📄 queryimpl.java
字号:
package org.speedframework.engine.impl;
import java.sql.Connection;
import org.speedframework.engine.Query;
import java.util.List;
import org.speedframework.util.SQLHelper;
import org.speedframework.util.ParamHelper;
import org.speedframework.entity.Pagination;
import org.speedframework.engine.Execute;
import org.speedframework.exception.SpeedException;
public class QueryImpl implements Query {
private Connection con;
private Object[] param;
private int index = 0;
private int maxResults = 0;
private Execute execute;
private boolean useCache = true;
private String dbtype;
public String getDbtype() {
return dbtype;
}
public void setDbtype(String dbtype) {
this.dbtype = dbtype;
}
public QueryImpl(Connection con,String dbtype) {
execute = new ExecuteImpl(con,dbtype);
this.con = con;
this.dbtype= dbtype;
}
/**
* setIndex
*
* @param begin
* int
*/
public void setIndex(int begin) {
this.index = begin;
}
/**
* setMaxResults
*
* @param results
* int
*/
public void setMaxResults(int results) {
this.maxResults = results;
}
/**
* getResults
*
* @param vo
* Class
* @return List
*/
public List getResults(String SQL, Object[] params, Class vo)
throws SpeedException {
this.check(SQL, params);
this.param = params;
String type = SQLHelper.getDataBaseType(con);
if (maxResults > 0) {
SQL = SQLHelper.getLimitSQL(type, SQL);
param = ParamHelper.getQueryLimitParam(param, index, maxResults);
}
return execute.select(SQL, param, vo, useCache);
}
/**
* getMaxCount
*
* @return int
*/
public int getMaxCount(String SQL, Object[] params) throws SpeedException {
this.check(SQL, params);
String type = SQLHelper.getDataBaseType(con);
String count_sql = SQLHelper.getCountSQL(type, SQL);
return execute.getDataCount(count_sql, params, useCache);
}
/**
* getResults
*
* @param vo
* Class
* @param pagination
* Pagination
* @return List
*/
public List getResults(String SQL, Object[] params, Class vo,
Pagination pagination) throws SpeedException {
this.check(SQL, params);
String type = SQLHelper.getDataBaseType(con);
pagination.setTotalCount(getMaxCount(SQL, params));
if (type.equals("microsoft sql server") || type.indexOf("access")!=-1) {
String[] page = new String[2];
page[0] = new Integer(pagination.getCount() * pagination.getPage())
.toString();
page[1] = new Integer((pagination.getPage() - 1)
* pagination.getCount()).toString();
// SQL = SQLHelper.getSQLServerLimitSQL(SQL,page,params);
// List li=execute.select(con, SQL, vo, useCache);
List li=execute.select(SQL, params, vo, useCache);
// pagination.setTotalCount(li.size());
int start=(pagination.getPage() - 1) * pagination.getCount();
int end=pagination.getCount() * pagination.getPage();
if(end>li.size()){
return li.subList(start,li.size());
}else{
return li.subList(start,end);
}
// return execute.select(con, SQL, vo, useCache).subList(
// (pagination.getPage() - 1) * pagination.getCount(),
// pagination.getCount() * pagination.getPage()
// );
}
else {
SQL = SQLHelper.getLimitSQL(type, SQL);
Object[] param_ = ParamHelper.getQueryLimitParam(type, params,
pagination);
return execute.select(SQL, param_, vo, useCache);
}
}
public boolean getUseCacheStatus() {
return useCache;
}
public void setUseCacheStatus(boolean useCache) {
this.useCache = useCache;
}
private void check(String SQL, Object[] params) throws SpeedException {
if (SQL == null || SQL.equals("")) {
throw new SpeedException("SQL must not null");
}
if (params == null) {
throw new SpeedException("Params must not null");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -