TransactionScope



A PooledConnection with an active transaction capable of performing nested transactions.

See also
Transactor

Summary

Public functions

suspend Nothing
rollback(result: T)

Rollback the transaction, completing it and returning the result.

Cmn
suspend R
<R : Any?> withNestedTransaction(block: suspend TransactionScope<R>.() -> R)

Begins a nested transaction and runs the block within the transaction.

Cmn

Inherited functions

From androidx.room.PooledConnection
suspend R
<R : Any?> usePrepared(sql: String, block: (SQLiteStatement) -> R)

Prepares a new SQL statement and use it within the code block.

Cmn

Public functions

rollback

suspend fun rollback(result: T): Nothing

Rollback the transaction, completing it and returning the result.

withNestedTransaction

suspend fun <R : Any?> withNestedTransaction(block: suspend TransactionScope<R>.() -> R): R

Begins a nested transaction and runs the block within the transaction. If block fails to complete normally i.e., an exception is thrown, or rollback is invoked then the transaction will be rollback, otherwise it is committed.

Note that a nested transaction is still governed by its parent transaction and it too must complete successfully for all its children transactions to be committed.

See also Savepoint

Parameters
block: suspend TransactionScope<R>.() -> R

The code that will execute within the transaction.