}
private LinkVisitor doLinkQuery(EntityOperator opt, final Condition cnd) {
return new AbstractLinkVisitor() {
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(new PojoCallback() {
public Object invoke(Connection conn, ResultSet rs, Pojo pojo) throws SQLException {
Object value = lnk.getCallback().invoke(conn, rs, pojo);
lnk.setValue(obj, value);
return value;
}
});
pojo.setEntity(lnk.getLinkedEntity());
opt.add(pojo);
}
}.opt(opt);
}