DefaultSessionProvider

The SessionProvider for an application that runs its own transactions, binding the current one to the thread that started it.

Outside a transaction, every operation borrows a session from dataSource and gives it back when it is done. That is as cheap as it sounds: the session itself is a handful of allocations over the connection, and giving it back costs no round trip unless it registered a LISTEN or left a transaction open.

Where something else owns the transaction - Spring, most obviously - this is the wrong provider; that one finds the session where the framework put it rather than on a ThreadLocal of its own.

Parameters

dataSource

Where connections come from. Not closed by close; whoever built the pool owns it.

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.

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.