use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class NutDao method doLinkQuery.
private LinkVisitor doLinkQuery(final EntityOperator opt, final Condition cnd) {
return new LinkVisitor() {
public void visit(final Object obj, final LinkField lnk) {
Pojo pojo = opt.maker().makeQuery(lnk.getLinkedEntity());
pojo.setOperatingObject(obj);
PItem[] _cndItems = Pojos.Items.cnd(lnk.createCondition(obj));
pojo.append(_cndItems);
if (cnd != null) {
if (cnd instanceof Criteria) {
Criteria cri = (Criteria) cnd;
SqlExpressionGroup seg = cri.where();
if (_cndItems.length > 0 && seg != null && !seg.isEmpty()) {
seg.setTop(false);
pojo.append(Pojos.Items.wrap(" AND "));
}
pojo.append(cri);
if (cri.getPager() != null) {
pojo.setPager(cri.getPager());
expert.formatQuery(pojo);
}
} else // 普通条件
{
pojo.append(new ConditionPItem(cnd));
}
}
pojo.setAfter(lnk.getCallback());
pojo.setEntity(lnk.getLinkedEntity());
_exec(pojo);
lnk.setValue(obj, pojo.getResult());
}
};
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class NutDao method delete.
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();
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class NutDao method fetchx.
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);
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class NutDao method fetch.
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);
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class NutDao method fetch.
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);
}
Aggregations