All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.db.activerecord.DaoTemplate Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
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()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy