[CORDA-3303] - Avoid flushing when inside a cascade (#5575)

* [CORDA-3303] - Avoid flushing when inside a cascade

* Remove listener infrastructure
This commit is contained in:
Dimos Raptis
2019-10-11 10:58:26 +01:00
committed by Rick Parker
parent 48fd78d059
commit 7666ca0d80
6 changed files with 192 additions and 126 deletions

View File

@ -25,9 +25,6 @@ class DatabaseTransaction(
) {
val id: UUID = UUID.randomUUID()
val flushing: Boolean get() = _flushingCount > 0
private var _flushingCount = 0
val connection: Connection by lazy(LazyThreadSafetyMode.NONE) {
database.dataSource.connection.apply {
autoCommit = false
@ -37,27 +34,6 @@ class DatabaseTransaction(
private val sessionDelegate = lazy {
val session = database.entityManagerFactory.withOptions().connection(connection).openSession()
session.addEventListeners(object : BaseSessionEventListener() {
override fun flushStart() {
_flushingCount++
super.flushStart()
}
override fun flushEnd(numberOfEntities: Int, numberOfCollections: Int) {
super.flushEnd(numberOfEntities, numberOfCollections)
_flushingCount--
}
override fun partialFlushStart() {
_flushingCount++
super.partialFlushStart()
}
override fun partialFlushEnd(numberOfEntities: Int, numberOfCollections: Int) {
super.partialFlushEnd(numberOfEntities, numberOfCollections)
_flushingCount--
}
})
hibernateTransaction = session.beginTransaction()
session
}