Esempio n. 1
0
 public <T> T fetchx(Class<T> classOfT, Object... pks) {
   Entity<T> en = holder.getEntity(classOfT);
   Pojo pojo =
       pojoMaker.makeQuery(en).append(Pojos.Items.cndPk(en, pks)).setAfter(_pojo_fetchEntity);
   _exec(pojo);
   return pojo.getObject(classOfT);
 }
Esempio n. 2
0
 public int delete(Class<?> classOfT, long id) {
   Entity<?> en = holder.getEntity(classOfT);
   Pojo pojo = pojoMaker.makeDelete(en).append(Pojos.Items.cndId(en, id));
   pojo.addParamsBy(id);
   _exec(pojo);
   return pojo.getUpdateCount();
 }
Esempio n. 3
0
 public Record fetch(String tableName, Condition cnd) {
   Pojo pojo =
       pojoMaker
           .makeQuery(tableName)
           .append(Pojos.Items.cnd(cnd))
           .addParamsBy("*")
           .setPager(createPager(1, 1))
           .setAfter(_pojo_fetchRecord);
   expert.formatQuery(pojo);
   _exec(pojo);
   return pojo.getObject(Record.class);
 }
Esempio n. 4
0
 @SuppressWarnings("unchecked")
 public <T> T fetch(T obj) {
   Entity<?> en = holder.getEntityBy(obj);
   Pojo pojo =
       pojoMaker
           .makeQuery(en)
           .append(Pojos.Items.cndAuto(en, obj))
           .setAfter(_pojo_fetchEntity)
           .setPager(createPager(1, 1));
   _exec(pojo);
   return (T) pojo.getResult();
 }
Esempio n. 5
0
 public <T> T fetch(Class<T> classOfT, long id) {
   Entity<T> en = holder.getEntity(classOfT);
   if (en.getIdField() == null) throw new DaoException("Need @Id for " + classOfT);
   Pojo pojo =
       pojoMaker
           .makeQuery(en)
           .append(Pojos.Items.cndId(en, id))
           .addParamsBy(id)
           .setAfter(_pojo_fetchEntity);
   _exec(pojo);
   return pojo.getObject(classOfT);
 }
Esempio n. 6
0
 public <T> List<T> query(Class<T> classOfT, Condition cnd, Pager pager) {
   Pojo pojo =
       pojoMaker
           .makeQuery(holder.getEntity(classOfT))
           .append(Pojos.Items.cnd(cnd))
           .addParamsBy("*")
           .setPager(pager)
           .setAfter(_pojo_queryEntity);
   expert.formatQuery(pojo);
   _exec(pojo);
   return pojo.getList(classOfT);
 }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 public <T> T fetch(Class<T> classOfT, Condition cnd) {
   Pojo pojo =
       pojoMaker
           .makeQuery(holder.getEntity(classOfT))
           .append(Pojos.Items.cnd(cnd))
           .addParamsBy("*")
           .setPager(createPager(1, 1))
           .setAfter(_pojo_fetchEntity);
   expert.formatQuery(pojo);
   _exec(pojo);
   return pojo.getObject(classOfT);
 }
Esempio n. 9
0
 public <T> T fetch(Class<T> classOfT, String name) {
   if (name == null) throw new IllegalArgumentException("name MUST NOT NULL!");
   Entity<T> en = holder.getEntity(classOfT);
   if (en.getNameField() == null) throw new DaoException("Need @Name for " + classOfT);
   Pojo pojo =
       pojoMaker
           .makeQuery(en)
           .append(Pojos.Items.cndName(en, name))
           .addParamsBy(name)
           .setAfter(_pojo_fetchEntity);
   _exec(pojo);
   return pojo.getObject(classOfT);
 }
Esempio n. 10
0
 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();
 }
Esempio n. 11
0
 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();
 }
Esempio n. 12
0
 public void formatQuery(Pojo pojo) {
   Pager pager = pojo.getContext().getPager();
   // 需要进行分页
   if (null != pager && pager.getPageNumber() > 0) {
     // 之前插入
     pojo.insertFirst(
         Pojos.Items.wrap(
             "SELECT * FROM (" + "SELECT ROW_NUMBER() OVER() AS ROWNUM, " + "T.* FROM ("));
     // 之后插入
     pojo.append(
         Pojos.Items.wrapf(
             ") T) AS A WHERE ROWNUM BETWEEN %d AND %d",
             pager.getOffset() + 1, pager.getOffset() + pager.getPageSize()));
   }
 }
Esempio n. 13
0
 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", "*");
 }
Esempio n. 14
0
 public int clear(String tableName, Condition cnd) {
   Pojo pojo = pojoMaker.makeDelete(tableName).append(Pojos.Items.cnd(cnd));
   _exec(pojo);
   return pojo.getUpdateCount();
 }
Esempio n. 15
0
 public int clear(Class<?> classOfT, Condition cnd) {
   Pojo pojo = pojoMaker.makeDelete(holder.getEntity(classOfT)).append(Pojos.Items.cnd(cnd));
   _exec(pojo);
   return pojo.getUpdateCount();
 }
Esempio n. 16
0
 public int delete(Class<?> classOfT, String name) {
   Entity<?> en = holder.getEntity(classOfT);
   Pojo pojo = pojoMaker.makeDelete(en).append(Pojos.Items.cndName(en, name)).addParamsBy(name);
   _exec(pojo);
   return pojo.getUpdateCount();
 }
Esempio n. 17
0
 public Pojo fetchPojoId(Entity<?> en, MappingField idField) {
   String autoSql = "SELECT MAX($field) AS $field FROM $view";
   Pojo autoInfo = new SqlFieldMacro(idField, autoSql);
   autoInfo.setEntity(en);
   return autoInfo;
 }
Esempio n. 18
0
 public void formatQuery(Pojo pojo) {
   Pager pager = pojo.getContext().getPager();
   // 需要进行分页
   if (null != pager && pager.getPageNumber() > 0)
     pojo.append(Pojos.Items.wrapf(" LIMIT %d OFFSET %d", pager.getPageSize(), pager.getOffset()));
 }
Esempio n. 19
0
 public <T> int deletex(Class<T> classOfT, Object... pks) {
   Entity<T> en = holder.getEntity(classOfT);
   Pojo pojo = pojoMaker.makeDelete(en).append(Pojos.Items.cndPk(en, pks));
   _exec(pojo);
   return pojo.getUpdateCount();
 }