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 16151ded691..c285ddcb978 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 @@ -369,7 +369,9 @@ public interface JdbcOperations { * @param rse a callback that will extract results * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if the query fails + * @deprecated as of 5.3, in favor of {@link #query(String, ResultSetExtractor, Object...)} */ + @Deprecated @Nullable T query(String sql, @Nullable Object[] args, ResultSetExtractor rse) throws DataAccessException; @@ -440,7 +442,9 @@ public interface JdbcOperations { * only the argument value but also the SQL type and optionally the scale * @param rch a callback that will extract results, one row at a time * @throws DataAccessException if the query fails + * @deprecated as of 5.3, in favor of {@link #query(String, RowCallbackHandler, Object...)} */ + @Deprecated void query(String sql, @Nullable Object[] args, RowCallbackHandler rch) throws DataAccessException; /** @@ -514,7 +518,9 @@ public interface JdbcOperations { * @param rowMapper a callback that will map one object per row * @return the result List, containing mapped objects * @throws DataAccessException if the query fails + * @deprecated as of 5.3, in favor of {@link #query(String, RowMapper, Object...)} */ + @Deprecated List query(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException; /** @@ -620,7 +626,9 @@ public interface JdbcOperations { * @throws IncorrectResultSizeDataAccessException if the query does not * return exactly one row * @throws DataAccessException if the query fails + * @deprecated as of 5.3, in favor of {@link #queryForObject(String, RowMapper, Object...)} */ + @Deprecated @Nullable T queryForObject(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException; @@ -681,7 +689,9 @@ public interface JdbcOperations { * exactly one row, or does not return exactly one column in that row * @throws DataAccessException if the query fails * @see #queryForObject(String, Class) + * @deprecated as of 5.3, in favor of {@link #queryForObject(String, Class, Object...)} */ + @Deprecated @Nullable T queryForObject(String sql, @Nullable Object[] args, Class requiredType) throws DataAccessException; @@ -783,7 +793,9 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see #queryForList(String, Class) * @see SingleColumnRowMapper + * @deprecated as of 5.3, in favor of {@link #queryForList(String, Class, Object...)} */ + @Deprecated List queryForList(String sql, @Nullable Object[] args, Class elementType) throws DataAccessException; /** 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 c7a83d1a12a..53b3b9eff54 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 @@ -749,6 +749,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { return query(sql, newArgTypePreparedStatementSetter(args, argTypes), rse); } + @Deprecated @Override @Nullable public T query(String sql, @Nullable Object[] args, ResultSetExtractor rse) throws DataAccessException { @@ -776,6 +777,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { query(sql, newArgTypePreparedStatementSetter(args, argTypes), rch); } + @Deprecated @Override public void query(String sql, @Nullable Object[] args, RowCallbackHandler rch) throws DataAccessException { query(sql, newArgPreparedStatementSetter(args), rch); @@ -801,6 +803,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { return result(query(sql, args, argTypes, new RowMapperResultSetExtractor<>(rowMapper))); } + @Deprecated @Override public List query(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException { return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper))); @@ -868,6 +871,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { return DataAccessUtils.nullableSingleResult(results); } + @Deprecated @Override @Nullable public T queryForObject(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException { @@ -890,6 +894,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { return queryForObject(sql, args, argTypes, getSingleColumnRowMapper(requiredType)); } + @Deprecated @Override public T queryForObject(String sql, @Nullable Object[] args, Class requiredType) throws DataAccessException { return queryForObject(sql, args, getSingleColumnRowMapper(requiredType)); @@ -915,6 +920,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { return query(sql, args, argTypes, getSingleColumnRowMapper(elementType)); } + @Deprecated @Override public List queryForList(String sql, @Nullable Object[] args, Class elementType) throws DataAccessException { return query(sql, args, getSingleColumnRowMapper(elementType)); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java index 7ee9817a8cf..eed67c1d8a5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java @@ -465,7 +465,7 @@ public abstract class AbstractJdbcInsert { if (keyQuery.toUpperCase().startsWith("RETURNING")) { Long key = getJdbcTemplate().queryForObject( - getInsertString() + " " + keyQuery, values.toArray(), Long.class); + getInsertString() + " " + keyQuery, Long.class, values.toArray()); Map keys = new HashMap<>(2); keys.put(getGeneratedKeyNames()[0], key); keyHolder.getKeyList().add(keys); diff --git a/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt b/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt index 531b6ccdd30..ff97b511d30 100644 --- a/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt +++ b/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors + * Copyright 2002-2020 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ inline fun JdbcOperations.queryForObject(sql: String, args: Array JdbcOperations.queryForObject(sql: String, args: Array): T? = - queryForObject(sql, args, T::class.java) as T + queryForObject(sql, T::class.java, args) as T /** * Extension for [JdbcOperations.queryForList] providing a `queryForList("...")` variant. @@ -87,7 +87,7 @@ inline fun JdbcOperations.queryForList(sql: String, args: Array JdbcOperations.queryForList(sql: String, args: Array): List = - queryForList(sql, args, T::class.java) + queryForList(sql, T::class.java, args) /** * Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function 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 eb2dfe36714..c134dc23c28 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors + * Copyright 2002-2020 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,9 +69,9 @@ class JdbcOperationsExtensionsTests { @Test fun `queryForObject with reified type parameters and args`() { val args = arrayOf(3) - every { template.queryForObject(sql, args, any>()) } returns 2 + every { template.queryForObject(sql, any>(), args) } returns 2 assertThat(template.queryForObject(sql, args)).isEqualTo(2) - verify { template.queryForObject(sql, args, any>()) } + verify { template.queryForObject(sql, any>(), args) } } @Test @@ -96,9 +96,9 @@ class JdbcOperationsExtensionsTests { fun `queryForList with reified type parameters and args`() { val list = listOf(1, 2, 3) val args = arrayOf(3) - every { template.queryForList(sql, args, any>()) } returns list + every { template.queryForList(sql, any>(), args) } returns list template.queryForList(sql, args) - verify { template.queryForList(sql, args, any>()) } + verify { template.queryForList(sql, any>(), args) } } @Test