@SuppressWarnings("rawtypes") private ShardOperationProcessor<List> getNonAggregationProcessor(final RowMapper rowMapper) { final List<QueryCallable<List>> callableList = new ArrayList<ShardJdbcTemplate.QueryCallable<List>>(); ShardOperationProcessor<List> processor = new ShardOperationProcessor<List>() { @SuppressWarnings("unchecked") @Override public void addOperation(Shard shard, String sql, Object[] args) { ResultSetExtractor extractor = new RowMapperResultSetExtractor(rowMapper); QueryCallable<List> callable = new QueryCallable<List>(shard, sql, args, extractor); callableList.add(callable); } @Override public List processOperations() { List<List> rawResultList = ShardJdbcTemplate.this.executeQuery(callableList); return AggregationUtil.aggregateObjectList(rawResultList); } }; return processor; }
public static <T> List<T> selectBeans(final Connection con, final String sql, int fetchCount, int limitedSize, RowMapper<T> mapper) throws Exception { List<T> resultList = Collections.emptyList(); try { noticeQuery(sql); PreparedStatement prepareStatement = null; ResultSet executeQuery = null; /* 쿼리 타임아웃 시간 설정 SEC */ // int queryTimeout = getQueryTimeout(); prepareStatement = con.prepareStatement(sql); LOGGER.debug(sql); // postgre-sql can't // prepareStatement.setQueryTimeout(queryTimeout); if (!(limitedSize <= 0)) { prepareStatement.setMaxRows(limitedSize); } if (fetchCount > 0) { prepareStatement.setFetchSize(fetchCount); } executeQuery = prepareStatement.executeQuery(); RowMapperResultSetExtractor<T> rowMapperResultSetExtractor = new RowMapperResultSetExtractor<T>(mapper); resultList = rowMapperResultSetExtractor.extractData(executeQuery); } catch (Throwable e) { throw e; } finally { close(con); } return resultList; }
@SneakyThrows public Stream<PrimaryKey> ofTable(final Table table) { log.info("About to fetch column metadata for " + table.name); try (Connection connection = dataSource.getConnection(); ResultSet resultSet = connection.getMetaData().getPrimaryKeys(null, null, table.name)) { List<PrimaryKey> primaryKeys = new RowMapperResultSetExtractor<>(toPrimaryKey()).extractData(resultSet); return primaryKeys.stream(); } }
private Stream<Option<ColumnAndIndex>> columnAndIndexOptions(Schema schema, Table table) throws SQLException { log.info("About to fetch column and index metadata for " + table.name); try (Connection connection = dataSource.getConnection(); ResultSet resultSet = connection.getMetaData().getIndexInfo(null, schema.name, table.name, true, true)) { return iterableStream(new RowMapperResultSetExtractor<>(toColumnAndIndexOption()).extractData(resultSet)); } }
/** * @param ps * @throws SQLException */ private void extractKeys(PreparedStatement ps) throws SQLException { ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { RowMapperResultSetExtractor<Map<String, Object>> rse = new RowMapperResultSetExtractor<Map<String, Object>>( new InsertKeyColumnRowMapper(TypeUtils.getRawType(idProperty.type(), null)), 1); keyHolder.getKeyList().addAll(rse.extractData(keys)); } finally { JdbcUtils.closeResultSet(keys); } } }
@Transactional @Override public <T> PagedList<T> search(QueryConfigurer commonClause, QueryConfigurer orderByClause, long pageNo, long pageSz, Predicate<Long> cancelPredicate, final RowMapper<T> rowMapper, final Expression<?>... expressions) { Function<SQLQuery, List<T>> searchFunction = new Function<SQLQuery, List<T>>() { @Override public List<T> apply(SQLQuery query) { ResultSetExtractor<List<T>> extractor = new RowMapperResultSetExtractor<>(rowMapper); return getResults("search", query, extractor, expressions); } }; return searchMain(commonClause, orderByClause, pageNo, pageSz, cancelPredicate, searchFunction); }
private <T> T queryForObject(String sql, PreparedStatementSetter setter, RowMapper<T> rowMapper) throws DataAccessException { return DataAccessUtils.requiredSingleResult(jdbc().query(sql, setter, new RowMapperResultSetExtractor<T>(rowMapper, 1))); }
private <T> List<T> queryForList(String sql, PreparedStatementSetter setter, ParameterizedRowMapper<T> rm) { return jdbc().query(sql, setter, new RowMapperResultSetExtractor<T>(rm)); }