use of org.nutz.dao.util.cri.SqlExpressionGroup 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.util.cri.SqlExpressionGroup in project nutz by nutzam.
the class Cnd method from.
/**
* 根据一个对象生成Cnd条件, FieldMatcher详细控制.
* <p/>
* <code>assertEquals(" WHERE name='wendal' AND age=0", Cnd.from(dao, pet, FieldMatcher.make("age|name", null, true).setIgnoreDate(true)).toString());</code>
*
* @param dao
* Dao实例
* @param obj
* 基对象,不可以是Class,字符串,数值和Boolean
* @param matcher
* 过滤字段属性,
* 可配置哪些字段可用/不可用/是否忽略空值/是否忽略0值/是否忽略java.util.Date类及其子类的对象/是否忽略@Id所标注的主键属性/是否忽略
* \@Name 所标注的主键属性/是否忽略 \@Pk 所引用的复合主键
* @return Cnd条件
*/
public static Cnd from(Dao dao, Object obj, FieldMatcher matcher) {
final SqlExpressionGroup exps = new SqlExpressionGroup();
boolean re = Daos.filterFields(obj, matcher, dao, new Callback2<MappingField, Object>() {
@Override
public void invoke(MappingField mf, Object val) {
exps.and(mf.getName(), "=", val);
}
});
if (re)
return Cnd.where(exps);
return null;
}
use of org.nutz.dao.util.cri.SqlExpressionGroup in project nutz by nutzam.
the class NutDao method doLinkQuery.
private LinkVisitor doLinkQuery(final EntityOperator opt, final Condition _cnd, final Map<String, Condition> cnds) {
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);
Condition cnd = _cnd;
if (_cnd == null && cnds != null)
cnd = cnds.get(lnk.getLinkedField().getName());
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());
}
};
}
Aggregations