Package org.nutz.dao.impl.entity.field

Examples of org.nutz.dao.impl.entity.field.ManyManyLinkField


    }

    protected void dropRelation(Dao dao, Entity<?> en) {
        final List<Sql> sqls = new ArrayList<Sql>(5);
        for (LinkField lf : en.visitManyMany(null, null, null)) {
            ManyManyLinkField mm = (ManyManyLinkField) lf;
            if (!dao.exists(mm.getRelationName()))
                continue;
            sqls.add(Sqls.create("DROP TABLE " + mm.getRelationName()));
        }
        dao.execute(sqls.toArray(new Sql[sqls.size()]));
    }
View Full Code Here


        for (LinkInfo li : manys) {
            en.addLinkField(new ManyLinkField(en, holder, li));
        }
        // 多对多 '@ManyMany'
        for (LinkInfo li : manymanys) {
            en.addLinkField(new ManyManyLinkField(en, holder, li));
        }
        // 检查复合主键
        en.checkCompositeFields(null == ti.annPK ? null : ti.annPK.value());

        /*
 
View Full Code Here

    }

    @Test
    public void eval_manymany() {
        Entity<?> en = en(Base.class);
        ManyManyLinkField link = (ManyManyLinkField) en.getLinkFields("fighters").get(0);
        assertEquals("dao_m_base_fighter", link.getRelationName());
    }
View Full Code Here

    }

    protected void createRelation(Dao dao, Entity<?> en) {
        final List<Sql> sqls = new ArrayList<Sql>(5);
        for (LinkField lf : en.visitManyMany(null, null, null)) {
            ManyManyLinkField mm = (ManyManyLinkField) lf;
            if (dao.exists(mm.getRelationName()))
                continue;
            String sql = "CREATE TABLE " + mm.getRelationName() + "(";
            sql += mm.getFromColumnName() + " " + evalFieldType(mm.getHostField()) + ",";
            sql += mm.getToColumnName() + " " + evalFieldType(mm.getLinkedField());
            sql += ")";
            sqls.add(Sqls.create(sql));
        }
        dao.execute(sqls.toArray(new Sql[sqls.size()]));
    }
View Full Code Here

    }

    protected void dropRelation(Dao dao, Entity<?> en) {
        final List<Sql> sqls = new ArrayList<Sql>(5);
        for (LinkField lf : en.visitManyMany(null, null, null)) {
            ManyManyLinkField mm = (ManyManyLinkField) lf;
            if (!dao.exists(mm.getRelationName()))
                continue;
            sqls.add(Sqls.create("DROP TABLE " + mm.getRelationName()));
        }
        dao.execute(sqls.toArray(new Sql[sqls.size()]));
    }
View Full Code Here

        this.items = Pojos.Items.cnd(cnd);
    }

    public void visit(Object obj, LinkField lnk) {
        if (lnk instanceof ManyManyLinkField) {
            ManyManyLinkField mm = (ManyManyLinkField) lnk;
            Entity<?> en = opt.makeEntity(mm.getRelationName(), map);
            Pojo pojo = opt.maker().makeUpdate(en, null);
            pojo.setOperatingObject(map);
            pojo.append(items);
            opt.add(pojo);
        }
View Full Code Here

    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);
View Full Code Here

public class DoClearRelationByHostFieldLinkVisitor extends AbstractLinkVisitor {

    public void visit(Object obj, LinkField lnk) {
        if (lnk instanceof ManyManyLinkField) {
            final ManyManyLinkField mm = (ManyManyLinkField) lnk;

            final Pojo pojo = opt.maker().makeDelete(mm.getRelationName());
            pojo.append(Pojos.Items.cndColumn(    mm.getFromColumnName(),
                                                mm.getHostField(),
                                                mm.getHostField().getValue(obj)));

            opt.add(pojo);
        }
    }
View Full Code Here

    }

    @Test
    public void eval_manymany() {
        Entity<?> en = en(Base.class);
        ManyManyLinkField link = (ManyManyLinkField) en.getLinkFields("fighters").get(0);
        assertEquals("dao_m_base_fighter", link.getRelationName());
    }
View Full Code Here

    @Test
    public void tank_many_many_link_test() {
        pojos.initPlatoon(1);
        TableName.set(1);
        Entity<?> en = dao.getEntity(Tank.class);
        ManyManyLinkField link = (ManyManyLinkField) en.getLinkFields("members").get(0);
        assertEquals("dao_d_m_soldier_tank_1", link.getRelationName());
        assertEquals("id", link.getLinkedPkNames()[0]);
        assertEquals("name", link.getLinkedPkNames()[1]);
        TableName.clear();
        pojos.dropPlatoon(1);
    }
View Full Code Here

TOP

Related Classes of org.nutz.dao.impl.entity.field.ManyManyLinkField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.