@@ -123,7 +123,7 @@ private constructor(
123
123
}
124
124
}
125
125
}
126
- }
126
+ },
127
127
)
128
128
},
129
129
5 ,
@@ -172,7 +172,9 @@ private constructor(
172
172
if (config.type.isVitess) {
173
173
hibernateSession.doReturningWork { conn ->
174
174
previousTarget = conn.catalog
175
- if (previousTarget != primaryTarget) { conn.catalog = primaryTarget }
175
+ if (previousTarget != primaryTarget) {
176
+ conn.catalog = primaryTarget
177
+ }
176
178
}
177
179
}
178
180
@@ -193,7 +195,9 @@ private constructor(
193
195
// Restore to the same destination the lock was acquired on.
194
196
hibernateSession.doReturningWork { conn ->
195
197
previousTarget = conn.catalog
196
- if (previousTarget != primaryTarget) { conn.catalog = primaryTarget }
198
+ if (previousTarget != primaryTarget) {
199
+ conn.catalog = primaryTarget
200
+ }
197
201
}
198
202
}
199
203
hibernateSession.tryReleaseLock(lockKey)
@@ -278,6 +282,7 @@ private constructor(
278
282
if (transaction.isActive) {
279
283
try {
280
284
transaction.rollback()
285
+ session.onSessionClose { session.runRollbackHooks(e) }
281
286
} catch (suppressed: Exception ) {
282
287
rethrow.addSuppressed(suppressed)
283
288
}
@@ -332,7 +337,7 @@ private constructor(
332
337
" No reader is configured for replica reads, pass in both a writer and reader qualifier " +
333
338
" and the full DataSourceClustersConfig into HibernateModule, like this:\n " +
334
339
" \t install(HibernateModule(AppDb::class, AppReaderDb::class, " +
335
- " config.data_source_clusters[\" name\" ]))"
340
+ " config.data_source_clusters[\" name\" ]))" ,
336
341
)
337
342
}
338
343
@@ -503,6 +508,8 @@ private constructor(
503
508
private val preCommitHooks = mutableListOf< () -> Unit > ()
504
509
private val postCommitHooks = mutableListOf< () -> Unit > ()
505
510
private val sessionCloseHooks = mutableListOf< () -> Unit > ()
511
+ private val rollbackHooks = mutableListOf< (error: Throwable ) -> Unit > ()
512
+
506
513
internal var inTransaction = false
507
514
508
515
init {
@@ -616,7 +623,7 @@ private constructor(
616
623
617
624
internal fun preCommit () {
618
625
preCommitHooks.forEach { preCommitHook ->
619
- // Propagate hook exceptions up to the transacter so that the the transaction is rolled
626
+ // Propagate hook exceptions up to the transacter so that the transaction is rolled
620
627
// back and the error gets returned to the application.
621
628
preCommitHook()
622
629
}
@@ -648,6 +655,14 @@ private constructor(
648
655
sessionCloseHooks.add(work)
649
656
}
650
657
658
+ override fun onRollback (work : (error: Throwable ) -> Unit ) {
659
+ rollbackHooks.add(work)
660
+ }
661
+
662
+ internal fun runRollbackHooks (error : Throwable ) {
663
+ rollbackHooks.forEach { rollbackHook -> rollbackHook(error) }
664
+ }
665
+
651
666
override fun <T > withoutChecks (vararg checks : Check , body : () -> T ): T {
652
667
return CheckDisabler .withoutChecks(* checks) { body() }
653
668
}
0 commit comments