diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java index be172510202..601c83a77cd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java @@ -1013,7 +1013,7 @@ public interface JdbcOperations { * {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED}) * @throws DataAccessException if there is any problem issuing the update */ - int[] batchUpdate(String sql, List batchArgs) throws DataAccessException; + int[] batchUpdate(String sql, List batchArgs) throws DataAccessException; /** * Execute a batch using the supplied SQL statement with the batch of supplied arguments. @@ -1026,7 +1026,7 @@ public interface JdbcOperations { * {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED}) * @throws DataAccessException if there is any problem issuing the update */ - int[] batchUpdate(String sql, List batchArgs, int[] argTypes) throws DataAccessException; + int[] batchUpdate(String sql, List batchArgs, int[] argTypes) throws DataAccessException; /** * Execute multiple batches using the supplied SQL statement with the collect of supplied diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 33b94792ddc..0eec243d061 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -1046,12 +1046,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int[] batchUpdate(String sql, List<@Nullable Object[]> batchArgs) throws DataAccessException { + public int[] batchUpdate(String sql, List batchArgs) throws DataAccessException { return batchUpdate(sql, batchArgs, new int[0]); } @Override - public int[] batchUpdate(String sql, List<@Nullable Object[]> batchArgs, int[] argTypes) throws DataAccessException { + public int[] batchUpdate(String sql, List batchArgs, int[] argTypes) throws DataAccessException { if (batchArgs.isEmpty()) { return new int[0]; } diff --git a/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt b/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt index 91c2c55092b..18cef980ef9 100644 --- a/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt +++ b/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt @@ -223,4 +223,42 @@ class JdbcOperationsExtensionsTests { verify { template.query(sql, ofType>(), 3) } } + @Test // gh-37012 + fun `batchUpdate with non-null batchArgs`() { + val batchArgs: List> = listOf(arrayOf(1, "a"), arrayOf(2, "b")) + val result = intArrayOf(1, 1) + every { template.batchUpdate(sql, batchArgs) } returns result + assertThat(template.batchUpdate(sql, batchArgs)).isEqualTo(result) + verify { template.batchUpdate(sql, batchArgs) } + } + + @Test // gh-37012 + fun `batchUpdate with nullable batchArgs`() { + val batchArgs: List> = listOf(arrayOf(1, null), arrayOf(null, "b")) + val result = intArrayOf(1, 1) + every { template.batchUpdate(sql, batchArgs) } returns result + assertThat(template.batchUpdate(sql, batchArgs)).isEqualTo(result) + verify { template.batchUpdate(sql, batchArgs) } + } + + @Test // gh-37012 + fun `batchUpdate with non-null batchArgs and argTypes`() { + val batchArgs: List> = listOf(arrayOf(1, "a"), arrayOf(2, "b")) + val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber, JDBCType.VARCHAR.vendorTypeNumber) + val result = intArrayOf(1, 1) + every { template.batchUpdate(sql, batchArgs, argTypes) } returns result + assertThat(template.batchUpdate(sql, batchArgs, argTypes)).isEqualTo(result) + verify { template.batchUpdate(sql, batchArgs, argTypes) } + } + + @Test // gh-37012 + fun `batchUpdate with nullable batchArgs and argTypes`() { + val batchArgs: List> = listOf(arrayOf(1, null), arrayOf(null, "b")) + val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber, JDBCType.VARCHAR.vendorTypeNumber) + val result = intArrayOf(1, 1) + every { template.batchUpdate(sql, batchArgs, argTypes) } returns result + assertThat(template.batchUpdate(sql, batchArgs, argTypes)).isEqualTo(result) + verify { template.batchUpdate(sql, batchArgs, argTypes) } + } + }