use of org.nutz.trans.Atom in project nutz by nutzam.
the class FieldFilterTest method test_query_by_filter.
@Test
public void test_query_by_filter() {
dao.update(dao.fetch(Pet.class, "xb").setNickName("XiaoBai"));
assertEquals("XiaoBai", dao.fetch(Pet.class, "xb").getNickName());
final List<Pet> pets = new ArrayList<Pet>();
FieldFilter.create(Pet.class, "id|name").run(new Atom() {
public void run() {
pets.add(dao.query(Pet.class, null, null).get(0));
}
});
assertNull(pets.get(0).getNickName());
}
use of org.nutz.trans.Atom in project nutz by nutzam.
the class FieldFilterTest method test_filter_no_field_match.
// Issue 435
@Test(expected = DaoException.class)
public void test_filter_no_field_match() {
dao.create(EmtryObject.class, true);
final EmtryObject obj = new EmtryObject();
// 应该抛出一个DaoException,因为没有任何的字段需要插入!
FieldFilter.create(EmtryObject.class, "id").run(new Atom() {
public void run() {
dao.insert(obj);
}
});
}
use of org.nutz.trans.Atom 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.trans.Atom 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.trans.Atom 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));
}
Aggregations