Package org.nutz.dao.sql

Examples of org.nutz.dao.sql.Sql


     *            参数map,无参数时,可为null
     *
     * @return SQL 语句所影响的行数
     */
    public int update(String sql, Map<String, Object> vars, Map<String, Object> params) {
        Sql sqlObj = createSqlObj(sql, params);
        execute(sqlObj, vars, params);
        return sqlObj.getUpdateCount();
    }
View Full Code Here


     * @return SQL 语句所影响的行数
     */
    public int batchUpdate(String sql,
                           Map<String, Object> vars,
                           List<Map<String, Object>> batchValues) {
        Sql sqlObj = null;
        boolean hasBatchValues = batchValues != null && batchValues.size() > 0;
        if (hasBatchValues) {
            sqlObj = createSqlObj(sql, batchValues.get(0));
            for (Map<String, Object> params : batchValues) {
                Map<String, Object> newParams = paramProcess(params);
                sqlObj.params().putAll(newParams);
                sqlObj.addBatch();
            }
            dao.execute(sqlObj);
        } else {
            sqlObj = createSqlObj(sql, null);
            execute(sqlObj, vars, null);
        }

        return sqlObj.getUpdateCount();
    }
View Full Code Here

     *            参数map,无参数时,可为null
     *
     * @return int数值,当查询为null时返回0
     */
    public int queryForInt(String sql, Map<String, Object> vars, Map<String, Object> params) {
        Sql sqlObj = createSqlObj(sql, params);
        sqlObj.setCallback(Sqls.callback.integer());
        execute(sqlObj, vars, params);
        return sqlObj.getInt();
    }
View Full Code Here

     *            参数map,无参数时,可为null
     *
     * @return long数值,当查询为null时返回0
     */
    public long queryForLong(String sql, Map<String, Object> vars, Map<String, Object> params) {
        Sql sqlObj = createSqlObj(sql, params);
        sqlObj.setCallback(Sqls.callback.longValue());
        execute(sqlObj, vars, params);
        Long result = sqlObj.getObject(Long.class);
        return result == null ? 0 : result;
    }
View Full Code Here

     */
    public <T> T queryForObject(String sql,
                                Map<String, Object> vars,
                                Map<String, Object> params,
                                Class<T> classOfT) {
        Sql sqlObj = createSqlObj(sql, params);
        sqlObj.setCallback(new SqlCallback() {
            public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
                if (null != rs && rs.next())
                    return rs.getObject(1);
                return null;
            }
        });

        execute(sqlObj, vars, params);
        return sqlObj.getObject(classOfT);
    }
View Full Code Here

     */
    public <T> T queryForObject(String sql,
                                Map<String, Object> vars,
                                Map<String, Object> params,
                                Entity<T> entity) {
        Sql sqlObj = createSqlObj(sql, params);
        sqlObj.setCallback(Sqls.callback.entity());
        sqlObj.setEntity(entity);

        execute(sqlObj, vars, params);

        return sqlObj.getObject(entity.getType());
    }
View Full Code Here

     * @param params
     *            参数map,无参数时,可为null
     * @return Record对象,无查询结果时返回null
     */
    public Record queryForRecord(String sql, Map<String, Object> vars, Map<String, Object> params) {
        Sql sqlObj = createSqlObj(sql, params);
        sqlObj.setCallback(Sqls.callback.record());

        execute(sqlObj, vars, params);

        return sqlObj.getObject(Record.class);
    }
View Full Code Here

     */
    public <T> List<T> query(String sql,
                             Map<String, Object> vars,
                             Map<String, Object> params,
                             Entity<T> entity) {
        Sql sqlObj = createSqlObj(sql, params);
        sqlObj.setCallback(Sqls.callback.entities());
        sqlObj.setEntity(entity);

        execute(sqlObj, vars, params);

        return sqlObj.getList(entity.getType());
    }
View Full Code Here

     */
    public <T> List<T> queryForList(String sql,
                                    Map<String, Object> vars,
                                    Map<String, Object> params,
                                    final Class<T> classOfT) {
        Sql sqlObj = createSqlObj(sql, params);

        sqlObj.setCallback(new SqlCallback() {
            public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
                List<T> list = new ArrayList<T>();
                while (rs.next()) {
                    T result = Castors.me().castTo(rs.getObject(1), classOfT);
                    list.add(result);
                }
                return list;
            }
        });

        execute(sqlObj, vars, params);

        return sqlObj.getList(classOfT);
    }
View Full Code Here

     * @return Record列表,无查询结果时返回长度为0的List对象
     */
    public List<Record> queryRecords(String sql,
                                     Map<String, Object> vars,
                                     Map<String, Object> params) {
        Sql sqlObj = createSqlObj(sql, params);
        sqlObj.setCallback(Sqls.callback.records());

        execute(sqlObj, vars, params);

        return sqlObj.getList(Record.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.