package dao;
import dao.db.Builder;
import util.Info;
import util.StringUtil;
import java.sql.*;
import java.util.*;
/**
* 操作数据库链式执行
* 目前只实现了部分方法,之后会继续完善该代码,让其支持实体类的数据获取
* 使用方法:Query.make("表名称").where("字段名" , "条件符号","条件值").select()
*
*/
public class Query {
protected String mName = "";
protected HashMap mOption = null;
protected String pk = "id";
protected HashMap mData = null;
protected Builder builder = null;
public static HashMap tableFields = new HashMap();
public Query()
{
reset();
}
/**
* 构造Query
* @param name
*/
public Query(String name)
{
reset();
setName(name);
}
/**
* 重置并初始化数据
* @return
*/
protected Query reset()
{
mName = "";
mOption = null;
mOption = new HashMap();
mData = new HashMap();
builder = Builder.make(new CommDAO().getConn());
if(tableFields == null)
{
tableFields = new HashMap();
}
return this;
}
/**
* 设置一个字段自增
* @param field
* @param step
* @return
*/
public Query inc(String field , int step)
{
if(step<1)step = 1;
ArrayList list = new ArrayList();
list.add("inc");
list.add(step);
mData.put(field , list);
return this;
}
/**
* 设置一个字段自减
* @param field
* @param step
* @return
*/
public Query dec(String field , int step)
{
if(step<1)step = 1;
ArrayList list = new ArrayList();
list.add("dec");
list.add(step);
mData.put(field , list);
return this;
}
/**
* 马上更新数据字段自增1
* @param field
* @return
*/
public boolean setInc(String field)
{
return setInc(field ,1);
}
/**
* 马上更新数据字段自增step
* @param field
* @param step
* @return
*/
public boolean setInc(String field , String step)
{
return inc(field , Integer.valueOf(step).intValue()).update();
}
/**
* 马上更新数据字段自增step
* @param field
* @param step
* @return
*/
public boolean setInc(String field , int step)
{
return inc(field , step).update();
}
/**
* 马上更新数据字段自减1
* @param field
* @return
*/
public boolean setDec(String field )
{
return setDec(field , 1);
}
/**
* 马上更新数据字段自减step
* @param field
* @param step
* @return
*/
public boolean setDec(String field , String step)
{
return dec(field , Integer.valueOf(step).intValue()).update();
}
/**
* 马上更新数据字段自减step
* @param field
* @param step
* @return
*/
public boolean setDec(String field , int step)
{
return dec(field , step).update();
}
/**
* 设置某字段为某个值,并更新
* @param field
* @param step
* @return
*/
public boolean setField(String field , Object step)
{
mData.put(field , step);
return update();
}
/**
* 获取当前写入的data
* @return
*/
public HashMap getData()
{
return mData;
}
/**
* 更新当前数据
* @return
*/
public boolean update()
{
return update(null);
}
/**
* 更新当前数据加写入的data
* @param updateData
* @return
*/
public boolean update( HashMap updateData )
{
if(updateData != null){
mData.putAll(updateData);
}
String sql = builder.buildUpdate(this);
executeInsert(sql);
return true;
}
/**
* 向query 写入data
* @param data
* @return
*/
public Query data(Map data)
{
mData.putAll(data);
return this;
}
/**
* 向当前query 写入data
* @param name
* @param value
* @return
*/
public Query data(String name , String value)
{
mData.put(name , value);
return this;
}
/**
* 向当前query 写入data
* @param name
* @param value
* @return
*/
public Query data(String name , int value)
{
mData.put(name , value);
return this;
}
/**
* 向当前query 写入data
* @param name
* @param value
* @return
*/
public Query data(String name , long value)
{
mData.put(name , value);
return this;
}
/**
* 向当前query 写入data
* @param name
* @param value
* @return
*/
public Query data(String name , float value)
{
mData.put(name , value);
return this;
}
/**
* 向当前query 写入data
* @param name
* @param value
* @return
*/
public Query data(String name , double value)
{
mData.put(name , value);
return this;
}
/**
* 向当前query 写入data
* @param name
* @param value
* @return
*/
public Query data(String name , boolean value)
{
mData.put(name , value ? 1 : 0);
return this;
}
/**
* 插入数据
* @param insertData
* @return
*/
public int insert(HashMap insertData ){ return insert(insertData , false); }
/**
* 插入数据
* @param insertData
* @param replace
* @return
*/
public int insert(HashMap insertData , boolean replace)
{
if(insertData != null){
mData.putAll(insertData);
}
String sql = builder.buildInsert(this , replace);
return executeInsert(sql);
}
/**
* 获取当前自增字段名称
* @return
*/
public String getPk() {
return pk;
}
/**
* 设置自增字段名
* @param pk
*/
public void setPk(String pk) {
this.pk = pk;
}
/**
* 尚未实现该代码,获取表的数据
*/
protected void finalize()
{
//Statement st = conn.createStatement();
//System.out.print(sql);
//ResultSet rs
//super.finalize();
free();
}
/**
* 释放资源
*/
public void free()
{
// 释放rs
for(int i=0;i<resultSetList.size();i++){
Object os = resultSetList.get(i);
try{
if(os instanceof Statement){
Statement st = ((Statement) os);
st.close();
}else if(os instanceof ResultSet){
((ResultSet) os).close();
}
}catch (SQLException e){
}
}
resultSetList.clear();
}
/**
* 设置表名称
* @param name
* @return
*/
public Query setName(String name)
{
mName = name;
return this;
}
/**
* 获取表名称
* @return
*/
public String getName()
{
return mName;
}
/**
* 设置属性
* @param name
* @param value
* @return
*/
public Query setAttribute(String name , Object value)
{
getOptionHashMap("data").put(name , value);
return this;
}
/**
* 获取属性
* @param name
* @return
*/
public Obj
没有合适的资源?快使用搜索试试~ 我知道了~
源码管理源码管理源码管理.zip
共934个文件
js:518个
jsp:101个
png:63个
1星 需积分: 5 55 下载量 84 浏览量
2021-09-21
11:27:50
上传
评论 8
收藏 24.48MB ZIP 举报
温馨提示
源码管理源码管理源码管理源码管理
资源详情
资源评论
资源推荐
收起资源包目录
源码管理源码管理源码管理.zip (934个子文件)
Query.class 22KB
Builder.class 13KB
Info.class 12KB
CommDAO.class 11KB
Uploader.class 9KB
Collect.class 8KB
LoginCtrl.class 7KB
DownloadRemoteImage.class 5KB
SqlServer.class 3KB
SetChar.class 3KB
StringUtil.class 2KB
Request.class 2KB
LocalRequestContextHolder.class 2KB
LocalRequestContext.class 2KB
QuerySql.class 2KB
Timer.class 2KB
QueryData.class 1KB
Mysql.class 322B
.classpath 3KB
org.eclipse.wst.common.component 553B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.css 170KB
bootstrap.min.css 149KB
bootstrap.min.css 138KB
style.default.css 96KB
style.pink.css 96KB
style.violet.css 96KB
style.blue.css 96KB
style.sea.css 96KB
style.green.css 96KB
style.red.css 96KB
all.css 69KB
fontawesome.css 68KB
all.min.css 56KB
fontawesome.min.css 54KB
video-js-cdn.css 45KB
v4-shims.css 40KB
video-js-cdn.min.css 40KB
video-js.min.css 40KB
bootstrap-grid.css 37KB
font-awesome.css 37KB
font-awesome.min.css 30KB
bootstrap-grid.min.css 28KB
v4-shims.min.css 26KB
bootstrap-theme.min.css 23KB
swiper.css 22KB
style.css 21KB
swiper.min.css 19KB
umeditor.css 18KB
dark-unica.css 16KB
sand-signika.css 15KB
grid-light.css 15KB
highcharts.css 15KB
layer.css 14KB
umeditor.min.css 14KB
mathquill.css 9KB
svg-with-js.css 8KB
svg-with-js.min.css 6KB
gui.css 6KB
layer.css 5KB
bootstrap-reboot.css 5KB
popup.css 5KB
orionicons.css 4KB
iconfont.css 4KB
bootstrap-reboot.min.css 4KB
datepicker.css 4KB
datepicker.css 4KB
image.css 3KB
CssAdmin.css 3KB
video.css 3KB
emotion.css 2KB
formula.css 869B
regular.css 733B
solid.css 726B
brands.css 714B
regular.min.css 676B
solid.min.css 668B
brands.min.css 661B
custom.css 403B
WdatePicker.css 192B
Symbola.eot 869KB
stixgeneral-webfont.eot 451KB
stixgeneralbol-webfont.eot 239KB
stixgeneralbolita-webfont.eot 210KB
stixgeneralitalic-webfont.eot 204KB
fa-solid-900.eot 190KB
fontawesome-webfont.eot 162KB
fa-brands-400.eot 129KB
fa-regular-400.eot 34KB
glyphicons-halflings-regular.eot 20KB
orion-font.eot 18KB
VideoJS.eot 6KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
cface.gif 8KB
共 934 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
Gouzi99
- 粉丝: 5
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1