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());
}
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());
}
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));
}
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++;
}
}
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());
}
Aggregations