Search in sources :

Example 1 with Pojo

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

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

the class NutDao method delete.

public int delete(Class<?> classOfT, String name) {
    Entity<?> en = holder.getEntity(classOfT);
    Pojo pojo = pojoMaker.makeDelete(en).append(Pojos.Items.cndName(en, name)).addParamsBy(name);
    _exec(pojo);
    return pojo.getUpdateCount();
}
Also used : Pojo(org.nutz.dao.sql.Pojo)

Example 3 with Pojo

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

the class NutDao method fetchx.

public <T> T fetchx(Class<T> classOfT, Object... pks) {
    Entity<T> en = holder.getEntity(classOfT);
    Pojo pojo = pojoMaker.makeQuery(en).append(Pojos.Items.cndPk(en, pks)).setAfter(_pojo_fetchEntity);
    _exec(pojo);
    return pojo.getObject(classOfT);
}
Also used : Pojo(org.nutz.dao.sql.Pojo)

Example 4 with Pojo

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

the class NutDao method fetch.

public <T> T fetch(Class<T> classOfT, String name) {
    if (name == null)
        throw new IllegalArgumentException("name MUST NOT NULL!");
    Entity<T> en = holder.getEntity(classOfT);
    if (en.getNameField() == null)
        throw new DaoException("Need @Name for " + classOfT);
    Pojo pojo = pojoMaker.makeQuery(en).append(Pojos.Items.cndName(en, name)).addParamsBy(name).setAfter(_pojo_fetchEntity);
    _exec(pojo);
    return pojo.getObject(classOfT);
}
Also used : Pojo(org.nutz.dao.sql.Pojo) DaoException(org.nutz.dao.DaoException)

Example 5 with Pojo

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

the class NutDao method fetch.

public <T> T fetch(Class<T> classOfT, Condition cnd) {
    Pojo pojo = pojoMaker.makeQuery(holder.getEntity(classOfT)).append(Pojos.Items.cnd(cnd)).addParamsBy("*").setPager(createPager(1, 1)).setAfter(_pojo_fetchEntity);
    expert.formatQuery(pojo);
    _exec(pojo);
    return pojo.getObject(classOfT);
}
Also used : Pojo(org.nutz.dao.sql.Pojo)

Aggregations

Pojo (org.nutz.dao.sql.Pojo)67 SqlFieldMacro (org.nutz.dao.impl.entity.macro.SqlFieldMacro)6 LinkField (org.nutz.dao.entity.LinkField)5 LinkVisitor (org.nutz.dao.entity.LinkVisitor)5 ExitLoop (org.nutz.lang.ExitLoop)5 LoopException (org.nutz.lang.LoopException)5 DaoException (org.nutz.dao.DaoException)4 ManyManyLinkField (org.nutz.dao.impl.entity.field.ManyManyLinkField)4 Criteria (org.nutz.dao.sql.Criteria)4 PItem (org.nutz.dao.sql.PItem)4 ArrayList (java.util.ArrayList)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 ConditionPItem (org.nutz.dao.impl.sql.pojo.ConditionPItem)3