Search in sources :

Example 1 with Pet

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"));
}
Also used : Record(org.nutz.dao.entity.Record) Pet(org.nutz.dao.test.meta.Pet) Sql(org.nutz.dao.sql.Sql) Test(org.junit.Test)

Example 2 with Pet

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());
}
Also used : Pet(org.nutz.dao.test.meta.Pet) Sql(org.nutz.dao.sql.Sql) Test(org.junit.Test)

Example 3 with Pet

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());
}
Also used : Pet(org.nutz.dao.test.meta.Pet) Atom(org.nutz.trans.Atom) Test(org.junit.Test)

Example 4 with Pet

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;
}
Also used : Pet(org.nutz.dao.test.meta.Pet)

Example 5 with Pet

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());
}
Also used : SimpleCriteria(org.nutz.dao.util.cri.SimpleCriteria) ArrayList(java.util.ArrayList) Pet(org.nutz.dao.test.meta.Pet) Test(org.junit.Test)

Aggregations

Pet (org.nutz.dao.test.meta.Pet)57 Test (org.junit.Test)54 Issue1163Pet (org.nutz.dao.test.meta.issue1163.Issue1163Pet)14 AbcPet (org.nutz.dao.test.meta.nutzcn.AbcPet)14 Atom (org.nutz.trans.Atom)9 Sql (org.nutz.dao.sql.Sql)8 ArrayList (java.util.ArrayList)7 Record (org.nutz.dao.entity.Record)5 Master (org.nutz.dao.test.meta.Master)5 List (java.util.List)4 NutDao (org.nutz.dao.impl.NutDao)4 SimpleCriteria (org.nutz.dao.util.cri.SimpleCriteria)4 HashMap (java.util.HashMap)3 Cnd (org.nutz.dao.Cnd)3 NutSql (org.nutz.dao.impl.sql.NutSql)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 LinkedList (java.util.LinkedList)2 Criteria (org.nutz.dao.sql.Criteria)2