Search in sources :

Example 1 with RelationObjectMap

use of org.nutz.dao.util.RelationObjectMap in project nutz by nutzam.

the class DoInsertRelationLinkVisitor method visit.

public void visit(final Object obj, LinkField lnk) {
    // 只有多对多的映射才被考虑
    if (lnk instanceof ManyManyLinkField) {
        // 获取两边映射主键的值
        final ManyManyLinkField mm = (ManyManyLinkField) lnk;
        Object value = lnk.getValue(obj);
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(Lang.length(value));
        Lang.each(value, new Each<Object>() {

            public void invoke(int i, Object ele, int length) throws ExitLoop, LoopException {
                list.add(new RelationObjectMap(mm, obj, ele));
            }
        });
        if (list.isEmpty())
            return;
        Entity<Map<String, Object>> en = holder.makeEntity(mm.getRelationName(), list.get(0));
        Pojo pojo = opt.maker().makeInsert(en);
        pojo.setOperatingObject(list);
        for (Object p : list) pojo.addParamsBy(p);
        opt.add(pojo);
    }
}
Also used : Pojo(org.nutz.dao.sql.Pojo) ArrayList(java.util.ArrayList) ManyManyLinkField(org.nutz.dao.impl.entity.field.ManyManyLinkField) RelationObjectMap(org.nutz.dao.util.RelationObjectMap) ExitLoop(org.nutz.lang.ExitLoop) LoopException(org.nutz.lang.LoopException) RelationObjectMap(org.nutz.dao.util.RelationObjectMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ManyManyLinkField (org.nutz.dao.impl.entity.field.ManyManyLinkField)1 Pojo (org.nutz.dao.sql.Pojo)1 RelationObjectMap (org.nutz.dao.util.RelationObjectMap)1 ExitLoop (org.nutz.lang.ExitLoop)1 LoopException (org.nutz.lang.LoopException)1