Search in sources :

Example 1 with LinkVisitor

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());
        }
    };
}
Also used : DoUpdateRelationLinkVisitor(org.nutz.dao.impl.link.DoUpdateRelationLinkVisitor) DoInsertRelationLinkVisitor(org.nutz.dao.impl.link.DoInsertRelationLinkVisitor) DoClearLinkVisitor(org.nutz.dao.impl.link.DoClearLinkVisitor) DoDeleteLinkVisitor(org.nutz.dao.impl.link.DoDeleteLinkVisitor) DoClearRelationByHostFieldLinkVisitor(org.nutz.dao.impl.link.DoClearRelationByHostFieldLinkVisitor) DoUpdateLinkVisitor(org.nutz.dao.impl.link.DoUpdateLinkVisitor) DoInsertLinkVisitor(org.nutz.dao.impl.link.DoInsertLinkVisitor) LinkVisitor(org.nutz.dao.entity.LinkVisitor) DoClearRelationByLinkedFieldLinkVisitor(org.nutz.dao.impl.link.DoClearRelationByLinkedFieldLinkVisitor) Pojo(org.nutz.dao.sql.Pojo) SqlExpressionGroup(org.nutz.dao.util.cri.SqlExpressionGroup) ConditionPItem(org.nutz.dao.impl.sql.pojo.ConditionPItem) PItem(org.nutz.dao.sql.PItem) Criteria(org.nutz.dao.sql.Criteria) LinkField(org.nutz.dao.entity.LinkField) ConditionPItem(org.nutz.dao.impl.sql.pojo.ConditionPItem)

Example 2 with LinkVisitor

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;
}
Also used : DoUpdateRelationLinkVisitor(org.nutz.dao.impl.link.DoUpdateRelationLinkVisitor) DoInsertRelationLinkVisitor(org.nutz.dao.impl.link.DoInsertRelationLinkVisitor) DoClearLinkVisitor(org.nutz.dao.impl.link.DoClearLinkVisitor) DoDeleteLinkVisitor(org.nutz.dao.impl.link.DoDeleteLinkVisitor) DoClearRelationByHostFieldLinkVisitor(org.nutz.dao.impl.link.DoClearRelationByHostFieldLinkVisitor) DoUpdateLinkVisitor(org.nutz.dao.impl.link.DoUpdateLinkVisitor) DoInsertLinkVisitor(org.nutz.dao.impl.link.DoInsertLinkVisitor) LinkVisitor(org.nutz.dao.entity.LinkVisitor) DoClearRelationByLinkedFieldLinkVisitor(org.nutz.dao.impl.link.DoClearRelationByLinkedFieldLinkVisitor) LinkField(org.nutz.dao.entity.LinkField)

Example 3 with LinkVisitor

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));
        }
    };
}
Also used : DoUpdateRelationLinkVisitor(org.nutz.dao.impl.link.DoUpdateRelationLinkVisitor) DoInsertRelationLinkVisitor(org.nutz.dao.impl.link.DoInsertRelationLinkVisitor) DoClearLinkVisitor(org.nutz.dao.impl.link.DoClearLinkVisitor) DoDeleteLinkVisitor(org.nutz.dao.impl.link.DoDeleteLinkVisitor) DoClearRelationByHostFieldLinkVisitor(org.nutz.dao.impl.link.DoClearRelationByHostFieldLinkVisitor) DoUpdateLinkVisitor(org.nutz.dao.impl.link.DoUpdateLinkVisitor) DoInsertLinkVisitor(org.nutz.dao.impl.link.DoInsertLinkVisitor) LinkVisitor(org.nutz.dao.entity.LinkVisitor) DoClearRelationByLinkedFieldLinkVisitor(org.nutz.dao.impl.link.DoClearRelationByLinkedFieldLinkVisitor) Pojo(org.nutz.dao.sql.Pojo) LinkField(org.nutz.dao.entity.LinkField)

Aggregations

LinkField (org.nutz.dao.entity.LinkField)3 LinkVisitor (org.nutz.dao.entity.LinkVisitor)3 DoClearLinkVisitor (org.nutz.dao.impl.link.DoClearLinkVisitor)3 DoClearRelationByHostFieldLinkVisitor (org.nutz.dao.impl.link.DoClearRelationByHostFieldLinkVisitor)3 DoClearRelationByLinkedFieldLinkVisitor (org.nutz.dao.impl.link.DoClearRelationByLinkedFieldLinkVisitor)3 DoDeleteLinkVisitor (org.nutz.dao.impl.link.DoDeleteLinkVisitor)3 DoInsertLinkVisitor (org.nutz.dao.impl.link.DoInsertLinkVisitor)3 DoInsertRelationLinkVisitor (org.nutz.dao.impl.link.DoInsertRelationLinkVisitor)3 DoUpdateLinkVisitor (org.nutz.dao.impl.link.DoUpdateLinkVisitor)3 DoUpdateRelationLinkVisitor (org.nutz.dao.impl.link.DoUpdateRelationLinkVisitor)3 Pojo (org.nutz.dao.sql.Pojo)2 ConditionPItem (org.nutz.dao.impl.sql.pojo.ConditionPItem)1 Criteria (org.nutz.dao.sql.Criteria)1 PItem (org.nutz.dao.sql.PItem)1 SqlExpressionGroup (org.nutz.dao.util.cri.SqlExpressionGroup)1