use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class NutDao method _count.
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());
// MySQL/PgSQL/SqlServer 与 Oracle/H2的结果会不一样,奇葩啊
GroupBy gb = ((Criteria) cnd).getGroupBy();
if (gb != null)
pojo.append(gb);
} else // 否则暴力获取 WHERE 子句
{
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", "*");
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class Sqlserver2005JdbcExpert method fetchPojoId.
public Pojo fetchPojoId(Entity<?> en, MappingField idField) {
String autoSql = "SELECT @@@@IDENTITY as $field";
Pojo autoInfo = new SqlFieldMacro(idField, autoSql);
autoInfo.setEntity(en);
return autoInfo;
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class DoClearRelationByLinkedFieldLinkVisitor method visit.
public void visit(Object obj, LinkField lnk) {
if (lnk instanceof ManyManyLinkField) {
final ManyManyLinkField mm = (ManyManyLinkField) lnk;
Object value = mm.getValue(obj);
if (Lang.length(value) == 0)
return;
final Pojo pojo = opt.maker().makeDelete(mm.getRelationName());
pojo.append(Pojos.Items.cndColumn(mm.getToColumnName(), mm.getLinkedField(), null));
Lang.each(value, new Each<Object>() {
public void invoke(int i, Object ele, int length) throws ExitLoop, LoopException {
pojo.addParamsBy(mm.getLinkedField().getValue(ele));
}
});
opt.add(pojo);
}
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class DoDeleteLinkVisitor method visit.
public void visit(Object obj, LinkField lnk) {
Object value = lnk.getValue(obj);
if (value == null || Lang.length(value) == 0) {
log.infof("Value of LinkField(@%s-->%s.%s) is null or isEmtry, ingore", lnk.getLinkType(), lnk.getEntity().getType().getSimpleName(), lnk.getHostField().getName());
return;
}
final Pojo pojo = opt.maker().makeDelete(lnk.getLinkedEntity());
pojo.setOperatingObject(value);
pojo.append(Pojos.Items.cndAuto(lnk.getLinkedEntity(), null));
Lang.each(value, new Each<Object>() {
public void invoke(int i, Object ele, int length) throws ExitLoop, LoopException {
pojo.addParamsBy(ele);
}
});
opt.add(pojo);
}
use of org.nutz.dao.sql.Pojo in project nutz by nutzam.
the class AbstractJdbcExpert method fetchPojoId.
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;
}
Aggregations