/** * Build a {@link PreparedStatementCreator} based on the given SQL and named parameters. * <p>Note: Directly called from all {@code query} variants. Delegates to the common * {@link #getPreparedStatementCreator(String, SqlParameterSource, Consumer)} method. * @param sql the SQL statement to execute * @param paramSource container of arguments to bind * @return the corresponding {@link PreparedStatementCreator} * @see #getPreparedStatementCreator(String, SqlParameterSource, Consumer) */ protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource) { return getPreparedStatementCreator(sql, paramSource, null); }
@Override @Nullable public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action) throws DataAccessException { return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action); }
@Override @Nullable public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse) throws DataAccessException { return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse); }
@Override public <T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException { return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper); }
@Override public void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) throws DataAccessException { getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rch); }
@Override public int update(String sql, SqlParameterSource paramSource) throws DataAccessException { return getJdbcOperations().update(getPreparedStatementCreator(sql, paramSource)); }
@Override @Nullable public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException { List<T> results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper); return DataAccessUtils.nullableSingleResult(results); }
@Override public SqlRowSet queryForRowSet(String sql, SqlParameterSource paramSource) throws DataAccessException { SqlRowSet result = getJdbcOperations().query( getPreparedStatementCreator(sql, paramSource), new SqlRowSetResultSetExtractor()); Assert.state(result != null, "No result"); return result; }
@Override public int update( String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames) throws DataAccessException { PreparedStatementCreator psc = getPreparedStatementCreator(sql, paramSource, pscf -> { if (keyColumnNames != null) { pscf.setGeneratedKeysColumnNames(keyColumnNames); } else { pscf.setReturnGeneratedKeys(true); } }); return getJdbcOperations().update(psc, generatedKeyHolder); }
@Override protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource, Consumer<PreparedStatementCreatorFactory> customizer) { PreparedStatementCreator preparedStatementCreator = super.getPreparedStatementCreator(sql, paramSource, customizer); return con -> { PreparedStatement preparedStatement = preparedStatementCreator.createPreparedStatement(con); preparedStatement.setMaxRows(JdbcPollingChannelAdapter.this.maxRows); return preparedStatement; }; } };
@Override @Nullable public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action) throws DataAccessException { return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action); }
@Override @Nullable public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse) throws DataAccessException { return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse); }
public void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) throws DataAccessException { getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rch); }
@Override protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource, Consumer<PreparedStatementCreatorFactory> customizer) { PreparedStatementCreator preparedStatementCreator = super.getPreparedStatementCreator(sql, paramSource, customizer); return con -> { PreparedStatement preparedStatement = preparedStatementCreator.createPreparedStatement(con); preparedStatement.setMaxRows(JdbcPollingChannelAdapter.this.maxRows); return preparedStatement; }; } };
@Override public void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) throws DataAccessException { getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rch); }
public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action) throws DataAccessException { return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action); }
public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse) throws DataAccessException { return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse); }
public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException { List<T> results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper); return DataAccessUtils.requiredSingleResult(results); }
@Override public <T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException { return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper); }
public SqlRowSet queryForRowSet(String sql, SqlParameterSource paramSource) throws DataAccessException { return getJdbcOperations().query( getPreparedStatementCreator(sql, paramSource), new SqlRowSetResultSetExtractor()); }