From 9c4147b73a579631f0f3e99497ce0abf3b365813 Mon Sep 17 00:00:00 2001 From: Chantal Loncle <82039410+bog-walk@users.noreply.github.com> Date: Sun, 7 Dec 2025 15:32:14 -0500 Subject: [PATCH] chore!: Remove unused R2dbcPreparedStatementApi methods - Remove closeIfPossible() & cancel(), as they do nothing and have no relevant Statement methods available. - Rename closeExecutedStatements() to clearExecutedStatements() & no longer needs to suspend --- .../Writerside/topics/Breaking-Changes.md | 9 +++++++++ .../sql/tests/shared/UserCreatedTransactionsTests.kt | 4 ++-- exposed-r2dbc/api/exposed-r2dbc.api | 6 +----- .../org/jetbrains/exposed/v1/r2dbc/R2dbcTransaction.kt | 8 +++----- .../v1/r2dbc/statements/R2dbcPreparedStatementImpl.kt | 8 -------- .../exposed/v1/r2dbc/statements/SuspendExecutable.kt | 2 +- .../r2dbc/statements/api/R2dbcPreparedStatementApi.kt | 6 ------ .../exposed/v1/r2dbc/transactions/Transactions.kt | 10 +++++----- 8 files changed, 21 insertions(+), 32 deletions(-) diff --git a/documentation-website/Writerside/topics/Breaking-Changes.md b/documentation-website/Writerside/topics/Breaking-Changes.md index e89ca5349e..267958bfa5 100644 --- a/documentation-website/Writerside/topics/Breaking-Changes.md +++ b/documentation-website/Writerside/topics/Breaking-Changes.md @@ -1,5 +1,14 @@ # Breaking Changes +## 1.0.0-rc-5 + +* The interface `R2dbcPreparedStatementApi` no longer holds the unused methods `closeIfPossible()` or `cancel()` + as there are no relevant matching methods available for `io.r2dbc.spi.Statement`, in the same way as there are for + JDBC's `java.sql.PreparedStatement`. Any resource cleanup logic that may have been implemented via these methods can + still be implemented by `GlobalStatementInterceptor.afterStatementPrepared()`. +* `R2dbcTransaction.closeExecutedStatements()` has been renamed to `.clearExecutedStatements()` to better relay it's actual + behavior. It no longer invokes the now-removed method `R2dbcPreparedStatementApi.closeIfPossible()` & no longer suspends. + ## 1.0.0-rc-4 * If H2 version 2.4.240+ is detected, `datetime()` column type will now map to type `TIMESTAMP(9)` in the following modes: diff --git a/exposed-r2dbc-tests/src/test/kotlin/org/jetbrains/exposed/v1/r2dbc/sql/tests/shared/UserCreatedTransactionsTests.kt b/exposed-r2dbc-tests/src/test/kotlin/org/jetbrains/exposed/v1/r2dbc/sql/tests/shared/UserCreatedTransactionsTests.kt index 95151a81b4..d395315cac 100644 --- a/exposed-r2dbc-tests/src/test/kotlin/org/jetbrains/exposed/v1/r2dbc/sql/tests/shared/UserCreatedTransactionsTests.kt +++ b/exposed-r2dbc-tests/src/test/kotlin/org/jetbrains/exposed/v1/r2dbc/sql/tests/shared/UserCreatedTransactionsTests.kt @@ -127,7 +127,7 @@ class UserCreatedTransactionsTests : R2dbcDatabaseTestsBase() { @OptIn(InternalApi::class) @Test - fun testCloseExecutedStatements() { + fun testClearExecutedStatements() { withConnection(dialect) { db, testDb -> val tx = TransactionManager.currentOrNew() @@ -144,7 +144,7 @@ class UserCreatedTransactionsTests : R2dbcDatabaseTestsBase() { assertEquals(1, result?.size) assertEquals(100, result?.get(0)) - tx.closeExecutedStatements() + tx.clearExecutedStatements() tx.close() } diff --git a/exposed-r2dbc/api/exposed-r2dbc.api b/exposed-r2dbc/api/exposed-r2dbc.api index 66f3455cd3..45d5e1c623 100644 --- a/exposed-r2dbc/api/exposed-r2dbc.api +++ b/exposed-r2dbc/api/exposed-r2dbc.api @@ -311,8 +311,8 @@ public class org/jetbrains/exposed/v1/r2dbc/R2dbcTransaction : org/jetbrains/exp public static final field Companion Lorg/jetbrains/exposed/v1/r2dbc/R2dbcTransaction$Companion; public fun (Lorg/jetbrains/exposed/v1/r2dbc/transactions/R2dbcTransactionInterface;)V public final fun addLogger ([Lorg/jetbrains/exposed/v1/core/SqlLogger;)Lorg/jetbrains/exposed/v1/core/CompositeSqlLogger; + public final fun clearExecutedStatements ()V public fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun closeExecutedStatements (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun commit (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun connection (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun exec (Ljava/lang/String;Ljava/lang/Iterable;Lorg/jetbrains/exposed/v1/core/statements/StatementType;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -752,8 +752,6 @@ public final class org/jetbrains/exposed/v1/r2dbc/statements/R2dbcConnectionImpl public final class org/jetbrains/exposed/v1/r2dbc/statements/R2dbcPreparedStatementImpl : org/jetbrains/exposed/v1/r2dbc/statements/api/R2dbcPreparedStatementApi { public fun (Lio/r2dbc/spi/Statement;Lio/r2dbc/spi/Connection;ZLorg/jetbrains/exposed/v1/core/vendors/DatabaseDialect;Lorg/jetbrains/exposed/v1/r2dbc/mappers/R2dbcTypeMapping;)V public fun addBatch (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun cancel (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun closeIfPossible (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun executeBatch (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun executeMultiple (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun executeQuery (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -969,8 +967,6 @@ public final class org/jetbrains/exposed/v1/r2dbc/statements/api/R2dbcLocalMetad public abstract interface class org/jetbrains/exposed/v1/r2dbc/statements/api/R2dbcPreparedStatementApi : org/jetbrains/exposed/v1/core/statements/api/PreparedStatementApi { public abstract fun addBatch (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun cancel (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun closeIfPossible (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun executeBatch (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun executeMultiple (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun executeQuery (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/R2dbcTransaction.kt b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/R2dbcTransaction.kt index 6d43fb07d2..61b99e618a 100644 --- a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/R2dbcTransaction.kt +++ b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/R2dbcTransaction.kt @@ -315,11 +315,9 @@ open class R2dbcTransaction( internal suspend fun execQuery(query: SuspendExecutable): R2dbcResult = execQuery(query) { it } ?: error("A R2dbcResult was expected, but a result was not retrieved from the database") - /** Closes all previously executed statements and resets or releases any used database and/or driver resources. */ - suspend fun closeExecutedStatements() { - executedStatements.forEach { - it.closeIfPossible() - } + /** Clears all previously executed statements and resets or releases any used database and/or driver resources. */ + fun clearExecutedStatements() { + // no Statement.close() in R2DBC openResultRowsCount = 0 executedStatements.clear() } diff --git a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/R2dbcPreparedStatementImpl.kt b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/R2dbcPreparedStatementImpl.kt index 1744c9624e..e72fc3d80e 100644 --- a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/R2dbcPreparedStatementImpl.kt +++ b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/R2dbcPreparedStatementImpl.kt @@ -136,10 +136,6 @@ class R2dbcPreparedStatementImpl( throw IllegalArgumentException("Unsupported array type: ${type::class.qualifiedName}") } - override suspend fun closeIfPossible() { - // do nothing - } - override suspend fun executeBatch(): List { val result = statement.execute() val r2dbcResult = R2dbcResult(result, typeMapping) @@ -152,8 +148,4 @@ class R2dbcPreparedStatementImpl( r2dbcResult.rowsUpdated().toList() } } - - override suspend fun cancel() { - // do nothing - } } diff --git a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/SuspendExecutable.kt b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/SuspendExecutable.kt index bb5ef84590..579cb7df16 100644 --- a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/SuspendExecutable.kt +++ b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/SuspendExecutable.kt @@ -150,7 +150,7 @@ internal suspend fun > SuspendExecutable.executeIn( if (isNotLastItemInTheBatch && (contexts.size > 1 || isAlwaysBatch)) statement.addBatch() } if (!transaction.db.supportsMultipleResultSets) { - transaction.closeExecutedStatements() + transaction.clearExecutedStatements() } transaction.currentStatement = statement diff --git a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/api/R2dbcPreparedStatementApi.kt b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/api/R2dbcPreparedStatementApi.kt index b3bd81fb41..61ca5062cf 100644 --- a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/api/R2dbcPreparedStatementApi.kt +++ b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/statements/api/R2dbcPreparedStatementApi.kt @@ -39,9 +39,6 @@ interface R2dbcPreparedStatementApi : PreparedStatementApi { /** The [R2dbcResult] generated by the executed statement, or `null` if none was retrieved. */ suspend fun getResultRow(): R2dbcResult? - /** Closes the statement, if still open, and releases any of its database and/or driver resources. */ - suspend fun closeIfPossible() - /** * Executes batched SQL statements stored as an [io.r2dbc.spi.Statement]. * @@ -49,7 +46,4 @@ interface R2dbcPreparedStatementApi : PreparedStatementApi { * ordered based on the order in which statements were provided to the batch. */ suspend fun executeBatch(): List - - /** Cancels the statement, if supported by the database. */ - suspend fun cancel() } diff --git a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/transactions/Transactions.kt b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/transactions/Transactions.kt index fd805540c8..b96726ce59 100644 --- a/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/transactions/Transactions.kt +++ b/exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/transactions/Transactions.kt @@ -258,10 +258,10 @@ internal suspend fun handleR2dbcException(cause: R2dbcException, transaction: R2 } /** - * Closes all statements and the connection associated with a transaction. + * Clears all statements and closes the connection associated with a transaction. * - * This function ensures proper cleanup of resources by closing the current statement, - * all executed statements, and the transaction connection. Any exceptions during cleanup are logged. + * This function ensures proper cleanup of resources by clearing the current statement, + * all executed statements, and closing the transaction connection. Any exceptions during cleanup are logged. * * @param transaction The transaction whose resources should be closed. */ @@ -270,10 +270,10 @@ internal suspend fun closeStatementsAndConnection(transaction: R2dbcTransaction) @Suppress("TooGenericExceptionCaught") try { currentStatement?.let { - it.closeIfPossible() + // no Statement.close() in R2DBC transaction.currentStatement = null } - transaction.closeExecutedStatements() + transaction.clearExecutedStatements() } catch (cause: Exception) { exposedLogger.warn("Statements close failed", cause) }