CORDA-3471: Create CordaTransactionSupport and make it accessible through AppServiceHub (#5768)

* CORDA-3471: Create `CordaTransactionSupport` and use wherever possible instead of `CordaPersistence`

* CORDA-3471: Address comments by @mnesbit
- Relocate `CordaTransactionSupport` to `core`
- Create a lighter version of transaction - `VaultTransaction` that gives access to `session` object only.

* CORDA-3471: More changes after discussion with  @mnesbit
- Rename `VaultTransaction` into `SessionScope`.

* CORDA-3471: Revert changes to most of the files after conversation with @mnesbit and @rick-r3

* CORDA-3471: Introduce `CordaTransactionSupportImpl` and make it accessible via `AppServiceHub`.

* CORDA-3471: Minor change (comment).

* CORDA-3471: Address input from @mnesbit

* CORDA-3471: Address input from @rick-r3

* CORDA-3471: Make Detekt happier

* CORDA-3471: Add a new test that proves transactions can be started from client threads

As requested by @mnesbit

* CORDA-3471: Change log and documentation update.

As requested by @mnesbit
This commit is contained in:
Viktor Kolomeyko
2019-12-04 17:18:40 +00:00
committed by Rick Parker
parent 5a41ec9b82
commit 43205e1f1a
10 changed files with 140 additions and 6 deletions

View File

@ -0,0 +1,21 @@
package net.corda.nodeapi.internal.persistence
import net.corda.core.node.services.vault.CordaTransactionSupport
import net.corda.core.node.services.vault.SessionScope
/**
* Helper class that wraps [CordaPersistence] and limits operations on it down to methods exposed by [CordaTransactionSupport].
*/
class CordaTransactionSupportImpl(private val persistence: CordaPersistence) : CordaTransactionSupport {
override fun <T> transaction(statement: SessionScope.() -> T): T {
// An alternative approach could be to make `DatabaseTransaction` extend from `SessionScope`, but this will introduce a hierarchical
// dependency which might be unwanted in some cases.
fun DatabaseTransaction.innerFunc(): T {
return statement.invoke(
object : SessionScope {
override val session = this@innerFunc.session
})
}
return persistence.transaction(0, DatabaseTransaction::innerFunc)
}
}