Search in sources :

Example 6 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 7 with Pet

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

Example 8 with Pet

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

Example 9 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 10 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)

Aggregations

Pet (org.nutz.dao.test.meta.Pet)48 Test (org.junit.Test)45 Issue1163Pet (org.nutz.dao.test.meta.issue1163.Issue1163Pet)13 Atom (org.nutz.trans.Atom)8 Sql (org.nutz.dao.sql.Sql)7 ArrayList (java.util.ArrayList)6 Record (org.nutz.dao.entity.Record)5 List (java.util.List)4 HashMap (java.util.HashMap)3 NutDao (org.nutz.dao.impl.NutDao)3 NutSql (org.nutz.dao.impl.sql.NutSql)3 SimpleCriteria (org.nutz.dao.util.cri.SimpleCriteria)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)2 Cnd (org.nutz.dao.Cnd)2 Criteria (org.nutz.dao.sql.Criteria)2 Master (org.nutz.dao.test.meta.Master)2 Stopwatch (org.nutz.lang.Stopwatch)2 Molecule (org.nutz.trans.Molecule)2