Search in sources :

Example 6 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, 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());
        }
    };
}
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) Condition(org.nutz.dao.Condition) 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) SimpleCriteria(org.nutz.dao.util.cri.SimpleCriteria) LinkField(org.nutz.dao.entity.LinkField) ConditionPItem(org.nutz.dao.impl.sql.pojo.ConditionPItem)

Example 7 with PItem

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

the class NutPojo method getParamMatrix.

public Object[][] getParamMatrix() {
    Object[][] re;
    /*
         * 木有参数对象,但是有参数,循环一下,看看元素们会给出什么样的参数
         */
    if (_params_count() > 0 && params.isEmpty()) {
        re = new Object[1][_params_count()];
        int i = 0;
        for (PItem item : items) i = item.joinParams(getEntity(), null, re[0], i);
    } else /*
         * 依照参数列表循环获取参数矩阵
         */
    {
        re = new Object[params.size()][_params_count()];
        int row = 0;
        for (Object obj : params) {
            int i = 0;
            for (PItem item : items) i = item.joinParams(getEntity(), obj, re[row], i);
            row++;
        }
    }
    return re;
}
Also used : PItem(org.nutz.dao.sql.PItem)

Example 8 with PItem

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

the class NutPojo method getAdaptors.

public ValueAdaptor[] getAdaptors() {
    ValueAdaptor[] adaptors = new ValueAdaptor[_params_count()];
    int i = 0;
    for (PItem item : items) i = item.joinAdaptor(getEntity(), adaptors, i);
    return adaptors;
}
Also used : ValueAdaptor(org.nutz.dao.jdbc.ValueAdaptor) PItem(org.nutz.dao.sql.PItem)

Example 9 with PItem

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

the class NutSql method getAdaptors.

public ValueAdaptor[] getAdaptors() {
    ValueAdaptor[] adaptors = new ValueAdaptor[_params_count()];
    int i = 0;
    for (PItem item : items) i = item.joinAdaptor(getEntity(), adaptors, i);
    return adaptors;
}
Also used : ValueAdaptor(org.nutz.dao.jdbc.ValueAdaptor) AbstractPItem(org.nutz.dao.impl.sql.pojo.AbstractPItem) StaticPItem(org.nutz.dao.impl.sql.pojo.StaticPItem) PItem(org.nutz.dao.sql.PItem)

Example 10 with PItem

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

the class NutSql method setSourceSql.

public void setSourceSql(String sql) {
    this.sourceSql = sql.trim();
    SqlLiteral literal = literal();
    this.varIndex = literal.getVarIndexes();
    this.paramIndex = literal.getParamIndexes();
    if (getSqlType() == null)
        setSqlType(literal.getType());
    String[] ss = literal.stack.cloneChain();
    PItem[] tmp = new PItem[ss.length];
    for (String var : varIndex.getOrders()) {
        int[] is = varIndex.indexesOf(var);
        if (is != null) {
            for (int i : is) {
                tmp[i] = new SqlVarPItem(var);
            }
        }
    }
    for (String param : paramIndex.getOrders()) {
        int[] is = paramIndex.indexesOf(param);
        if (is != null) {
            for (int i : is) {
                tmp[i] = new SqlParamPItem(param);
            }
        }
    }
    this.items = new ArrayList<PItem>();
    for (int i = 0; i < tmp.length; i++) {
        if (tmp[i] == null) {
            tmp[i] = new StaticPItem(ss[i], true);
        }
        items.add(tmp[i]);
    }
}
Also used : AbstractPItem(org.nutz.dao.impl.sql.pojo.AbstractPItem) StaticPItem(org.nutz.dao.impl.sql.pojo.StaticPItem) PItem(org.nutz.dao.sql.PItem) StaticPItem(org.nutz.dao.impl.sql.pojo.StaticPItem)

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