From c5d569e0f1b86bf073327989c27d8693d587c630 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Wed, 26 Mar 2025 23:16:17 +0300 Subject: [PATCH] Extensions to use compilation cache like it is variable with sql source --- .../db/jdbc_resources_manager/entry_points.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/jvmMain/kotlin/ru/langrafhomyak/db/jdbc_resources_manager/entry_points.kt diff --git a/src/jvmMain/kotlin/ru/langrafhomyak/db/jdbc_resources_manager/entry_points.kt b/src/jvmMain/kotlin/ru/langrafhomyak/db/jdbc_resources_manager/entry_points.kt new file mode 100644 index 0000000..d965589 --- /dev/null +++ b/src/jvmMain/kotlin/ru/langrafhomyak/db/jdbc_resources_manager/entry_points.kt @@ -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 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) } +} \ No newline at end of file