mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
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:
committed by
Rick Parker
parent
5a41ec9b82
commit
43205e1f1a
@ -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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user