Search in sources :

Example 1 with Fighter

use of org.nutz.dao.test.meta.Fighter in project nutz by nutzam.

the class ManyManyTest method update_links.

@Test
public void update_links() {
    Base b = dao.fetchLinks(dao.fetch(Base.class, "blue"), "fighters");
    int lv = b.getLevel();
    b.setLevel(45);
    for (Iterator<Fighter> it = b.getFighters().iterator(); it.hasNext(); ) {
        it.next().setType(Fighter.TYPE.F22);
    }
    dao.updateLinks(b, "fighters");
    b = dao.fetch(Base.class, "blue");
    assertEquals(lv, b.getLevel());
    b = dao.fetchLinks(dao.fetch(Base.class, "blue"), "fighters");
    assertEquals(7, b.countFighter(Fighter.TYPE.F22));
}
Also used : Fighter(org.nutz.dao.test.meta.Fighter) Base(org.nutz.dao.test.meta.Base) Test(org.junit.Test)

Example 2 with Fighter

use of org.nutz.dao.test.meta.Fighter in project nutz by nutzam.

the class ManyManyTest method update_with.

@Test
public void update_with() {
    Base b = dao.fetchLinks(dao.fetch(Base.class, "blue"), "fighters");
    b.setLevel(45);
    for (Iterator<Fighter> it = b.getFighters().iterator(); it.hasNext(); ) {
        it.next().setType(Fighter.TYPE.F22);
    }
    dao.updateWith(b, "fighters");
    b = dao.fetch(Base.class, "blue");
    assertEquals(45, b.getLevel());
    b = dao.fetchLinks(dao.fetch(Base.class, "blue"), "fighters");
    assertEquals(7, b.countFighter(Fighter.TYPE.F22));
}
Also used : Fighter(org.nutz.dao.test.meta.Fighter) Base(org.nutz.dao.test.meta.Base) Test(org.junit.Test)

Example 3 with Fighter

use of org.nutz.dao.test.meta.Fighter in project nutz by nutzam.

the class BatchTransTest method try_insert_static_objects_by_many_many.

@Test
public void try_insert_static_objects_by_many_many() {
    pojos.init();
    final Base b = Base.make("B");
    b.setFighters(new ArrayList<Fighter>());
    TableName.run(1, new Atom() {

        public void run() {
            Trans.exec(new Atom() {

                public void run() {
                    dao.insert(Country.make("A"));
                    try {
                        dao.insert(Country.make("A"));
                    } catch (DaoException e) {
                    }
                    dao.insert(Country.make("C"));
                    dao.insert(Country.make("D"));
                }
            });
            assertEquals(3, dao.count(Country.class));
        }
    });
}
Also used : Fighter(org.nutz.dao.test.meta.Fighter) DaoException(org.nutz.dao.DaoException) Base(org.nutz.dao.test.meta.Base) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Base (org.nutz.dao.test.meta.Base)3 Fighter (org.nutz.dao.test.meta.Fighter)3 DaoException (org.nutz.dao.DaoException)1