use of org.nutz.dao.test.meta.Pet in project nutz by nutzam.
the class SimpleDaoExecTest method test_exec_out.
@Test
public void test_exec_out() {
if (!dao.meta().isMySql())
// Only test for mysql now
return;
dao.create(Pet.class, true);
dao.insert(Pet.create("wendal"));
Pet pet = dao.fetch(Pet.class, "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), OUT outId int)\nBEGIN\n\tselect id into outId from t_pet where name=nm;\nEND"));
// 像普通自定义SQL那样创建SQL对象.
Sql sql = Sqls.create("CALL proc_pet_fetch(@nm, @OUTid)");
sql.setEntity(dao.getEntity(Pet.class));
// 设置入参
sql.params().set("nm", "wendal");
// 设置出参类型,注意,必须加OUT开头
sql.params().set("OUTid", Types.INTEGER);
dao.execute(sql);
Record re = sql.getOutParams();
assertNotNull(re);
assertEquals(pet.getId(), re.get("id"));
}
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 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());
}
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 EachTest method each_by_like_ignorecase.
@Test
public void each_by_like_ignorecase() {
SimpleCriteria cri = Cnd.cri();
cri.where().andLike("name", "PeT6", true);
final List<Pet> pets = new ArrayList<Pet>();
dao.each(Pet.class, cri, dao.createPager(1, 10), new Each<Pet>() {
public void invoke(int i, Pet pet, int length) {
pets.add(pet);
}
});
assertEquals(1, pets.size());
assertEquals("pet6", pets.get(0).getName());
}
Aggregations