TransactionScope


public interface TransactionScope<T extends Object> extends PooledConnection


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

See also
Transactor

Summary

Public methods

abstract @NonNull Void
rollback(@NonNull T result)

Rollback the transaction, completing it and returning the result.

abstract @NonNull R
<R extends Object> withNestedTransaction(
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransactionScope<@NonNull R>, @NonNull R> block
)

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

Inherited methods

From androidx.room.PooledConnection
abstract @NonNull R
<R extends Object> usePrepared(
    @NonNull String sql,
    @NonNull Function1<@NonNull SQLiteStatement, @NonNull R> block
)

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

Public methods

rollback

abstract @NonNull Void rollback(@NonNull T result)

Rollback the transaction, completing it and returning the result.

withNestedTransaction

abstract @NonNull R <R extends Object> withNestedTransaction(
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransactionScope<@NonNull R>, @NonNull R> block
)

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
@ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransactionScope<@NonNull R>, @NonNull R> block

The code that will execute within the transaction.