improved integration; added delegation to NamedParameterJdbcTemplate for batchUpdate from SimpleJdbcTemplate; added call to proteced getParsedSql method; fixed bugs (SPR-3322, SPR-5162)
This commit is contained in:
@@ -8,18 +8,18 @@ import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||
|
||||
/**
|
||||
* Generic utility methods for working with JDBC batch statements. Mainly for internal use
|
||||
* Generic utility methods for working with JDBC batch statements using named parameters. Mainly for internal use
|
||||
* within the framework.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
public class NamedParameterBatchUpdateUtils extends BatchUpdateUtils {
|
||||
|
||||
public static int[] executeBatchUpdateWithNamedParameters(String sql, final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
|
||||
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql,
|
||||
final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
|
||||
if (batchArgs.length <= 0) {
|
||||
return new int[] {0};
|
||||
}
|
||||
final ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
|
||||
return jdbcOperations.batchUpdate(
|
||||
sqlToUse,
|
||||
|
||||
@@ -272,7 +272,8 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
||||
}
|
||||
|
||||
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
|
||||
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(sql, batchArgs, getJdbcOperations());
|
||||
ParsedSql parsedSql = this.getParsedSql(sql);
|
||||
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(parsedSql, batchArgs, getJdbcOperations());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,11 +25,9 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.BatchUpdateUtils;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -235,29 +233,23 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
|
||||
}
|
||||
|
||||
public int[] batchUpdate(String sql, List<Object[]> batchArgs) {
|
||||
return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, new int[0], getJdbcOperations());
|
||||
return batchUpdate(sql, batchArgs, new int[0]);
|
||||
}
|
||||
|
||||
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) {
|
||||
return batchUpdate(sql, batchArgs, argTypes);
|
||||
return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, argTypes, getJdbcOperations());
|
||||
}
|
||||
|
||||
public int[] batchUpdate(String sql, Map<String, Object>[] batchValues) {
|
||||
SqlParameterSource[] batchArgs = new SqlParameterSource[batchValues.length];
|
||||
int i = 0;
|
||||
for (Map<String, Object> values : batchValues) {
|
||||
batchArgs[i] = new MapSqlParameterSource(values);
|
||||
i++;
|
||||
}
|
||||
return batchUpdate(sql, batchArgs);
|
||||
return getNamedParameterJdbcOperations().batchUpdate(sql, batchValues);
|
||||
}
|
||||
|
||||
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
|
||||
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(sql, batchArgs, getJdbcOperations());
|
||||
return getNamedParameterJdbcOperations().batchUpdate(sql, batchArgs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/*
|
||||
* Considers an Object array passed into a varargs parameter as
|
||||
* collection of arguments rather than as single argument.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user