corda / net.corda.node.utilities / StrandLocalTransactionManager

StrandLocalTransactionManager

class StrandLocalTransactionManager : TransactionManager

A relatively close copy of the ThreadLocalTransactionManager in Exposed but with the following adjustments to suit our environment:

Because the construction of a Database instance results in replacing the singleton TransactionManager instance, our tests involving two MockNodes effectively replace the database instances of each other and continue to trample over each other. So here we use a companion object to hold them as ThreadLocal and StrandLocalTransactionManager is otherwise effectively stateless so it's replacement does not matter. The ThreadLocal is then set correctly and explicitly just prior to initiating a transaction in databaseTransaction and createDatabaseTransaction above.

The StrandLocalTransactionManager instances have an Observable of the transaction close Boundarys which facilitates the use of Observable.afterDatabaseCommit to create event streams that only emit once the database transaction is closed and the data has been persisted and becomes visible to other observers.

Types

Boundary data class Boundary

Constructors

<init> StrandLocalTransactionManager(initWithDatabase: Database)

A relatively close copy of the ThreadLocalTransactionManager in Exposed but with the following adjustments to suit our environment:

Functions

currentOrNull fun currentOrNull(): Transaction?
newTransaction fun newTransaction(isolation: Int): Transaction

Companion Object Properties

database var database: Database
manager val manager: StrandLocalTransactionManager
transactionBoundaries val transactionBoundaries: Subject<Boundary, Boundary>
transactionId val transactionId: UUID

Companion Object Functions

restoreThreadLocalTx fun restoreThreadLocalTx(context: Pair<Database?, Transaction?>): Unit
setThreadLocalTx fun setThreadLocalTx(tx: Transaction?): Pair<Database?, Transaction?>