cn.jiangzeyin.database.run.read.Select Maven / Gradle / Ivy
package cn.jiangzeyin.database.run.read;
import cn.jiangzeyin.StringUtil;
import cn.jiangzeyin.database.DbWriteService;
import cn.jiangzeyin.database.base.ReadBase;
import cn.jiangzeyin.database.config.DatabaseContextHolder;
import cn.jiangzeyin.database.config.SystemColumn;
import cn.jiangzeyin.database.util.SqlUtil;
import cn.jiangzeyin.database.util.Util;
import cn.jiangzeyin.system.DbLog;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import javax.sql.DataSource;
import java.util.List;
import java.util.Map;
/**
* 查询数据库操作
*
* @author jiangzeyin
*/
@SuppressWarnings("unchecked")
public class Select extends ReadBase {
private String orderBy;
private String sql;
/**
* 查询数据重多少开始
*/
private int limitStart;
/**
* 查询数据个数
*/
private int limitCount;
public int getLimitStart() {
return limitStart;
}
/**
* 设置查询开始位置
*
* @param limitStart 开始行
* @return this
* @author jiangzeyin
*/
public Select setLimitStart(int limitStart) {
this.limitStart = limitStart;
return this;
}
public int getLimitCount() {
return limitCount;
}
/**
* 设置查询数量
*
* @param limitCount 共几行
* @return this
* @author jiangzeyin
*/
public Select setLimitCount(int limitCount) {
this.limitCount = limitCount;
return this;
}
public Select() {
// setTclass(DbReflectUtil.getTClass(this));
}
public Select(int isDelete) {
setIsDelete(isDelete);
}
public Select(String tag) {
super.setTag(tag);
}
public String getOrderBy() {
return orderBy;
}
public Select setOrderBy(String orderBy) {
this.orderBy = orderBy;
return this;
}
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
public void setSql(String sql, Result resultType) {
this.sql = sql;
setResultType(resultType);
}
public T run(Result resultType) {
setResultType(resultType);
return run();
}
/**
* 查询
*
* @return 结果
* @author jiangzeyin
*/
@Override
public t run() {
try {
if (getResultType() == Result.JsonObject) {
setLimitCount(1);
}
String tag = getTag() == null ? DbWriteService.getInstance().getDatabaseName(getTclass()) : getTag();
setTag(tag);
DataSource dataSource = DatabaseContextHolder.getReadDataSource(tag);
String runSql = getSql();
if (StringUtils.isEmpty(runSql)) {
runSql = SqlUtil.getSelectSql(this);
}
setRunSql(runSql);
DbLog.getInstance().info(getTransferLog() + runSql);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy