use of org.nutz.dao.entity.LinkVisitor 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.entity.LinkVisitor in project nutz by nutzam.
the class NutDao method insertWith.
public <T> T insertWith(T obj, String regex) {
// TODO 天啊,每个调用都有4个正则表达式,能快起来不?
// TODO zzh: NutEntity 会缓存正则表达式计算的结果的,会很快的
EntityOperator opt = _optBy(obj);
if (null == opt)
return null;
final LinkVisitor one = doInsert(opt);
final boolean[] flag = new boolean[1];
// issue 889. hostField是@Id(auto=true)的时候
// 需要把相应的@One对象,押后到host对象插入之后
opt.entity.visitOne(obj, regex, new LinkVisitor() {
public void visit(Object obj, LinkField lnk) {
if (lnk.getHostField().isId()) {
flag[0] = true;
return;
}
one.visit(obj, lnk);
}
});
opt.addInsert();
opt.entity.visitMany(obj, regex, doInsert(opt));
opt.entity.visitManyMany(obj, regex, doInsert(opt));
opt.entity.visitManyMany(obj, regex, doInsertRelation(opt));
opt.exec();
if (flag[0]) {
opt = _optBy(obj);
final LinkVisitor _one = doInsert(opt);
opt.entity.visitOne(obj, regex, new LinkVisitor() {
public void visit(Object obj, LinkField lnk) {
if (!lnk.getHostField().isId())
return;
_one.visit(obj, lnk);
}
});
opt.exec();
}
return obj;
}
use of org.nutz.dao.entity.LinkVisitor in project nutz by nutzam.
the class NutDao method doFetch.
private LinkVisitor doFetch(final EntityOperator opt) {
return new LinkVisitor() {
public void visit(final Object obj, final LinkField lnk) {
Pojo pojo = opt.maker().makeQuery(lnk.getLinkedEntity());
pojo.setOperatingObject(obj);
pojo.append(Pojos.Items.cnd(lnk.createCondition(obj)));
pojo.setAfter(lnk.getCallback());
_exec(pojo);
lnk.setValue(obj, pojo.getObject(Object.class));
}
};
}
Aggregations