Search in sources :

Example 61 with Pojo

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

the class NutPojoMaker method makeCountByJoin.

@Override
public Pojo makeCountByJoin(final Entity<?> en, String regex) {
    final Pojo pojo = Pojos.pojo(expert, en, SqlType.SELECT);
    pojo.setEntity(en);
    pojo.append(Pojos.Items.wrap("count(1)"));
    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 62 with Pojo

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

the class Sqlserver2005JdbcExpert method fetchPojoId.

public Pojo fetchPojoId(Entity<?> en, MappingField idField) {
    String autoSql = "SELECT @@@@IDENTITY as $field";
    Pojo autoInfo = new SqlFieldMacro(idField, autoSql);
    autoInfo.setEntity(en);
    return autoInfo;
}
Also used : Pojo(org.nutz.dao.sql.Pojo) SqlFieldMacro(org.nutz.dao.impl.entity.macro.SqlFieldMacro)

Example 63 with Pojo

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

the class DoDeleteLinkVisitor method visit.

public void visit(Object obj, LinkField lnk) {
    Object value = lnk.getValue(obj);
    if (value == null || Lang.eleSize(value) == 0) {
        log.infof("Value of LinkField(@%s-->%s.%s) is null or isEmtry, ingore", lnk.getLinkType(), lnk.getEntity().getType().getSimpleName(), lnk.getHostField().getName());
        return;
    }
    final Pojo pojo = opt.maker().makeDelete(lnk.getLinkedEntity());
    pojo.setOperatingObject(value);
    pojo.append(Pojos.Items.cndAuto(lnk.getLinkedEntity(), null));
    Lang.each(value, new Each<Object>() {

        public void invoke(int i, Object ele, int length) throws ExitLoop, LoopException {
            pojo.addParamsBy(ele);
        }
    });
    opt.add(pojo);
}
Also used : Pojo(org.nutz.dao.sql.Pojo) ExitLoop(org.nutz.lang.ExitLoop) LoopException(org.nutz.lang.LoopException)

Example 64 with Pojo

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

the class NutPojoMaker method makeFunc.

@Override
public Pojo makeFunc(String tableName, String funcName, String colName) {
    Pojo pojo = makePojo(SqlType.SELECT);
    pojo.append(Pojos.Items.wrapf("%s(%s) FROM %s", funcName, colName, tableName));
    return pojo;
}
Also used : Pojo(org.nutz.dao.sql.Pojo)

Example 65 with Pojo

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

the class NutPojoMaker method makeInsert.

@Override
public Pojo makeInsert(final Entity<?> en) {
    Pojo pojo = Pojos.pojo(expert, en, SqlType.INSERT);
    pojo.setEntity(en);
    pojo.append(Pojos.Items.entityTableName());
    pojo.append(Pojos.Items.insertFields());
    pojo.append(Pojos.Items.insertValues());
    if (expert.isSupportAutoIncrement()) {
        MappingField mf = en.getIdField();
        if (mf != null && mf.isAutoIncreasement()) {
            if (expert.isSupportGeneratedKeys()) {
                pojo.setAfter(new GeneratedKeys());
                pojo.getContext().attr("RETURN_GENERATED_KEYS", true);
            }
        }
    }
    return pojo;
}
Also used : Pojo(org.nutz.dao.sql.Pojo) MappingField(org.nutz.dao.entity.MappingField)

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