Search in sources :

Example 1 with PItem

use of org.nutz.dao.sql.PItem 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 PItem

use of org.nutz.dao.sql.PItem in project nutz by nutzam.

the class NutPojoMaker method makeQueryByJoin.

/**
 * 按联接进行查询
 * @param en
 * @param regex
 * @return
 */
@Override
public Pojo makeQueryByJoin(final Entity<?> en, String regex) {
    final Pojo pojo = Pojos.pojo(expert, en, SqlType.SELECT);
    pojo.setEntity(en);
    pojo.append(new QueryJoinFeilds(en, true, en.getTableName()));
    en.visitOne(null, regex, new LinkVisitor() {

        @Override
        public void visit(Object obj, LinkField lnk) {
            pojo.append(Pojos.Items.wrap(","));
            pojo.append(new QueryJoinFeilds(lnk.getLinkedEntity(), false, lnk.getName()));
        }
    });
    pojo.append(Pojos.Items.wrap("FROM"));
    pojo.append(Pojos.Items.entityViewName());
    en.visitOne(null, regex, new LinkVisitor() {

        @Override
        public void visit(Object obj, LinkField lnk) {
            PItem item = expert.formatLeftJoinLink(obj, lnk, en);
            if (item != null)
                pojo.append(item);
        }
    });
    return pojo;
}
Also used : LinkVisitor(org.nutz.dao.entity.LinkVisitor) Pojo(org.nutz.dao.sql.Pojo) NoParamsPItem(org.nutz.dao.impl.sql.pojo.NoParamsPItem) PItem(org.nutz.dao.sql.PItem) LinkField(org.nutz.dao.entity.LinkField)

Example 3 with PItem

use of org.nutz.dao.sql.PItem in project nutz by nutzam.

the class NutSql method getParamMatrix.

public Object[][] getParamMatrix() {
    int pc = _params_count();
    int row_count = rows.size();
    if (rows.size() > 1 && params.size() == 0 && rows.get(0).size() != 0) {
        row_count--;
    }
    Object[][] re = new Object[row_count][pc];
    for (int z = 0; z < row_count; z++) {
        VarSet row = rows.get(z);
        int i = 0;
        for (PItem item : items) i = item.joinParams(getEntity(), row, re[z], i);
    }
    return re;
}
Also used : VarSet(org.nutz.dao.sql.VarSet) AbstractPItem(org.nutz.dao.impl.sql.pojo.AbstractPItem) StaticPItem(org.nutz.dao.impl.sql.pojo.StaticPItem) PItem(org.nutz.dao.sql.PItem)

Example 4 with PItem

use of org.nutz.dao.sql.PItem in project nutz by nutzam.

the class NutSql method _params_count.

protected int _params_count() {
    int count = 0;
    Entity<?> en = getEntity();
    for (PItem item : items) {
        count += item.paramCount(en);
    }
    return count;
}
Also used : AbstractPItem(org.nutz.dao.impl.sql.pojo.AbstractPItem) StaticPItem(org.nutz.dao.impl.sql.pojo.StaticPItem) PItem(org.nutz.dao.sql.PItem)

Example 5 with PItem

use of org.nutz.dao.sql.PItem in project nutz by nutzam.

the class NutPojo method _params_count.

private int _params_count() {
    if (_pmnum < 0) {
        _pmnum = 0;
        Entity<?> en = getEntity();
        for (PItem item : items) {
            _pmnum += item.paramCount(en);
        }
    }
    return _pmnum;
}
Also used : PItem(org.nutz.dao.sql.PItem)

Aggregations

PItem (org.nutz.dao.sql.PItem)12 LinkField (org.nutz.dao.entity.LinkField)4 LinkVisitor (org.nutz.dao.entity.LinkVisitor)4 AbstractPItem (org.nutz.dao.impl.sql.pojo.AbstractPItem)4 StaticPItem (org.nutz.dao.impl.sql.pojo.StaticPItem)4 Pojo (org.nutz.dao.sql.Pojo)4 DoClearLinkVisitor (org.nutz.dao.impl.link.DoClearLinkVisitor)2 DoClearRelationByHostFieldLinkVisitor (org.nutz.dao.impl.link.DoClearRelationByHostFieldLinkVisitor)2 DoClearRelationByLinkedFieldLinkVisitor (org.nutz.dao.impl.link.DoClearRelationByLinkedFieldLinkVisitor)2 DoDeleteLinkVisitor (org.nutz.dao.impl.link.DoDeleteLinkVisitor)2 DoInsertLinkVisitor (org.nutz.dao.impl.link.DoInsertLinkVisitor)2 DoInsertRelationLinkVisitor (org.nutz.dao.impl.link.DoInsertRelationLinkVisitor)2 DoUpdateLinkVisitor (org.nutz.dao.impl.link.DoUpdateLinkVisitor)2 DoUpdateRelationLinkVisitor (org.nutz.dao.impl.link.DoUpdateRelationLinkVisitor)2 ConditionPItem (org.nutz.dao.impl.sql.pojo.ConditionPItem)2 NoParamsPItem (org.nutz.dao.impl.sql.pojo.NoParamsPItem)2 ValueAdaptor (org.nutz.dao.jdbc.ValueAdaptor)2 Criteria (org.nutz.dao.sql.Criteria)2 SqlExpressionGroup (org.nutz.dao.util.cri.SqlExpressionGroup)2 Condition (org.nutz.dao.Condition)1