# TransactionScope

Artifact: [androidx.room:room-runtime](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/Transactor.kt+class:androidx.room.TransactionScope) Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

*** ** * ** ***


```
public interface TransactionScope<T extends Object> extends PooledConnection
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/room/PooledConnection` with an active transaction capable of performing nested transactions.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/room/Transactor` |   |

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Void.html` | `https://developer.android.com/reference/androidx/room/TransactionScope#rollback(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull T result)` Rollback the transaction, completing it and returning the `https://developer.android.com/reference/androidx/room/TransactionScope#rollback(kotlin.Any)`. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull R` | `<R extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/room/TransactionScope#withNestedTransaction(kotlin.coroutines.SuspendFunction1)( @https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/TransactionScope<@https://developer.android.com/reference/androidx/annotation/NonNull R>, @https://developer.android.com/reference/androidx/annotation/NonNull R> block )` Begins a nested transaction and runs the `https://developer.android.com/reference/androidx/room/TransactionScope#withNestedTransaction(kotlin.coroutines.SuspendFunction1)` within the transaction. |

| ### Inherited methods |
|---|
| From [androidx.room.PooledConnection](https://developer.android.com/reference/androidx/room/PooledConnection) |---|---| | `abstract @https://developer.android.com/reference/androidx/annotation/NonNull R` | `<R extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sql, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteStatement, @https://developer.android.com/reference/androidx/annotation/NonNull R> block )` Prepares a new SQL statement and use it within the code `https://developer.android.com/reference/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)`. | |

## Public methods

### rollback

```
abstract @NonNull Void rollback(@NonNull T result)
```

Rollback the transaction, completing it and returning the `https://developer.android.com/reference/androidx/room/TransactionScope#rollback(kotlin.Any)`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/room/Transactor#withTransaction(androidx.room.Transactor.SQLiteTransactionType,kotlin.coroutines.SuspendFunction1)` |   |
| `https://developer.android.com/reference/androidx/room/TransactionScope#withNestedTransaction(kotlin.coroutines.SuspendFunction1)` |   |

### withNestedTransaction

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

Begins a nested transaction and runs the `https://developer.android.com/reference/androidx/room/TransactionScope#withNestedTransaction(kotlin.coroutines.SuspendFunction1)` within the transaction. If `https://developer.android.com/reference/androidx/room/TransactionScope#withNestedTransaction(kotlin.coroutines.SuspendFunction1)` fails to complete normally i.e., an exception is thrown, or `https://developer.android.com/reference/androidx/room/TransactionScope#rollback(kotlin.Any)` 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](https://www.sqlite.org/lang_savepoint.html)

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/TransactionScope<@https://developer.android.com/reference/androidx/annotation/NonNull R>, @https://developer.android.com/reference/androidx/annotation/NonNull R> block` | The code that will execute within the transaction. |