Search in sources :

Example 36 with Pet

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

the class FieldFilterTest method test_insert_by_filter.

@Test
public void test_insert_by_filter() {
    // insert one pet
    final Pet p = pet("xh").setNickName("XiaoHei");
    FieldFilter.create(Pet.class, "id|name").run(new Atom() {

        public void run() {
            dao.insert(p);
        }
    });
    Pet p2 = dao.fetch(Pet.class, p.getId());
    assertNull(p2.getNickName());
}
Also used : Pet(org.nutz.dao.test.meta.Pet) Atom(org.nutz.trans.Atom) Test(org.junit.Test)

Example 37 with Pet

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

the class FieldFilterTest method test_select_by_filter.

@Test
public void test_select_by_filter() {
    dao.update(dao.fetch(Pet.class, "xb").setNickName("XiaoBai"));
    assertEquals("XiaoBai", dao.fetch(Pet.class, "xb").getNickName());
    final Pet[] pets = new Pet[1];
    FieldFilter.create(Pet.class, "id|name").run(new Atom() {

        public void run() {
            pets[0] = dao.fetch(Pet.class, "xb");
        }
    });
    assertNull(pets[0].getNickName());
}
Also used : Pet(org.nutz.dao.test.meta.Pet) Atom(org.nutz.trans.Atom) Test(org.junit.Test)

Example 38 with Pet

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

the class InsertTest method test_fastinsert_as_rollback.

/**
     * Github Issue #131
     */
@Test
public void test_fastinsert_as_rollback() {
    dao.create(Pet.class, true);
    // 在插入数据中有错误 ...
    final Pet[] pets = Pet.create(10);
    pets[4].setName(Strings.dup('t', 1024));
    try {
        Trans.exec(new Atom() {

            public void run() {
                dao.fastInsert(pets);
            }
        });
    } catch (RuntimeException e) {
    }
    assertEquals(0, dao.count(Pet.class));
    // 插入后,主动抛出一个错误,看回滚不回滚
    try {
        final Pet[] pets2 = Pet.create(10);
        Trans.exec(new Atom() {

            public void run() {
                dao.fastInsert(pets2);
                throw new RuntimeException("I am ok!");
            }
        });
    } catch (RuntimeException e) {
        assertEquals("I am ok!", e.getMessage());
    }
    assertEquals(0, dao.count(Pet.class));
}
Also used : Pet(org.nutz.dao.test.meta.Pet) Atom(org.nutz.trans.Atom) Test(org.junit.Test)

Example 39 with Pet

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

the class QueryTest method test_query_by_fieldfilter.

/**
     * add for Issue #605
     */
@Test
public void test_query_by_fieldfilter() {
    Molecule<List<Pet>> mo = new Molecule<List<Pet>>() {

        public void run() {
            setObj(dao.query(Pet.class, Cnd.orderBy().asc("id")));
        }
    };
    FieldFilter.create(Pet.class, "^id|name$").run(mo);
    int i = 0;
    for (Pet pet : mo.getObj()) {
        assertEquals(i + 1, pet.getId());
        assertEquals("pet" + i, pet.getName());
        assertEquals(0, pet.getAge());
        assertNull(pet.getBirthday());
        assertNull(pet.getNickName());
        i++;
    }
}
Also used : Molecule(org.nutz.trans.Molecule) List(java.util.List) Pet(org.nutz.dao.test.meta.Pet) Test(org.junit.Test)

Example 40 with Pet

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

the class QueryTest method fetch_by_name.

@Test
public void fetch_by_name() {
    Pet pet = dao.fetch(Pet.class, Cnd.where("name", "=", "pet2"));
    assertEquals("pet2", pet.getName());
}
Also used : Pet(org.nutz.dao.test.meta.Pet) Test(org.junit.Test)

Aggregations

Pet (org.nutz.dao.test.meta.Pet)48 Test (org.junit.Test)45 Issue1163Pet (org.nutz.dao.test.meta.issue1163.Issue1163Pet)13 Atom (org.nutz.trans.Atom)8 Sql (org.nutz.dao.sql.Sql)7 ArrayList (java.util.ArrayList)6 Record (org.nutz.dao.entity.Record)5 List (java.util.List)4 HashMap (java.util.HashMap)3 NutDao (org.nutz.dao.impl.NutDao)3 NutSql (org.nutz.dao.impl.sql.NutSql)3 SimpleCriteria (org.nutz.dao.util.cri.SimpleCriteria)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 Cnd (org.nutz.dao.Cnd)2 Criteria (org.nutz.dao.sql.Criteria)2 Master (org.nutz.dao.test.meta.Master)2 Stopwatch (org.nutz.lang.Stopwatch)2 Molecule (org.nutz.trans.Molecule)2