Examples of ResultSetLooping


Examples of org.nutz.dao.pager.ResultSetLooping

import org.nutz.dao.sql.SqlContext;

public class PojoQueryEntityCallback implements PojoCallback {

  public Object invoke(Connection conn, ResultSet rs, final Pojo pojo) throws SQLException {
    return new ResultSetLooping() {
      protected Object createObject(ResultSet rs, SqlContext context) {
        return pojo.getEntity().getObject(rs, context.getFieldMatcher());
      }
    }.doLoop(rs, pojo.getContext());
  }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

import org.nutz.dao.sql.SqlContext;

public class QueryRecordCallback implements SqlCallback {

  public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
    return new ResultSetLooping() {
      protected Object createObject(ResultSet rs, SqlContext context) {
        return Record.create(rs);
      }
    }.doLoop(rs, sql.getContext());
  }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

import org.nutz.dao.sql.SqlContext;

public class PojoQueryRecordCallback implements PojoCallback {

  public Object invoke(Connection conn, ResultSet rs, Pojo pojo) throws SQLException {
    return new ResultSetLooping() {
      protected Object createObject(ResultSet rs, SqlContext context) {
        return Record.create(rs);
      }
    }.doLoop(rs, pojo.getContext());
  }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

public class QueryEntityCallback extends EntityCallback {

  @Override
  protected Object process(final ResultSet rs, final Entity<?> entity, final SqlContext context)
      throws SQLException {
    return new ResultSetLooping() {
      protected Object createObject(ResultSet rs, SqlContext context) {
        return entity.getObject(rs, context.getFieldMatcher());
      }
    }.doLoop(rs, context);
  }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

            throws SQLException {

        final ResultSetMetaData meta = rs.getMetaData();
        final int count = meta.getColumnCount();
        // ResultSetLooping 封装了遍历结果集的方法,里面包含了针对sqlserver等浮标型分页的支持
        ResultSetLooping ing = new ResultSetLooping() {
            protected boolean createObject(int index,
                                           ResultSet rs,
                                           SqlContext context,
                                           int rowCout) {
                String name = null;
                int i = 0;
                try {
                    LinkedHashMap<String, Object> re = new LinkedHashMap<String, Object>();
                    for (i = 1; i <= count; i++) {
                        name = meta.getColumnLabel(i);
                        switch (meta.getColumnType(i)) {
                        case Types.TIMESTAMP: {
                            re.put(name, rs.getTimestamp(i));
                            break;
                        }
                        case Types.DATE: {// ORACLE的DATE类型包含时间,如果用默认的只有日期没有时间
                                          // from
                                          // cqyunqin
                            re.put(name, rs.getTimestamp(i));
                            break;
                        }
                        case Types.CLOB: {
                            re.put(name, Streams.read(rs.getCharacterStream(i))
                                                .toString());
                            break;
                        }
                        default:
                            re.put(name, rs.getObject(i));
                            break;
                        }
                    }
                    list.add(re);
                    return true;
                }
                catch (Exception e) {
                    if (name != null) {
                        throw new DaoException(String.format("Column Name=%s, index=%d",
                                                             name,
                                                             i),
                                               e);
                    }
                    throw new DaoException(e);
                }
            }
        };
        ing.doLoop(rs, sql.getContext());
        return ing.getList();
    }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

public class QueryEntityCallback extends EntityCallback {

    @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()));
                return true;
            }
        };
        ing.doLoop(rs, context);
        return ing.getList();
    }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

import org.nutz.dao.sql.SqlContext;

public class QueryRecordCallback implements SqlCallback {

    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();
    }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

        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;
    }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

        if (null == each)
            return null;

        // 开始执行
        final Entity<?> en = pojo.getEntity();
        ResultSetLooping ing = new ResultSetLooping() {
            protected boolean createObject(int index, ResultSet rs, SqlContext context, int rowCount) {
                Object obj = en.getObject(rs, context.getFieldMatcher());
                try {
                    each.invoke(index, obj, rowCount);
                }
                catch (ContinueLoop e) {}
                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) {
            SQLException e2 = new SQLException();
            e2.initCause(e.getCause());
            throw e2;
        }

        // 返回数量
        return ing.getIndex() + 1;

    }
View Full Code Here

Examples of org.nutz.dao.pager.ResultSetLooping

import org.nutz.dao.sql.SqlContext;

public class PojoQueryEntityCallback implements PojoCallback {

    public Object invoke(Connection conn, ResultSet rs, final Pojo pojo) 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()));
                return true;
            }
        };
        ing.doLoop(rs, pojo.getContext());
        return ing.getList();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.