Fix JdbcOperationsExtensions
This commit reverts some changes done in 2d5f9723fa
in order to fix JdbcOperations.queryForObject and
JdbcOperations.queryForList.
It is not possible to provide a vararg variant in Kotlin
for now due to a signature clash, but that will probably
make sense in Spring Framework 6 timeframe along to array
based variant removal for both Java and Kotlin.
Closes gh-26312
This commit is contained in:
parent
44b29b6ecf
commit
6d85a8a0cc
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors
|
||||
* Copyright 2002-2021 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,8 +54,10 @@ 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, T::class.java, args) as T
|
||||
queryForObject(sql, args, T::class.java) as T
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant.
|
||||
|
|
@ -86,8 +88,11 @@ inline fun <reified T> JdbcOperations.queryForList(sql: String, args: Array<out
|
|||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
// TODO Replace by the vararg variant in Spring Framework 6
|
||||
inline fun <reified T> JdbcOperations.queryForList(sql: String, args: Array<out Any>): List<T> =
|
||||
queryForList(sql, T::class.java, args)
|
||||
queryForList(sql, args, T::class.java)
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors
|
||||
* Copyright 2002-2021 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,11 +67,12 @@ class JdbcOperationsExtensionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Suppress("DEPRECATION")
|
||||
fun `queryForObject with reified type parameters and args`() {
|
||||
val args = arrayOf(3)
|
||||
every { template.queryForObject(sql, any<Class<Int>>(), args) } returns 2
|
||||
val args = arrayOf(3, 4)
|
||||
every { template.queryForObject(sql, args, any<Class<Int>>()) } returns 2
|
||||
assertThat(template.queryForObject<Int>(sql, args)).isEqualTo(2)
|
||||
verify { template.queryForObject(sql, any<Class<Int>>(), args) }
|
||||
verify { template.queryForObject(sql, args, any<Class<Int>>()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -93,12 +94,13 @@ class JdbcOperationsExtensionsTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Suppress("DEPRECATION")
|
||||
fun `queryForList with reified type parameters and args`() {
|
||||
val list = listOf(1, 2, 3)
|
||||
val args = arrayOf(3)
|
||||
every { template.queryForList(sql, any<Class<Int>>(), args) } returns list
|
||||
val args = arrayOf(3, 4)
|
||||
every { template.queryForList(sql, args, any<Class<Int>>()) } returns list
|
||||
template.queryForList<Int>(sql, args)
|
||||
verify { template.queryForList(sql, any<Class<Int>>(), args) }
|
||||
verify { template.queryForList(sql, args, any<Class<Int>>()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue