Stop calling deprecated JdbcOperations methods
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
This commit is contained in:
committed by
Juergen Hoeller
parent
e41487492d
commit
5be83e9223
@@ -798,12 +798,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
@Deprecated
|
||||
@Override
|
||||
public <T> List<T> query(String sql, @Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper)));
|
||||
return result(query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> query(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException {
|
||||
return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper)));
|
||||
return result(query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -865,13 +865,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
@Deprecated
|
||||
@Override
|
||||
public <T> @Nullable T queryForObject(String sql,@Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
|
||||
List<T> results = query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper, 1));
|
||||
return DataAccessUtils.nullableSingleResult(results);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException {
|
||||
List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
|
||||
List<T> results = query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper, 1));
|
||||
return DataAccessUtils.nullableSingleResult(results);
|
||||
}
|
||||
|
||||
@@ -885,12 +885,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
@Deprecated
|
||||
@Override
|
||||
public <T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, Class<T> requiredType) throws DataAccessException {
|
||||
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
|
||||
return queryForObject(sql, getSingleColumnRowMapper(requiredType), args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T queryForObject(String sql, Class<T> requiredType, @Nullable Object @Nullable ... args) throws DataAccessException {
|
||||
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
|
||||
return queryForObject(sql, getSingleColumnRowMapper(requiredType), args);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -900,7 +900,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
|
||||
return result(queryForObject(sql, args, getColumnMapRowMapper()));
|
||||
return result(queryForObject(sql, getColumnMapRowMapper(), args));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -911,12 +911,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
@Deprecated
|
||||
@Override
|
||||
public <T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args, Class<T> elementType) throws DataAccessException {
|
||||
return query(sql, args, getSingleColumnRowMapper(elementType));
|
||||
return query(sql, newArgPreparedStatementSetter(args), getSingleColumnRowMapper(elementType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryForList(String sql, Class<T> elementType, @Nullable Object @Nullable ... args) throws DataAccessException {
|
||||
return query(sql, args, getSingleColumnRowMapper(elementType));
|
||||
return query(sql, newArgPreparedStatementSetter(args), getSingleColumnRowMapper(elementType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -926,7 +926,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> queryForList(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
|
||||
return query(sql, args, getColumnMapRowMapper());
|
||||
return query(sql, newArgPreparedStatementSetter(args), getColumnMapRowMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -936,7 +936,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
|
||||
@Override
|
||||
public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
|
||||
return result(query(sql, args, new SqlRowSetResultSetExtractor()));
|
||||
return result(query(sql, newArgPreparedStatementSetter(args), new SqlRowSetResultSetExtractor()));
|
||||
}
|
||||
|
||||
protected int update(final PreparedStatementCreator psc, final @Nullable PreparedStatementSetter pss)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2025 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.
|
||||
@@ -72,8 +72,8 @@ public interface PreparedStatementCallback<T> {
|
||||
* @throws SQLException if thrown by a JDBC method, to be auto-converted
|
||||
* to a DataAccessException by an SQLExceptionTranslator
|
||||
* @throws DataAccessException in case of custom exceptions
|
||||
* @see JdbcTemplate#queryForObject(String, Object[], Class)
|
||||
* @see JdbcTemplate#queryForList(String, Object[])
|
||||
* @see JdbcTemplate#queryForObject(String, Class, Object...)
|
||||
* @see JdbcTemplate#queryForList(String, Object...)
|
||||
*/
|
||||
@Nullable T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 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.
|
||||
@@ -54,10 +54,8 @@ inline fun <reified T> JdbcOperations.queryForObject(sql: String, args: Array<ou
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
// TODO Replace by the vararg variant in Spring Framework 6
|
||||
inline fun <reified T> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): T? =
|
||||
queryForObject(sql, args, T::class.java as Class<*>) as T
|
||||
queryForObject(sql, T::class.java as Class<*>, args) as T
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant.
|
||||
@@ -88,10 +86,8 @@ inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Arra
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
// TODO Replace by the vararg variant in Spring Framework 6
|
||||
inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>): List<T> =
|
||||
queryForList(sql, args, T::class.java)
|
||||
queryForList(sql, T::class.java, args)
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors
|
||||
* Copyright 2002-2025 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.
|
||||
@@ -67,12 +67,11 @@ class JdbcOperationsExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("DEPRECATION")
|
||||
fun `queryForObject with reified type parameters and args`() {
|
||||
val args = arrayOf(3, 4)
|
||||
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
|
||||
@@ -94,13 +93,12 @@ class JdbcOperationsExtensionsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("DEPRECATION")
|
||||
fun `queryForList with reified type parameters and args`() {
|
||||
val list = listOf(1, 2, 3)
|
||||
val args = arrayOf(3, 4)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user