Package org.nutz.dao.sql

Examples of org.nutz.dao.sql.Sql


    }

    @Test
    public void check_Update_SQL() {
        SqlManager sqls = createSqls();
        Sql sql = sqls.create(".abc.update");
        assertTrue(sql.toString().toUpperCase().startsWith("UPDATE"));
    }
View Full Code Here


    }

    @Test
    public void check_Fetch_SQL() {
        SqlManager sqls = createSqls();
        Sql sql = sqls.create("abc.fetch");
        assertTrue(sql.toString().toUpperCase().startsWith("SELECT"));
    }
View Full Code Here

    }

    @Test
    public void check_Query_SQL() {
        SqlManager sqls = createSqls();
        Sql sql = sqls.create("abc.query");
        assertTrue(sql.toString().toUpperCase().startsWith("SELECT"));
    }
View Full Code Here

    @Test
    public void test_parse_whole_directory() {
        SqlManager sqls = new FileSqlManager("org/nutz/dao/test/sqls/dir");
        assertTrue(sqls.count() > 0);
        Sql sql = sqls.create(".abc.update");
        sql.params().set("name", "ABC");
        sql.params().set("id", 16);
        assertEquals("UPDATE t_abc SET name='ABC' WHERE id=16;", sql.toString());
    }
View Full Code Here

public class SqlImplTest {

    @Test
    public void test_sql_get_list() {
        Sql sql = Sqls.create("SELECT version()");
        ArrayList<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
        list.add(new HashMap<Object, Object>());
        list.add(new HashMap<Object, Object>());

        sql.getContext().setResult(list);

        List<?> re = sql.getList(Map.class);// 传入 map结果会导致上面的isFrom 为false
        assertTrue(re == list);

        re = sql.getList(HashMap.class);// 因为list中的实例是HashMap,因此能够正常返回
        assertTrue(re == list);
    }
View Full Code Here

        if (dao.meta().isOracle())
            return;
        pojos.initPet();
        dao.insert(Pet.create(4));

        Sql sql = Sqls.create("SELECT 'pet_02' IN (SELECT name FROM t_pet)");
        sql.setCallback(new FetchBooleanCallback());
        dao.execute(sql);
        boolean pet02IsExsit = sql.getBoolean();
        assertEquals(true, pet02IsExsit);

        sql = Sqls.create("SELECT 'pet_05' IN (SELECT name FROM t_pet)");
        sql.setCallback(new FetchBooleanCallback());
        dao.execute(sql);
        boolean pet05IsExsit = sql.getBoolean();
        assertEquals(false, pet05IsExsit);
    }
View Full Code Here

public class CustomizedSqlsTest extends DaoCase {

    @Test
    public void test_escape_varname_test() {
        Sql sql = Sqls.create("A_$xyz$_B");
        sql.vars().set("xyz", "X");
        assertEquals("A_X_B", sql.toString());
    }
View Full Code Here

        // For mysql only
        if (dao.meta().isMySql()) {
            pojos.initPet();
            dao.insert(Pet.create(8));
            assertEquals(8, dao.count(Pet.class));
            Sql sql = Sqls.queryEntity("SELECT * FROM t_pet $condition LIMIT @off,@size ");
            sql.setEntity(dao.getEntity(Pet.class));
            sql.params().set("off", 2).set("size", 2);
            sql.setCondition(Cnd.orderBy().asc("name"));
            dao.execute(sql);
            List<Pet> pets = sql.getList(Pet.class);
            assertEquals(2, pets.size());
            assertEquals("pet_02", pets.get(0).getName());
            assertEquals("pet_03", pets.get(1).getName());

        } else {
View Full Code Here

    @Test
    public void test_query_without_entity() {
        pojos.initPet();
        dao.insert(Pet.create(4));
        Sql sql = Sqls.create("SELECT * FROM t_pet $condition");
        sql.setCondition(Cnd.where("name", "like", "pet_%").asc("name"));
        sql.setCallback(new SqlCallback() {
            public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
                List<Pet> pets = new ArrayList<Pet>(4);
                while (rs.next())
                    pets.add(dao.getObject(Pet.class, rs, null));
                return pets;
            }
        });
        dao.execute(sql);
        List<Pet> pets = sql.getList(Pet.class);
        assertEquals(4, pets.size());
        assertEquals("pet_00", pets.get(0).getName());
        assertEquals("pet_01", pets.get(1).getName());
        assertEquals("pet_02", pets.get(2).getName());
        assertEquals("pet_03", pets.get(3).getName());
View Full Code Here

        pojos.init();
        ((NutDao) dao).setSqlManager(new FileSqlManager("org/nutz/dao/test/sqls/exec.sqls"));
        int platoonId = 23;
        try {
            pojos.initPlatoon(platoonId);
            Sql sql = dao.sqls().create("tank.insert");
            sql.vars().set("id", platoonId);
            sql.params().set("code", "T1").set("weight", 12);
            dao.execute(sql);

            sql = dao.sqls().create("tank.insert");
            sql.vars().set("id", platoonId);
            sql.params().set("code", "T2").set("weight", 13);
            dao.execute(sql);

            sql = dao.sqls().create("tank.insert");
            sql.vars().set("id", platoonId);
            sql.params().set("code", "T3").set("weight", 14);
            dao.execute(sql);

            sql = dao.sqls().create("tank.insert");
            sql.vars().set("id", platoonId);
            sql.params().set("code", "T4").set("weight", 15);
            dao.execute(sql);

            TableName.run(platoonId, new Atom() {
                public void run() {
                    assertEquals(4, dao.count(Tank.class));
View Full Code Here

TOP

Related Classes of org.nutz.dao.sql.Sql

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.