Polish "Allow batch update to take a KeyHolder"
See gh-28132
This commit is contained in:
parent
78db5dd516
commit
c21a9b94c5
|
|
@ -1014,9 +1014,11 @@ public interface JdbcOperations {
|
|||
* (may also contain special JDBC-defined negative values for affected rows such as
|
||||
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
|
||||
* @throws DataAccessException if there is any problem issuing the update
|
||||
* @since 6.1
|
||||
* @see org.springframework.jdbc.support.GeneratedKeyHolder
|
||||
*/
|
||||
int[] batchUpdate(PreparedStatementCreator psc, BatchPreparedStatementSetter pss, KeyHolder generatedKeyHolder) throws DataAccessException;
|
||||
int[] batchUpdate(PreparedStatementCreator psc, BatchPreparedStatementSetter pss,
|
||||
KeyHolder generatedKeyHolder) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
|
||||
|
|
|
|||
|
|
@ -1021,7 +1021,9 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int[] batchUpdate(final PreparedStatementCreator psc, final BatchPreparedStatementSetter pss, final KeyHolder generatedKeyHolder) throws DataAccessException {
|
||||
public int[] batchUpdate(final PreparedStatementCreator psc, final BatchPreparedStatementSetter pss,
|
||||
final KeyHolder generatedKeyHolder) throws DataAccessException {
|
||||
|
||||
int[] result = execute(psc, getPreparedStatementCallback(pss, generatedKeyHolder));
|
||||
|
||||
Assert.state(result != null, "No result array");
|
||||
|
|
|
|||
|
|
@ -556,8 +556,8 @@ public interface NamedParameterJdbcOperations {
|
|||
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs);
|
||||
|
||||
/**
|
||||
* Execute a batch using the supplied SQL statement with the batch of supplied arguments,
|
||||
* returning generated keys.
|
||||
* Execute a batch using the supplied SQL statement with the batch of supplied
|
||||
* arguments, returning generated keys.
|
||||
* @param sql the SQL statement to execute
|
||||
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of
|
||||
* arguments for the query
|
||||
|
|
@ -566,6 +566,7 @@ public interface NamedParameterJdbcOperations {
|
|||
* (may also contain special JDBC-defined negative values for affected rows such as
|
||||
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
|
||||
* @throws DataAccessException if there is any problem issuing the update
|
||||
* @since 6.1
|
||||
* @see org.springframework.jdbc.support.GeneratedKeyHolder
|
||||
*/
|
||||
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder);
|
||||
|
|
@ -582,7 +583,9 @@ public interface NamedParameterJdbcOperations {
|
|||
* (may also contain special JDBC-defined negative values for affected rows such as
|
||||
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
|
||||
* @throws DataAccessException if there is any problem issuing the update
|
||||
* @since 6.1
|
||||
* @see org.springframework.jdbc.support.GeneratedKeyHolder
|
||||
*/
|
||||
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder, String[] keyColumnNames);
|
||||
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder,
|
||||
String[] keyColumnNames);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -400,7 +400,9 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
|||
}
|
||||
|
||||
@Override
|
||||
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder, String[] keyColumnNames) {
|
||||
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder,
|
||||
@Nullable String[] keyColumnNames) {
|
||||
|
||||
if (batchArgs.length == 0) {
|
||||
return new int[0];
|
||||
}
|
||||
|
|
@ -416,20 +418,18 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
|||
}
|
||||
Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
|
||||
PreparedStatementCreator psc = pscf.newPreparedStatementCreator(params);
|
||||
return getJdbcOperations().batchUpdate(
|
||||
psc,
|
||||
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;
|
||||
}
|
||||
},
|
||||
generatedKeyHolder);
|
||||
return getJdbcOperations().batchUpdate(psc, 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;
|
||||
}
|
||||
}, generatedKeyHolder);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue