protected List<?> doPoll(SqlParameterSource sqlQueryParameterSource) {
    final RowMapper<?> rowMapper =
        this.rowMapper == null ? new ColumnMapRowMapper() : this.rowMapper;
    ResultSetExtractor<List<Object>> resultSetExtractor;

    if (this.maxRowsPerPoll > 0) {
      resultSetExtractor =
          rs -> {
            List<Object> results =
                new ArrayList<Object>(JdbcPollingChannelAdapter.this.maxRowsPerPoll);
            int rowNum = 0;
            while (rs.next() && rowNum < JdbcPollingChannelAdapter.this.maxRowsPerPoll) {
              results.add(rowMapper.mapRow(rs, rowNum++));
            }
            return results;
          };
    } else {
      @SuppressWarnings("unchecked")
      ResultSetExtractor<List<Object>> temp =
          new RowMapperResultSetExtractor<Object>((RowMapper<Object>) rowMapper);
      resultSetExtractor = temp;
    }

    if (sqlQueryParameterSource != null) {
      return this.jdbcOperations.query(
          this.selectQuery, sqlQueryParameterSource, resultSetExtractor);
    } else {
      return this.jdbcOperations.getJdbcOperations().query(this.selectQuery, resultSetExtractor);
    }
  }
Пример #2
0
  @Override
  public List<TableRowDto<T>> extractData(ResultSet resultSet)
      throws SQLException, DataAccessException {
    List<TableRowDto<T>> listTableRow = new ArrayList<TableRowDto<T>>();

    while (resultSet.next()) {
      TableRowDto<T> tableRow = new TableRowDto<T>();
      tableRow.setPage(resultSet.getInt("PAGE"));
      tableRow.setPageLine(resultSet.getInt("PAGELINE"));
      tableRow.setTableLine(resultSet.getInt("TABLELINE"));

      T model = rowMapper.mapRow(resultSet, resultSet.getRow());
      tableRow.setModel(model);
      try {
        for (String pk : this.pkColums) {
          tableRow.addPrimaryKey(pk, BeanUtils.getProperty(model, pk));
        }
        listTableRow.add(tableRow);
      } catch (IllegalAccessException e) {
        throw new SQLException(e);
      } catch (InvocationTargetException e) {
        throw new SQLException(e);
      } catch (NoSuchMethodException e) {
        throw new SQLException(e);
      }
    }
    return listTableRow;
  }
Пример #3
0
 public <T> List<T> getListBySQL(String sql, Object[] values, RowMapper<T> rm) {
   this.log("query sql [ " + sql + " ]");
   PreparedStatement ps = null;
   ResultSet rs = null;
   Connection con = this.getCurrentConnection();
   try {
     ps = con.prepareStatement(sql);
     if (values != null) {
       for (int i = 0; i < values.length; i++) {
         ps.setObject(i + 1, values[i]);
       }
     }
     rs = ps.executeQuery();
     int rowNum = 0;
     List<T> list = new ArrayList<T>();
     while (rs.next()) {
       list.add(rm.mapRow(rs, rowNum++));
     }
     return list;
   } catch (SQLException e) {
     JdbcUtils.closeStatement(ps);
     ps = null;
     DataSourceUtils.releaseConnection(con, getDataSource());
     con = null;
     e.printStackTrace();
     throw getExceptionTranslator().translate("StatementCallback", sql, e);
   } finally {
     JdbcUtils.closeResultSet(rs);
     JdbcUtils.closeStatement(ps);
     DataSourceUtils.releaseConnection(con, getDataSource());
   }
 }
Пример #4
0
 public App mapRow(ResultSet rs, int rowNum) throws SQLException {
   return new App(
       appSummaryMapper.mapRow(rs, rowNum),
       encryptor.decrypt(rs.getString("apiKey")),
       encryptor.decrypt(rs.getString("secret")),
       rs.getString("callbackUrl"));
 }
Пример #5
0
  /**
   * 获取下一条记录,并转化为相应实体类
   *
   * @return
   */
  private E transformNext() {
    try {
      if (rs.next() == false) return null;

      if (rowMapper == null) rowMapper = new EntityRowMapper<E>(entityCls);

      return rowMapper.mapRow(rs, ++index);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  @Override
  protected Binding prefetch() throws Exception {
    if (!rs.next()) {
      return super.finish();
    }

    long rowId = nextRowId++;

    Binding result = rowMapper.mapRow(rs, (int) rowId);

    return result;
  }
Пример #7
0
 public Pair<Group, Resource> mapRow(ResultSet rs, int i) throws SQLException {
   Pair<Group, Resource> pair = new Pair<Group, Resource>();
   pair.put(GROUP_MAPPER.mapRow(rs, i), ResourcesManagerImpl.RESOURCE_MAPPER.mapRow(rs, i));
   return pair;
 }