Search in sources :

Example 26 with Pojo

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

the class DoInsertLinkVisitor method visit.

public void visit(final Object obj, final LinkField lnk) {
    final Object value = lnk.getValue(obj);
    if (Lang.length(value) == 0)
        return;
    // 从宿主对象更新关联对象
    opt.add(Pojos.createRun(new PojoCallback() {

        public Object invoke(Connection conn, ResultSet rs, Pojo pojo, Statement stmt) throws SQLException {
            lnk.updateLinkedField(obj, value);
            return pojo.getOperatingObject();
        }
    }).setOperatingObject(obj));
    // 为其循环生成插入语句 : holder.getEntityBy 会考虑到集合和数组的情况的
    final Entity<?> en = lnk.getLinkedEntity();
    Lang.each(value, new Each<Object>() {

        public void invoke(int i, Object ele, int length) throws ExitLoop, LoopException {
            if (ele == null)
                throw new NullPointerException("null ele in linked field!!");
            // 执行插入
            opt.addInsert(en, ele);
            // 更新字段
            opt.add(Pojos.createRun(new PojoCallback() {

                public Object invoke(Connection conn, ResultSet rs, Pojo pojo, Statement stmt) throws SQLException {
                    lnk.saveLinkedField(obj, pojo.getOperatingObject());
                    return pojo.getOperatingObject();
                }
            }).setOperatingObject(ele));
        }
    });
}
Also used : Pojo(org.nutz.dao.sql.Pojo) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) PojoCallback(org.nutz.dao.sql.PojoCallback) ExitLoop(org.nutz.lang.ExitLoop) LoopException(org.nutz.lang.LoopException) ResultSet(java.sql.ResultSet)

Example 27 with Pojo

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

the class NutPojoMaker method makeUpdate.

public Pojo makeUpdate(Entity<?> en, Object refer) {
    Pojo pojo = Pojos.pojo(expert, en, SqlType.UPDATE);
    pojo.setEntity(en);
    pojo.append(Pojos.Items.entityTableName());
    pojo.append(Pojos.Items.updateFields(refer));
    return pojo;
}
Also used : Pojo(org.nutz.dao.sql.Pojo)

Example 28 with Pojo

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

the class EntityOperator method addUpdate.

public Pojo addUpdate(Condition cnd) {
    if (null == entity)
        return null;
    Pojo pojo = dao.pojoMaker.makeUpdate(entity, null).append(Pojos.Items.cnd(cnd));
    pojoList.add(pojo);
    return pojo;
}
Also used : Pojo(org.nutz.dao.sql.Pojo)

Example 29 with Pojo

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

the class EntityOperator method addInsert.

public List<Pojo> addInsert(Entity<?> en, Object obj) {
    if (null == en)
        return null;
    int len = Map.class.isAssignableFrom(obj.getClass()) ? 1 : Lang.length(obj);
    List<Pojo> re = new ArrayList<Pojo>(len);
    if (len > 0) {
        if (len == 1) {
            for (Pojo pojo : en.cloneBeforeInsertMacroes()) re.add(pojo.setOperatingObject(obj));
        }
        re.add(dao.pojoMaker.makeInsert(en).setOperatingObject(obj));
        if (len == 1) {
            for (Pojo pojo : en.cloneAfterInsertMacroes()) re.add(pojo.setOperatingObject(obj));
        }
        pojoList.addAll(re);
    }
    return re;
}
Also used : Pojo(org.nutz.dao.sql.Pojo) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 30 with Pojo

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

the class EntityOperator method addInsertSelfOnly.

public Pojo addInsertSelfOnly(Entity<?> en, Object obj) {
    if (null == en)
        return null;
    Pojo pojo;
    if (obj instanceof Chain) {
        pojo = dao.pojoMaker.makePojo(SqlType.INSERT);
        pojo.append(Pojos.Items.entityTableName());
        pojo.append(new InsertByChainPItem((Chain) obj));
        pojo.setEntity(en);
    } else {
        pojo = dao.pojoMaker.makeInsert(en).setOperatingObject(obj);
    }
    pojoList.add(pojo);
    return pojo;
}
Also used : Chain(org.nutz.dao.Chain) Pojo(org.nutz.dao.sql.Pojo) InsertByChainPItem(org.nutz.dao.impl.sql.pojo.InsertByChainPItem)

Aggregations

Pojo (org.nutz.dao.sql.Pojo)49 SqlFieldMacro (org.nutz.dao.impl.entity.macro.SqlFieldMacro)6 ExitLoop (org.nutz.lang.ExitLoop)5 LoopException (org.nutz.lang.LoopException)5 ManyManyLinkField (org.nutz.dao.impl.entity.field.ManyManyLinkField)4 ArrayList (java.util.ArrayList)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 Map (java.util.Map)2 DaoException (org.nutz.dao.DaoException)2 LinkField (org.nutz.dao.entity.LinkField)2 LinkVisitor (org.nutz.dao.entity.LinkVisitor)2 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