Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.litongjava.db.activerecord.DaoTemplate Maven / Gradle / Ivy
package com.litongjava.db.activerecord;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import com.litongjava.db.SqlPara;
import com.litongjava.model.page.Page;
/**
* DaoTemplate
*
*
* 例子:
* model.template("find", 123).find();
*
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class DaoTemplate {
protected Model dao;
protected SqlPara sqlPara;
public DaoTemplate(Model dao, String key, Map, ?> data) {
this.dao = dao;
this.sqlPara = dao.getSqlPara(key, data);
}
public DaoTemplate(Model dao, String key, Object... paras) {
this.dao = dao;
this.sqlPara = dao.getSqlPara(key, paras);
}
public DaoTemplate(boolean byString, Model dao, String content, Map, ?> data) {
this.dao = dao;
this.sqlPara = dao.getSqlParaByString(content, data);
}
public DaoTemplate(boolean byString, Model dao, String content, Object... paras) {
this.dao = dao;
this.sqlPara = dao.getSqlParaByString(content, paras);
}
public SqlPara getSqlPara() {
return sqlPara;
}
// ---------
public List find() {
return dao.find(sqlPara);
}
public M findFirst() {
return dao.findFirst(sqlPara);
}
public Page paginate(int pageNumber, int pageSize) {
return dao.paginate(pageNumber, pageSize, sqlPara);
}
public Page paginate(int pageNumber, int pageSize, boolean isGroupBySql) {
return dao.paginate(pageNumber, pageSize, isGroupBySql, sqlPara);
}
// ---------
public void each(Function func) {
dao.each(func, sqlPara.getSql(), sqlPara.getPara());
}
// ---------
public List findByCache(String cacheName, Object key) {
return dao.findByCache(cacheName, key, sqlPara.getSql(), sqlPara.getPara());
}
public M findFirstByCache(String cacheName, Object key) {
return dao.findFirstByCache(cacheName, key, sqlPara.getSql(), sqlPara.getPara());
}
public Page paginateByCache(String cacheName, Object key, int pageNumber, int pageSize) {
String[] sqls = PageSqlKit.parsePageSql(sqlPara.getSql());
return dao.paginateByCache(cacheName, key, pageNumber, pageSize, sqls[0], sqls[1], sqlPara.getPara());
}
public Page paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql) {
String[] sqls = PageSqlKit.parsePageSql(sqlPara.getSql());
return dao.paginateByCache(cacheName, key, pageNumber, pageSize, isGroupBySql, sqls[0], sqls[1], sqlPara.getPara());
}
}