use of org.nutz.dao.pager.ResultSetLooping 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();
}
use of org.nutz.dao.pager.ResultSetLooping 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();
}
use of org.nutz.dao.pager.ResultSetLooping 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();
}
use of org.nutz.dao.pager.ResultSetLooping 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;
}
use of org.nutz.dao.pager.ResultSetLooping 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();
}
Aggregations