# Transactor

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

*** ** * ** ***


```
public interface Transactor extends PooledConnection
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/room3/PooledConnection` that can perform transactions.

## Summary

| ### Nested types |
|---|
| `public enum https://developer.android.com/reference/androidx/room3/Transactor.SQLiteTransactionType extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/Transactor.SQLiteTransactionType>` Transaction types. |

| ### Public methods |
|---|---|
| `abstract boolean` | `https://developer.android.com/reference/androidx/room3/Transactor#inTransaction()()` Returns true if this connection has an active transaction, otherwise false. |
| `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/room3/Transactor#withTransaction(androidx.room3.Transactor.SQLiteTransactionType,kotlin.coroutines.SuspendFunction1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/Transactor.SQLiteTransactionType type, @https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/TransactionScope<@https://developer.android.com/reference/androidx/annotation/NonNull R>, @https://developer.android.com/reference/androidx/annotation/NonNull R> block )` Begins a transaction and runs the `https://developer.android.com/reference/androidx/room3/Transactor#withTransaction(androidx.room3.Transactor.SQLiteTransactionType,kotlin.coroutines.SuspendFunction1)` within the transaction. |

### Inherited methods

From [androidx.room3.PooledConnection](https://developer.android.com/reference/androidx/room3/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/room3/PooledConnection#usePrepared(kotlin.String,kotlin.coroutines.SuspendFunction1)(
@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 SuspendFunction1<@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/room3/PooledConnection#usePrepared(kotlin.String,kotlin.coroutines.SuspendFunction1)`.

## 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,
    @NonNull SuspendFunction1<@NonNull TransactionScope<@NonNull R>, @NonNull R> block
)
```

Begins a transaction and runs the `https://developer.android.com/reference/androidx/room3/Transactor#withTransaction(androidx.room3.Transactor.SQLiteTransactionType,kotlin.coroutines.SuspendFunction1)` within the transaction. If `https://developer.android.com/reference/androidx/room3/Transactor#withTransaction(androidx.room3.Transactor.SQLiteTransactionType,kotlin.coroutines.SuspendFunction1)` fails to complete normally i.e. an exception is thrown, or `https://developer.android.com/reference/androidx/room3/TransactionScope#rollback(kotlin.Any)` is invoked then the transaction will be rollback, otherwise it is committed.

If `https://developer.android.com/reference/androidx/room3/Transactor#inTransaction()` returns `true` and this function is invoked it is the equivalent of starting a nested transaction as if `https://developer.android.com/reference/androidx/room3/TransactionScope#withNestedTransaction(kotlin.coroutines.SuspendFunction1)` was invoked and the `https://developer.android.com/reference/androidx/room3/Transactor#withTransaction(androidx.room3.Transactor.SQLiteTransactionType,kotlin.coroutines.SuspendFunction1)` of the transaction will be ignored since its type will be inherited from the parent transaction.

See also [Transaction](https://www.sqlite.org/lang_transaction.html)

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/Transactor.SQLiteTransactionType type` | The type of transaction to begin. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/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. |