Skip to content

Commit

Permalink
jdbc: fixed usage of multiple different DataSources when there is an …
Browse files Browse the repository at this point in the history
…active transaction
  • Loading branch information
angryziber committed Dec 2, 2024
1 parent 53bf32b commit 40f8697
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased
* jdbc: between operator introduced with open and closed ranges, also in and notIn
* jdbc: @NoTransaction can now be used on jobs
* jdbc: fixed usage of multiple different DataSources when there is an active transaction
* json: TSGenerator will now use more type-safe string template types for java.time classes, e.g. `${number}-${number}-${number}` instead of `string`

# 1.6.9
Expand Down
4 changes: 2 additions & 2 deletions jdbc/src/Transaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.coroutines.CoroutineContext
/** Disable transaction for a route or a job. This will most likely leave the connection in auto-commit mode (depending on connection pool settings). */
@Target(FUNCTION, CLASS) annotation class NoTransaction

class Transaction(private val db: DataSource): AutoCloseable {
class Transaction(val db: DataSource): AutoCloseable {
companion object {
private val log = logger()
private val threadLocal = ThreadLocal<Transaction>()
Expand Down Expand Up @@ -56,7 +56,7 @@ class Transaction(private val db: DataSource): AutoCloseable {

fun <R> DataSource.withConnection(block: Connection.() -> R): R {
val tx = Transaction.current()
return if (tx != null) tx.connection.block()
return if (tx?.db == this) tx.connection.block()
else connection.use(block)
}

Expand Down

0 comments on commit 40f8697

Please sign in to comment.