nested

inline fun <T> nested(isolation: TransactionIsolationLevel? = null, readOnly: Boolean = false, statementTimeout: Duration? = null, transactionTimeout: Duration? = null, crossinline block: OctaviusSessionOperations.() -> T): T

Executes the given block within a nested transaction scope.

If a transaction is already active, a savepoint is created. Upon successful completion of the block, the savepoint is released. If an exception occurs, the transaction is rolled back to the savepoint. If no transaction is active, a new one is started similar to required.

Inside the block, manual transaction operations are not accessible as the receiver is restricted to OctaviusSessionOperations. A return out of the block does not compile either - use return@nested, since an early exit would otherwise slip past the release and the rollback alike and leave the savepoint standing.

The four terms reach only the case where this starts a transaction of its own; on the savepoint path they are ignored and a warning names them.

Return

The result of the block.

Parameters

isolation
readOnly
statementTimeout
transactionTimeout
block

The block of code to execute.