use of org.nutz.dao.test.meta.Pet in project nutz by nutzam.
the class SimpleDaoExecTest method test_simple_mysql_exec2.
// Mysql支持存储过程
@Test
public void test_simple_mysql_exec2() {
if (!dao.meta().isMySql())
// Only test for mysql now
return;
dao.create(Pet.class, true);
dao.insert(Pet.create("wendal"));
dao.execute(Sqls.create("DROP PROCEDURE IF EXISTS proc_pet_fetch"));
dao.execute(Sqls.create("CREATE PROCEDURE proc_pet_fetch(IN nm varchar(1024))\nBEGIN\n\tSELECT * FROM t_pet where name=nm;\nEND"));
Sql sql = Sqls.fetchEntity("CALL proc_pet_fetch(@nm)");
sql.setEntity(dao.getEntity(Pet.class));
sql.params().set("nm", "wendal");
dao.execute(sql);
Pet pet = sql.getObject(Pet.class);
assertNotNull(pet);
assertEquals("wendal", pet.getName());
}
use of org.nutz.dao.test.meta.Pet in project nutz by nutzam.
the class SqlLiteralTest method test_param_names_putall_map.
@Test
public void test_param_names_putall_map() {
NutSql sql = L("INSERT INTO t_pet($id,$name,$alias,$age) VALUES(@id,@name,@nickName,@age)");
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", "userId");
map.put("name", "userName");
map.put("alias", "alias");
map.put("age", "age");
Pet pet = new Pet();
pet.setId(18);
pet.setName("pet");
pet.setNickName("haha");
pet.setAge(5);
sql.vars().putAll(map);
sql.params().putAll(pet);
String expect = "INSERT INTO t_pet(userId,userName,alias,age) VALUES(18,'pet','haha',5)";
assertEquals(expect, sql.toString());
}
use of org.nutz.dao.test.meta.Pet in project nutz by nutzam.
the class SimpleTransTest method test_update_rollback.
@Test
public void test_update_rollback() {
dao.create(Pet.class, true);
dao.insert(Pet.create("XiaoBai"));
dao.insert(Pet.create("XiaoHei"));
final Pet pet1 = dao.fetch(Pet.class, "XiaoBai");
final Pet pet2 = dao.fetch(Pet.class, "XiaoHei");
pet1.setName("A");
pet2.setName("A");
// Begin transaction
Trans.DEBUG = true;
try {
Trans.exec(new Atom() {
public void run() {
dao.update(pet1);
System.out.println(dao.fetch(Pet.class, pet1.getId()).getName());
dao.update(pet2);
//throw Lang.noImplement();
}
});
} catch (Exception e) {
e.printStackTrace();
}
// End transaction
System.out.println(dao.fetch(Pet.class, pet1.getId()).getName());
assertFalse(dao.fetch(Pet.class, pet1.getId()).getName().equals(pet1.getName()));
}
use of org.nutz.dao.test.meta.Pet in project nutz by nutzam.
the class FieldFilterTest method pet.
private static Pet pet(String name) {
Pet p = new Pet();
p.setName(name);
return p;
}
use of org.nutz.dao.test.meta.Pet in project nutz by nutzam.
the class FieldFilterTest method test_update_by_filter.
@Test
public void test_update_by_filter() {
final Pet p = dao.fetch(Pet.class, "xb");
p.setNickName("XiaoBai");
FieldFilter.create(Pet.class, "id|name").run(new Atom() {
public void run() {
dao.update(p);
}
});
Pet p2 = dao.fetch(Pet.class, p.getId());
assertNull(p2.getNickName());
}
Aggregations