Package org.nutz.dao.sql

Examples of org.nutz.dao.sql.Sql


    @Test
    public void test_dynamic_query() {
        pojos.init();
        Platoon p = pojos.create4Platoon(Base.make("xyz"), "GG");
        Sql sql = dao.sqls().create("tank.query").setEntity(dao.getEntity(Tank.class));
        sql.vars().set("id", p.getId());
        sql.setCallback(Sqls.callback.entities());
        dao.execute(sql);
        assertEquals(2, sql.getList(Tank.class).size());

        pojos.dropPlatoon(p.getId());
    }
View Full Code Here


    }

    @Test
    public void test_statice_null_field() {
        pojos.init();
        Sql sql = Sqls.create("INSERT INTO dao_country (name,detail) VALUES(@name,@detail)");
        sql.params().set("name", "ABC").set("detail", "haha");
        dao.execute(sql);
        assertEquals(1, dao.count("dao_country"));

        sql = Sqls.create("UPDATE dao_country SET detail=@detail WHERE name=@name");
        sql.params().set("name", "ABC").set("detail", null);
        dao.execute(sql);
        Country c = dao.fetch(Country.class, "ABC");
        assertNull(c.getDetail());
    }
View Full Code Here

    }
   
    @Test
    public void test_cnd_pager() {
        pojos.init();
        Sql sql = Sqls.create("select * from t_pet $condition");
        sql.setCondition(Cnd.where("name", "=", "wendal"));
        Pager pager = dao.createPager(1, 20);
        sql.setPager(pager);
        dao.execute(sql);
    }
View Full Code Here

            return;
        }
        List<Sql> sqls = new ArrayList<Sql>();
        // 表注释
        if (en.hasTableComment()) {
            Sql tableCommentSQL = Sqls.create(Strings.isBlank(commentTable)    ? DEFAULT_COMMENT_TABLE
                                                                            : commentTable);
            tableCommentSQL.vars()
                            .set("table", en.getTableName())
                            .set("tableComment", en.getTableComment());
            sqls.add(tableCommentSQL);
        }
        // 字段注释
        if (en.hasColumnComment()) {
            for (MappingField mf : en.getMappingFields()) {
                if (mf.hasColumnComment()) {
                    Sql columnCommentSQL = Sqls.create(Strings.isBlank(commentColumn)    ? DEFAULT_COMMENT_COLUMN
                                                                                        : commentColumn);
                    columnCommentSQL.vars()
                                    .set("table", en.getTableName())
                                    .set("column", mf.getColumnName())
                                    .set("columnComment", mf.getColumnComment());
                    sqls.add(columnCommentSQL);
                }
View Full Code Here

        }
        return pager;
    }

    public static <T> List<T> queryList(Dao dao, Class<T> klass, String sql_str) {
        Sql sql = Sqls.create(sql_str)
                        .setCallback(Sqls.callback.entities())
                        .setEntity(dao.getEntity(klass));
        dao.execute(sql);
        return sql.getList(klass);
    }
View Full Code Here

        dao.execute(sql);
        return sql.getList(klass);
    }

    public static Object query(Dao dao, String sql_str, SqlCallback callback) {
        Sql sql = Sqls.create(sql_str).setCallback(callback);
        dao.execute(sql);
        return sql.getResult();
    }
View Full Code Here

   
    /**
     * 查询sql并把结果放入传入的class组成的List中
     */
    public static <T> List<T> query(Dao dao, Class<T> classOfT, String sql, Condition cnd, Pager pager) {
        Sql sql2 = Sqls.queryEntity(sql);
        sql2.setEntity(dao.getEntity(classOfT));
        sql2.setCondition(cnd);
        sql2.setPager(pager);
        dao.execute(sql2);
        return sql2.getList(classOfT);
    }
View Full Code Here

   
    /**
     * 查询某sql的结果条数
     */
    public static int queryCount(Dao dao, String sql) {
        Sql sql2 = Sqls.fetchLong("select count(1) FROM ("+sql+")");
        dao.execute(sql2);
        return sql2.getInt();
    }
View Full Code Here

    }

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

    }

    @Test
    public void check_Insert_SQL() {
        SqlManager sqls = createSqls();
        Sql sql = sqls.create(".abc.insert");
        assertTrue(sql.toString().toUpperCase().startsWith("INSERT"));
    }
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.