Deprecate superseded Object[] signatures in JdbcOperations/JdbcTemplate

Closes gh-25272
This commit is contained in:
Juergen Hoeller
2020-06-18 17:47:27 +02:00
parent 1c75f95be0
commit 2d5f9723fa
5 changed files with 27 additions and 9 deletions

View File

@@ -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> T query(String sql, @Nullable Object[] args, ResultSetExtractor<T> 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
<T> List<T> query(String sql, @Nullable Object[] args, RowMapper<T> 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> T queryForObject(String sql, @Nullable Object[] args, RowMapper<T> 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> T queryForObject(String sql, @Nullable Object[] args, Class<T> 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
<T> List<T> queryForList(String sql, @Nullable Object[] args, Class<T> elementType) throws DataAccessException;
/**

View File

@@ -749,6 +749,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return query(sql, newArgTypePreparedStatementSetter(args, argTypes), rse);
}
@Deprecated
@Override
@Nullable
public <T> T query(String sql, @Nullable Object[] args, ResultSetExtractor<T> 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 <T> List<T> query(String sql, @Nullable Object[] args, RowMapper<T> 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> T queryForObject(String sql, @Nullable Object[] args, RowMapper<T> 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> T queryForObject(String sql, @Nullable Object[] args, Class<T> 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 <T> List<T> queryForList(String sql, @Nullable Object[] args, Class<T> elementType) throws DataAccessException {
return query(sql, args, getSingleColumnRowMapper(elementType));

View File

@@ -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<String, Object> keys = new HashMap<>(2);
keys.put(getGeneratedKeyNames()[0], key);
keyHolder.getKeyList().add(keys);

View File

@@ -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 <reified T> JdbcOperations.queryForObject(sql: String, args: Array<ou
* @since 5.0
*/
inline fun <reified T> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): T? =
queryForObject(sql, args, T::class.java) as T
queryForObject(sql, T::class.java, args) as T
/**
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant.
@@ -87,7 +87,7 @@ inline fun <reified T> JdbcOperations.queryForList(sql: String, args: Array<out
* @since 5.0
*/
inline fun <reified T> JdbcOperations.queryForList(sql: String, args: Array<out Any>): List<T> =
queryForList(sql, args, T::class.java)
queryForList(sql, T::class.java, args)
/**
* Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function

View File

@@ -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<Class<Int>>()) } returns 2
every { template.queryForObject(sql, any<Class<Int>>(), args) } returns 2
assertThat(template.queryForObject<Int>(sql, args)).isEqualTo(2)
verify { template.queryForObject(sql, args, any<Class<Int>>()) }
verify { template.queryForObject(sql, any<Class<Int>>(), 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<Class<Int>>()) } returns list
every { template.queryForList(sql, any<Class<Int>>(), args) } returns list
template.queryForList<Int>(sql, args)
verify { template.queryForList(sql, args, any<Class<Int>>()) }
verify { template.queryForList(sql, any<Class<Int>>(), args) }
}
@Test