示例#1
0
文件: NutDao.java 项目: JRed1989/nutz
 private int _count(Entity<?> en, String tableName, Condition cnd) {
   // 如果有条件的话
   if (null != cnd) {
     Pojo pojo = pojoMaker.makeFunc(tableName, "COUNT", "*");
     pojo.setEntity(en);
     // 高级条件接口,直接得到 WHERE 子句
     if (cnd instanceof Criteria) {
       pojo.append(((Criteria) cnd).where());
     }
     // 否则暴力获取 WHERE 子句
     else {
       String str = Pojos.formatCondition(en, cnd);
       if (!Strings.isBlank(str)) {
         String[] ss = str.toUpperCase().split("ORDER BY");
         pojo.append(Pojos.Items.wrap(str.substring(0, ss[0].length())));
       }
     }
     // 设置回调,并执行 SQL
     pojo.setAfter(_pojo_fetchInt);
     _exec(pojo);
     return pojo.getInt();
   }
   // 没有条件,直接生成表达式
   return func(tableName, "COUNT", "*");
 }
示例#2
0
文件: NutDao.java 项目: JRed1989/nutz
 public List<Record> query(String tableName, Condition cnd, Pager pager) {
   Pojo pojo =
       pojoMaker
           .makeQuery(tableName)
           .addParamsBy("*")
           .setPager(pager)
           .append(Pojos.Items.cnd(cnd));
   expert.formatQuery(pojo);
   pojo.setAfter(_pojo_queryRecord);
   _exec(pojo);
   return pojo.getList(Record.class);
 }
示例#3
0
文件: NutDao.java 项目: JRed1989/nutz
 public int each(String tableName, Condition cnd, Pager pager, Each<Record> callback) {
   Pojo pojo =
       pojoMaker
           .makeQuery(tableName)
           .addParamsBy("*")
           .setPager(pager)
           .append(Pojos.Items.cnd(cnd));
   expert.formatQuery(pojo);
   pojo.setAfter(_pojo_eachRecord);
   pojo.getContext().attr(Each.class.getName(), callback);
   _exec(pojo);
   return pojo.getInt();
 }
示例#4
0
文件: NutDao.java 项目: JRed1989/nutz
 public <T> int each(Class<T> classOfT, Condition cnd, Pager pager, Each<T> callback) {
   Pojo pojo =
       pojoMaker
           .makeQuery(holder.getEntity(classOfT))
           .append(Pojos.Items.cnd(cnd))
           .addParamsBy("*")
           .setPager(pager)
           .setAfter(_pojo_queryEntity);
   expert.formatQuery(pojo);
   pojo.setAfter(_pojo_eachEntity);
   pojo.getContext().attr(Each.class.getName(), callback);
   _exec(pojo);
   return pojo.getInt();
 }