Skip to content

Commit 5be83e9

Browse files
quaffjhoeller
authored andcommitted
Stop calling deprecated JdbcOperations methods
Signed-off-by: Yanming Zhou <[email protected]>
1 parent e414874 commit 5be83e9

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,12 @@ public <T> List<T> query(String sql, @Nullable Object @Nullable [] args, int[] a
798798
@Deprecated
799799
@Override
800800
public <T> List<T> query(String sql, @Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException {
801-
return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper)));
801+
return result(query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper)));
802802
}
803803

804804
@Override
805805
public <T> List<T> query(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException {
806-
return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper)));
806+
return result(query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper)));
807807
}
808808

809809
/**
@@ -865,13 +865,13 @@ public <T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullabl
865865
@Deprecated
866866
@Override
867867
public <T> @Nullable T queryForObject(String sql,@Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException {
868-
List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
868+
List<T> results = query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper, 1));
869869
return DataAccessUtils.nullableSingleResult(results);
870870
}
871871

872872
@Override
873873
public <T> @Nullable T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException {
874-
List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
874+
List<T> results = query(sql, newArgPreparedStatementSetter(args), new RowMapperResultSetExtractor<>(rowMapper, 1));
875875
return DataAccessUtils.nullableSingleResult(results);
876876
}
877877

@@ -885,12 +885,12 @@ public <T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullabl
885885
@Deprecated
886886
@Override
887887
public <T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, Class<T> requiredType) throws DataAccessException {
888-
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
888+
return queryForObject(sql, getSingleColumnRowMapper(requiredType), args);
889889
}
890890

891891
@Override
892892
public <T> @Nullable T queryForObject(String sql, Class<T> requiredType, @Nullable Object @Nullable ... args) throws DataAccessException {
893-
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
893+
return queryForObject(sql, getSingleColumnRowMapper(requiredType), args);
894894
}
895895

896896
@Override
@@ -900,7 +900,7 @@ public Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable []
900900

901901
@Override
902902
public Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
903-
return result(queryForObject(sql, args, getColumnMapRowMapper()));
903+
return result(queryForObject(sql, getColumnMapRowMapper(), args));
904904
}
905905

906906
@Override
@@ -911,12 +911,12 @@ public <T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args,
911911
@Deprecated
912912
@Override
913913
public <T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args, Class<T> elementType) throws DataAccessException {
914-
return query(sql, args, getSingleColumnRowMapper(elementType));
914+
return query(sql, newArgPreparedStatementSetter(args), getSingleColumnRowMapper(elementType));
915915
}
916916

917917
@Override
918918
public <T> List<T> queryForList(String sql, Class<T> elementType, @Nullable Object @Nullable ... args) throws DataAccessException {
919-
return query(sql, args, getSingleColumnRowMapper(elementType));
919+
return query(sql, newArgPreparedStatementSetter(args), getSingleColumnRowMapper(elementType));
920920
}
921921

922922
@Override
@@ -926,7 +926,7 @@ public List<Map<String, Object>> queryForList(String sql, @Nullable Object @Null
926926

927927
@Override
928928
public List<Map<String, Object>> queryForList(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
929-
return query(sql, args, getColumnMapRowMapper());
929+
return query(sql, newArgPreparedStatementSetter(args), getColumnMapRowMapper());
930930
}
931931

932932
@Override
@@ -936,7 +936,7 @@ public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable [] args,
936936

937937
@Override
938938
public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
939-
return result(query(sql, args, new SqlRowSetResultSetExtractor()));
939+
return result(query(sql, newArgPreparedStatementSetter(args), new SqlRowSetResultSetExtractor()));
940940
}
941941

942942
protected int update(final PreparedStatementCreator psc, final @Nullable PreparedStatementSetter pss)

spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,8 +72,8 @@ public interface PreparedStatementCallback<T> {
7272
* @throws SQLException if thrown by a JDBC method, to be auto-converted
7373
* to a DataAccessException by an SQLExceptionTranslator
7474
* @throws DataAccessException in case of custom exceptions
75-
* @see JdbcTemplate#queryForObject(String, Object[], Class)
76-
* @see JdbcTemplate#queryForList(String, Object[])
75+
* @see JdbcTemplate#queryForObject(String, Class, Object...)
76+
* @see JdbcTemplate#queryForList(String, Object...)
7777
*/
7878
@Nullable T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException;
7979

spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* 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
5454
* @author Mario Arias
5555
* @since 5.0
5656
*/
57-
@Suppress("DEPRECATION")
58-
// TODO Replace by the vararg variant in Spring Framework 6
5957
inline fun <reified T> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): T? =
60-
queryForObject(sql, args, T::class.java as Class<*>) as T
58+
queryForObject(sql, T::class.java as Class<*>, args) as T
6159

6260
/**
6361
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant.
@@ -88,10 +86,8 @@ inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Arra
8886
* @author Mario Arias
8987
* @since 5.0
9088
*/
91-
@Suppress("DEPRECATION")
92-
// TODO Replace by the vararg variant in Spring Framework 6
9389
inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>): List<T> =
94-
queryForList(sql, args, T::class.java)
90+
queryForList(sql, T::class.java, args)
9591

9692

9793
/**

spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors
2+
* Copyright 2002-2025 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,12 +67,11 @@ class JdbcOperationsExtensionsTests {
6767
}
6868

6969
@Test
70-
@Suppress("DEPRECATION")
7170
fun `queryForObject with reified type parameters and args`() {
7271
val args = arrayOf(3, 4)
73-
every { template.queryForObject(sql, args, any<Class<Int>>()) } returns 2
72+
every { template.queryForObject(sql, any<Class<Int>>(), args) } returns 2
7473
assertThat(template.queryForObject<Int>(sql, args)).isEqualTo(2)
75-
verify { template.queryForObject(sql, args, any<Class<Int>>()) }
74+
verify { template.queryForObject(sql, any<Class<Int>>(), args) }
7675
}
7776

7877
@Test
@@ -94,13 +93,12 @@ class JdbcOperationsExtensionsTests {
9493
}
9594

9695
@Test
97-
@Suppress("DEPRECATION")
9896
fun `queryForList with reified type parameters and args`() {
9997
val list = listOf(1, 2, 3)
10098
val args = arrayOf(3, 4)
101-
every { template.queryForList(sql, args, any<Class<Int>>()) } returns list
99+
every { template.queryForList(sql, any<Class<Int>>(), args) } returns list
102100
template.queryForList<Int>(sql, args)
103-
verify { template.queryForList(sql, args, any<Class<Int>>()) }
101+
verify { template.queryForList(sql, any<Class<Int>>(), args) }
104102
}
105103

106104
@Test

0 commit comments

Comments
 (0)