Search in sources :

Example 6 with RowMapperResultSetExtractor

use of org.springframework.jdbc.core.RowMapperResultSetExtractor in project spring-integration by spring-projects.

the class JdbcPollingChannelAdapter method doPoll.

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) RowMapperResultSetExtractor(org.springframework.jdbc.core.RowMapperResultSetExtractor)

Aggregations

RowMapperResultSetExtractor (org.springframework.jdbc.core.RowMapperResultSetExtractor)6 ColumnMapRowMapper (org.springframework.jdbc.core.ColumnMapRowMapper)5 Map (java.util.Map)4 ResultSet (java.sql.ResultSet)2 BeanPropertyRowMapper (org.springframework.jdbc.core.BeanPropertyRowMapper)2 RowMapper (org.springframework.jdbc.core.RowMapper)2 PreparedStatement (java.sql.PreparedStatement)1 SQLDataException (java.sql.SQLDataException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1