Extensions to use compilation cache like it is variable with sql source

This commit is contained in:
Andrew Golovashevich 2025-03-26 23:16:17 +03:00
parent 6b8be01b28
commit c5d569e0f1

View File

@ -0,0 +1,21 @@
@file:JvmName("_EntryPointsKt")
package ru.langrafhomyak.db.jdbc_resources_manager
import java.sql.Connection
import java.sql.PreparedStatement
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
@JvmName("prepareStatement")
public fun Connection.prepareStatement(ps: PreparedStatementsCompilationCache): PreparedStatement = ps.preparedStatementForConnection(this)
@JvmName("prepareStatement\$autoclose")
public fun <R> Connection.prepareStatement(ps: PreparedStatementsCompilationCache, preparedStatementScope: (ps: PreparedStatement) -> R): R {
contract {
callsInPlace(preparedStatementScope, InvocationKind.EXACTLY_ONCE)
}
val w = ps.preparedStatementForConnection(this)
return safeAutoClose1(finally = w::close) { preparedStatementScope(w) }
}