|
|
|
|
@ -526,10 +526,11 @@ public class NamedParameterJdbcTemplateTests {
@@ -526,10 +526,11 @@ public class NamedParameterJdbcTemplateTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testBatchUpdateWithSqlParameterSourcePlusTypeInfo() throws Exception { |
|
|
|
|
SqlParameterSource[] ids = new SqlParameterSource[2]; |
|
|
|
|
ids[0] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC); |
|
|
|
|
ids[1] = new MapSqlParameterSource().addValue("id", 200, Types.NUMERIC); |
|
|
|
|
final int[] rowsAffected = new int[] {1, 2}; |
|
|
|
|
SqlParameterSource[] ids = new SqlParameterSource[3]; |
|
|
|
|
ids[0] = new MapSqlParameterSource().addValue("id", null, Types.NULL); |
|
|
|
|
ids[1] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC); |
|
|
|
|
ids[2] = new MapSqlParameterSource().addValue("id", 200, Types.NUMERIC); |
|
|
|
|
final int[] rowsAffected = new int[] {1, 2, 3}; |
|
|
|
|
|
|
|
|
|
given(preparedStatement.executeBatch()).willReturn(rowsAffected); |
|
|
|
|
given(connection.getMetaData()).willReturn(databaseMetaData); |
|
|
|
|
@ -537,13 +538,15 @@ public class NamedParameterJdbcTemplateTests {
@@ -537,13 +538,15 @@ public class NamedParameterJdbcTemplateTests {
|
|
|
|
|
|
|
|
|
|
int[] actualRowsAffected = namedParameterTemplate.batchUpdate( |
|
|
|
|
"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids); |
|
|
|
|
assertThat(actualRowsAffected.length == 2).as("executed 2 updates").isTrue(); |
|
|
|
|
assertThat(actualRowsAffected.length == 3).as("executed 3 updates").isTrue(); |
|
|
|
|
assertThat(actualRowsAffected[0]).isEqualTo(rowsAffected[0]); |
|
|
|
|
assertThat(actualRowsAffected[1]).isEqualTo(rowsAffected[1]); |
|
|
|
|
assertThat(actualRowsAffected[2]).isEqualTo(rowsAffected[2]); |
|
|
|
|
verify(connection).prepareStatement("UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"); |
|
|
|
|
verify(preparedStatement).setNull(1, Types.NULL); |
|
|
|
|
verify(preparedStatement).setObject(1, 100, Types.NUMERIC); |
|
|
|
|
verify(preparedStatement).setObject(1, 200, Types.NUMERIC); |
|
|
|
|
verify(preparedStatement, times(2)).addBatch(); |
|
|
|
|
verify(preparedStatement, times(3)).addBatch(); |
|
|
|
|
verify(preparedStatement, atLeastOnce()).close(); |
|
|
|
|
verify(connection, atLeastOnce()).close(); |
|
|
|
|
} |
|
|
|
|
|