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

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.

Updated Dec 27, 2019

Discover the latest app development tools, platform updates, training, and documentation for developers across every Android device.

Updated Dec 18, 2024

The developer center about creating games for Android. Learn how to develop, optimize, and publish your Android game using the latest tools and SDKs.

Updated Nov 13, 2024