/** * Build a {@link PreparedStatementCreator} based on the given SQL and named parameters. * <p>Note: Used for the {@code update} variant with generated key handling, and also * delegated from {@link #getPreparedStatementCreator(String, SqlParameterSource)}. * @param sql the SQL statement to execute * @param paramSource container of arguments to bind * @param customizer callback for setting further properties on the * {@link PreparedStatementCreatorFactory} in use), applied before the * actual {@code newPreparedStatementCreator} call * @return the corresponding {@link PreparedStatementCreator} * @since 5.0.5 * @see #getParsedSql(String) * @see PreparedStatementCreatorFactory#PreparedStatementCreatorFactory(String, List) * @see PreparedStatementCreatorFactory#newPreparedStatementCreator(Object[]) */ protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource, @Nullable Consumer<PreparedStatementCreatorFactory> customizer) { ParsedSql parsedSql = getParsedSql(sql); PreparedStatementCreatorFactory pscf = getPreparedStatementCreatorFactory(parsedSql, paramSource); if (customizer != null) { customizer.accept(pscf); } Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null); return pscf.newPreparedStatementCreator(params); }
@Override public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) { if (batchArgs.length == 0) { return new int[0]; } ParsedSql parsedSql = getParsedSql(sql); PreparedStatementCreatorFactory pscf = getPreparedStatementCreatorFactory(parsedSql, batchArgs[0]); return getJdbcOperations().batchUpdate( pscf.getSql(), new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); pscf.newPreparedStatementSetter(values).setValues(ps); } @Override public int getBatchSize() { return batchArgs.length; } }); }