Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,12 @@ public <T> List<T> query(String sql, @Nullable Object @Nullable [] args, int[] a
@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)));
}

/**
Expand Down Expand Up @@ -865,13 +865,13 @@ public <T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullabl
@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);
}

Expand All @@ -885,12 +885,12 @@ public <T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullabl
@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
Expand All @@ -900,7 +900,7 @@ public Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable []

@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
Expand All @@ -911,12 +911,12 @@ public <T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args,
@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
Expand All @@ -926,7 +926,7 @@ public List<Map<String, Object>> queryForList(String sql, @Nullable Object @Null

@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
Expand All @@ -936,7 +936,7 @@ public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable [] args,

@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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down