DefaultSessionProvider

The SessionProvider for an application that runs its own transactions: the outermost operation on a thread borrows a session from dataSource, binds it to the thread, and gives it back when it returns.

Operations made from inside one another share that session, in a transaction or not, so nesting holds one connection. A level that begins while the one above is still reading a result - in a forEach* block or a ResultConverter - is refused by the driver with CONNECTION_BUSY; a second connection there is taken from the DataSource by hand.

Where a framework owns the transactions, use a provider that finds its session instead.

Parameters

dataSource

Where connections come from. Not closed by close.

Constructors

Link copied to clipboard
constructor(dataSource: DataSource)

Functions

Link copied to clipboard
open override fun close()

Releases what this provider holds of its own. Whatever supplies its connections is not its to close.

Link copied to clipboard
open override fun <T> execute(action: OctaviusSessionOperations.() -> T): T

Runs action on the session for the current context: the transaction's inside a transaction, the enclosing call's inside another execute, and otherwise one obtained for this call alone, whose statements commit as they go. An implementation is expected to share the session across nested calls.

Link copied to clipboard
open override fun <T> transaction(definition: TransactionDefinition, block: () -> T): T

Runs block with a transaction open, committing when it returns and rolling back when it throws. Every execute from this thread while block runs lands on the transaction's session; work handed to another thread does not.