net.corda.node.utilities

## Class StrandLocalTransactionManager

- net.corda.node.utilities.StrandLocalTransactionManager

-     public class StrandLocalTransactionManager

  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 `class 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 `class StrandLocalTransactionManager` instances have an Observable of the transaction close `class StrandLocalTransactionManager.Boundary`s 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.

  See Also:
    ThreadLocalTransactionManager, MockNode, ThreadLocal, `class StrandLocalTransactionManager`, ThreadLocal, `class StrandLocalTransactionManager`, `class StrandLocalTransactionManager.Boundary`, Observable.afterDatabaseCommit

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `StrandLocalTransactionManager.Boundary`
    `static class` | `StrandLocalTransactionManager.Companion`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static StrandLocalTransactionManager.Companion` | `Companion`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StrandLocalTransactionManager(org.jetbrains.exposed.sql.Database initWithDatabase)` A relatively close copy of the ThreadLocalTransactionManager in Exposed but with the following adjustments to suit our environment:

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.jetbrains.exposed.sql.Transaction` | `currentOrNull()`
    `org.jetbrains.exposed.sql.Transaction` | `newTransaction(int isolation)`

- - ### Field Detail

    - #### Companion

          public static StrandLocalTransactionManager.Companion Companion

  - ### Constructor Detail

    - #### StrandLocalTransactionManager

          public StrandLocalTransactionManager(org.jetbrains.exposed.sql.Database initWithDatabase)

      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 `class 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 `class StrandLocalTransactionManager` instances have an Observable of the transaction close `class StrandLocalTransactionManager.Boundary`s 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.

      See Also:
        ThreadLocalTransactionManager, MockNode, ThreadLocal, `class StrandLocalTransactionManager`, ThreadLocal, `class StrandLocalTransactionManager`, `class StrandLocalTransactionManager.Boundary`, Observable.afterDatabaseCommit

  - ### Method Detail

    - #### newTransaction

          public org.jetbrains.exposed.sql.Transaction newTransaction(int isolation)

    - #### currentOrNull

          public org.jetbrains.exposed.sql.Transaction currentOrNull()