Search in sources :

Example 1 with SqlContext

use of org.nutz.dao.sql.SqlContext in project nutz by nutzam.

the class QueryEntityCallback method process.

@Override
protected Object process(final ResultSet rs, final Entity<?> entity, final SqlContext context) throws SQLException {
    ResultSetLooping ing = new ResultSetLooping() {

        protected boolean createObject(int index, ResultSet rs, SqlContext context, int rowCount) {
            list.add(entity.getObject(rs, context.getFieldMatcher(), prefix));
            return true;
        }
    };
    ing.doLoop(rs, context);
    return ing.getList();
}
Also used : SqlContext(org.nutz.dao.sql.SqlContext) ResultSetLooping(org.nutz.dao.pager.ResultSetLooping) ResultSet(java.sql.ResultSet)

Example 2 with SqlContext

use of org.nutz.dao.sql.SqlContext in project nutz by nutzam.

the class QueryMapCallback method invoke.

public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
    final ResultSetMetaData meta = rs.getMetaData();
    // ResultSetLooping 封装了遍历结果集的方法,里面包含了针对sqlserver等浮标型分页的支持
    ResultSetLooping ing = new ResultSetLooping() {

        protected boolean createObject(int index, ResultSet rs, SqlContext context, int rowCout) {
            NutMap re = new NutMap();
            Record.create(re, rs, meta);
            list.add(re);
            return true;
        }
    };
    ing.doLoop(rs, sql.getContext());
    return ing.getList();
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SqlContext(org.nutz.dao.sql.SqlContext) ResultSetLooping(org.nutz.dao.pager.ResultSetLooping) ResultSet(java.sql.ResultSet) NutMap(org.nutz.lang.util.NutMap)

Example 3 with SqlContext

use of org.nutz.dao.sql.SqlContext in project nutz by nutzam.

the class QueryRecordCallback method invoke.

public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
    ResultSetLooping ing = new ResultSetLooping() {

        protected boolean createObject(int index, ResultSet rs, SqlContext context, int rowCout) {
            list.add(Record.create(rs));
            return true;
        }
    };
    ing.doLoop(rs, sql.getContext());
    return ing.getList();
}
Also used : SqlContext(org.nutz.dao.sql.SqlContext) ResultSetLooping(org.nutz.dao.pager.ResultSetLooping) ResultSet(java.sql.ResultSet)

Example 4 with SqlContext

use of org.nutz.dao.sql.SqlContext in project nutz by nutzam.

the class PojoEachRecordCallback method invoke.

@SuppressWarnings("unchecked")
public Object invoke(Connection conn, ResultSet rs, Pojo pojo, Statement stmt) throws SQLException {
    // 得到回调
    final Each<Object> each = pojo.getContext().attr(Each.class);
    // 没有回调,什么都不用执行了
    if (null == each)
        return null;
    // 开始执行
    ResultSetLooping ing = new ResultSetLooping() {

        protected boolean createObject(int index, ResultSet rs, SqlContext context, int rowCount) {
            Object obj = Record.create(rs);
            try {
                each.invoke(index, obj, rowCount);
            } catch (LoopException e) {
                throw Lang.wrapThrow(e);
            }
            return false;
        }
    };
    try {
        // 循环开始
        if (each instanceof Loop)
            if (!((Loop<?>) each).begin())
                return 0;
        // 循环中
        ing.doLoop(rs, pojo.getContext());
        // 循环结束
        if (each instanceof Loop)
            ((Loop<?>) each).end();
    } catch (ExitLoop e) {
    } catch (LoopException e) {
        throw new SQLException(e.getCause().getMessage());
    }
    // 返回数量
    return ing.getIndex() + 1;
}
Also used : Loop(org.nutz.lang.Loop) ExitLoop(org.nutz.lang.ExitLoop) SqlContext(org.nutz.dao.sql.SqlContext) LoopException(org.nutz.lang.LoopException) ExitLoop(org.nutz.lang.ExitLoop) ResultSetLooping(org.nutz.dao.pager.ResultSetLooping) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 5 with SqlContext

use of org.nutz.dao.sql.SqlContext in project nutz by nutzam.

the class PojoQueryEntityCallback method invoke.

public Object invoke(Connection conn, ResultSet rs, final Pojo pojo, Statement stmt) throws SQLException {
    ResultSetLooping ing = new ResultSetLooping() {

        protected boolean createObject(int index, ResultSet rs, SqlContext context, int rowCount) {
            list.add(pojo.getEntity().getObject(rs, context.getFieldMatcher(), prefix));
            return true;
        }
    };
    ing.doLoop(rs, pojo.getContext());
    return ing.getList();
}
Also used : SqlContext(org.nutz.dao.sql.SqlContext) ResultSetLooping(org.nutz.dao.pager.ResultSetLooping) ResultSet(java.sql.ResultSet)

Aggregations

ResultSet (java.sql.ResultSet)7 ResultSetLooping (org.nutz.dao.pager.ResultSetLooping)7 SqlContext (org.nutz.dao.sql.SqlContext)7 SQLException (java.sql.SQLException)2 ExitLoop (org.nutz.lang.ExitLoop)2 Loop (org.nutz.lang.Loop)2 LoopException (org.nutz.lang.LoopException)2 ResultSetMetaData (java.sql.ResultSetMetaData)1 ContinueLoop (org.nutz.lang.ContinueLoop)1 NutMap (org.nutz.lang.util.NutMap)1