From 6d85a8a0cc6972203337ca0bc14ddd08cc52e238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 4 Jan 2021 14:48:49 +0100 Subject: [PATCH] Fix JdbcOperationsExtensions This commit reverts some changes done in 2d5f9723fa9ba54480cffb650158f6a8e956e6c8 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 --- .../jdbc/core/JdbcOperationsExtensions.kt | 11 ++++++++--- .../jdbc/core/JdbcOperationsExtensionsTests.kt | 16 +++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt b/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt index ff97b511d3..f6dbe709a5 100644 --- a/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt +++ b/spring-jdbc/src/main/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensions.kt @@ -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 JdbcOperations.queryForObject(sql: String, args: Array JdbcOperations.queryForObject(sql: String, args: Array): T? = - queryForObject(sql, T::class.java, args) as T + queryForObject(sql, args, T::class.java) as T /** * Extension for [JdbcOperations.queryForList] providing a `queryForList("...")` variant. @@ -86,8 +88,11 @@ inline fun JdbcOperations.queryForList(sql: String, args: Array JdbcOperations.queryForList(sql: String, args: Array): List = - queryForList(sql, T::class.java, args) + queryForList(sql, args, T::class.java) + /** * Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function diff --git a/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt b/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt index 8c1f39fae4..e3e086b30f 100644 --- a/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt +++ b/spring-jdbc/src/test/kotlin/org/springframework/jdbc/core/JdbcOperationsExtensionsTests.kt @@ -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>(), args) } returns 2 + val args = arrayOf(3, 4) + every { template.queryForObject(sql, args, any>()) } returns 2 assertThat(template.queryForObject(sql, args)).isEqualTo(2) - verify { template.queryForObject(sql, any>(), args) } + verify { template.queryForObject(sql, args, any>()) } } @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>(), args) } returns list + val args = arrayOf(3, 4) + every { template.queryForList(sql, args, any>()) } returns list template.queryForList(sql, args) - verify { template.queryForList(sql, any>(), args) } + verify { template.queryForList(sql, args, any>()) } } @Test