transaction

open override fun <T> transaction(propagation: TransactionPropagation = TransactionPropagation.REQUIRED, isolation: TransactionIsolationLevel? = null, readOnly: Boolean = false, statementTimeout: Duration? = null, transactionTimeout: Duration? = null, block: OctaviusClient.() -> T): T

Runs block inside a transaction, committing when it returns and rolling back when it throws.

Every execute made from this thread while block runs lands on the transaction's session, so a repository function called from in here joins the transaction without being told about it. That binding is per-thread and does not follow work handed to another one: a coroutine launched on a different dispatcher inside block gets a session and a transaction of its own, and the commit here says nothing about it.

The receiver is this client, so queries inside read exactly as they do outside. What it does not offer is a way to commit or roll back: the surrounding block is what decides, and a session reached through execute is an OctaviusSessionOperations rather than the full session for the same reason.

Return

Whatever block produced.

Parameters

propagation

What to do about a transaction already running on this thread.

isolation

The isolation level to run at, or null for the server's. Ignored when joining a transaction that is already running, which cannot change the level it began at.

readOnly

Whether the transaction refuses writes. Ignored on the same terms as isolation.

statementTimeout

Aborts any single statement running longer than this.

transactionTimeout

Aborts the transaction once it has been open longer than this.

block

The work to run in the transaction.