Transactor


public interface Transactor extends PooledConnection


A PooledConnection that can perform transactions.

Summary

Nested types

Transaction types.

Public methods

abstract boolean

Returns true if this connection has an active transaction, otherwise false.

abstract @NonNull R
<R extends Object> withTransaction(
    @NonNull Transactor.SQLiteTransactionType type,
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransactionScope<@NonNull R>, @NonNull R> block
)

Begins a 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

inTransaction

abstract boolean inTransaction()

Returns true if this connection has an active transaction, otherwise false.

withTransaction

abstract @NonNull R <R extends Object> withTransaction(
    @NonNull Transactor.SQLiteTransactionType type,
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransactionScope<@NonNull R>, @NonNull R> block
)

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

If inTransaction returns true and this function is invoked it is the equivalent of starting a nested transaction as if TransactionScope.withNestedTransaction was invoked and the type of the transaction will be ignored since its type will be inherited from the parent transaction.

See also Transaction

Parameters
@NonNull Transactor.SQLiteTransactionType type

The type of transaction to begin.

@ExtensionFunctionType @NonNull SuspendFunction1<@NonNull TransactionScope<@NonNull R>, @NonNull R> block

The code that will execute within the transaction.