8000 Add option to r2dbc to close the prepared statement (#330) · jasync-sql/jasync-sql@f945a99 · GitHub
[go: up one dir, main page]

Skip to content

Commit f945a99

Browse files
authored
Add option to r2dbc to close the prepared statement (#330)
1 parent 6bcf868 commit f945a99

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

r2dbc-mysql/src/main/java/JasyncStatement.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal class JasyncStatement(private val clientSupplier: Supplier<JasyncConnec
2626

2727
private var isPrepared = false
2828
private var selectLastInsertId: Boolean = false
29+
private var releasePreparedStatementAfterUse: Boolean = false
2930

3031
private var generatedKeyName: String = "LAST_INSERT_ID"
3132

@@ -71,6 +72,13 @@ internal class JasyncStatement(private val clientSupplier: Supplier<JasyncConnec
7172
return this
7273
}
7374

75+
fun releasePreparedStatementAfterUse(): Statement {
76+
check(isPrepared) { "releasePreparedStatementAfterUse can only be called for prepared statements" }
77+
78+
releasePreparedStatementAfterUse = true
79+
return this
80+
}
81+
7482
override fun execute(): Publisher<out Result> {
7583
return Mono.fromSupplier(clientSupplier).flatMapMany { connection ->
7684
if (isPrepared) {
@@ -84,7 +92,7 @@ internal class JasyncStatement(private val clientSupplier: Supplier<JasyncConnec
8492
}
8593
}.toFlux()
8694

87-
allParams.concatMap { connection.sendPreparedStatement(sql, it).toMono() }
95+
allParams.concatMap { connection.sendPreparedStatement(sql, it, releasePreparedStatementAfterUse).toMono() }
8896
} else {
8997
connection.sendQuery(sql).toMono()
9098
}

0 commit comments

Comments
 (0)
0