# RoomDatabase

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

*** ** * ** ***


```
public abstract class RoomDatabase
```

<br />

*** ** * ** ***

Base class for all Room databases. All classes that are annotated with `https://developer.android.com/reference/androidx/room/Database` must extend this class.

RoomDatabase provides direct access to the underlying database implementation but you should prefer using `https://developer.android.com/reference/androidx/room/Dao` classes.

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

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<T extends https://developer.android.com/reference/androidx/room/RoomDatabase>` Builder for `https://developer.android.com/reference/androidx/room/RoomDatabase`. |
| `public abstract class https://developer.android.com/reference/androidx/room/RoomDatabase.Callback` Callback for `https://developer.android.com/reference/androidx/room/RoomDatabase` |
| `public enum https://developer.android.com/reference/androidx/room/RoomDatabase.JournalMode extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.JournalMode>` Journal modes for SQLite database. |
| `public final class https://developer.android.com/reference/androidx/room/RoomDatabase.MigrationContainer` A container to hold migrations. |
| `public abstract class https://developer.android.com/reference/androidx/room/RoomDatabase.PrepackagedDatabaseCallback` Callback for `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromAsset(kotlin.String)`, `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromFile(java.io.File)` and `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromInputStream(java.util.concurrent.Callable)` |
| `public fun interface https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback` Callback interface for when SQLite queries are executed. |

| ### Protected fields |
|---|---|
| `final https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` | `https://developer.android.com/reference/androidx/room/RoomDatabase#mDatabase()` **This field is deprecated.** This property is always null and will be removed in a future version. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/room/RoomDatabase#RoomDatabase()()` You cannot create an instance of a database, instead, you should acquire it via #Room.databaseBuilder or #Room.inMemoryDatabaseBuilder. |
| `https://developer.android.com/reference/androidx/room/RoomDatabase#RoomDatabase()()` |

| ### Public methods |
|---|---|
| `void` | `[beginTransaction](https://developer.android.com/reference/androidx/room/RoomDatabase#beginTransaction())()` **This method is deprecated.** beginTransaction() is deprecated |
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/room/RoomDatabase#clearAllTables()()` Deletes all rows from all the tables that are registered to this database as `https://developer.android.com/reference/androidx/room/Database#entities()`. |
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase#close()()` Closes the database. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteStatement` | `https://developer.android.com/reference/androidx/room/RoomDatabase#compileStatement(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sql)` Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#compileStatement(kotlin.String)`. |
| `void` | `[endTransaction](https://developer.android.com/reference/androidx/room/RoomDatabase#endTransaction())()` **This method is deprecated.** endTransaction() is deprecated |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/InvalidationTracker` | `https://developer.android.com/reference/androidx/room/RoomDatabase#getInvalidationTracker()()` The invalidation tracker for this database. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper` | `https://developer.android.com/reference/androidx/room/RoomDatabase#getOpenHelper()()` The SQLite open helper used by this database. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/androidx/room/RoomDatabase#getQueryExecutor()()` The Executor in use by this database for async queries. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/androidx/room/RoomDatabase#getTransactionExecutor()()` The Executor in use by this database for async transactions. |
| `T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> [getTypeConverter](https://developer.android.com/reference/androidx/room/RoomDatabase#getTypeConverter(java.lang.Class))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> klass)` **This method is deprecated.** No longer called by generated implementation |
| `boolean` | `https://developer.android.com/reference/androidx/room/RoomDatabase#inTransaction()()` Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#inTransaction()`. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/CallSuper https://developer.android.com/reference/androidx/room/RoomDatabase#init(androidx.room.DatabaseConfiguration)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/DatabaseConfiguration configuration)` Called by Room when it is initialized. |
| `boolean` | `https://developer.android.com/reference/androidx/room/RoomDatabase#isOpen()()` True if database connection is open and initialized. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/Cursor.html` | `https://developer.android.com/reference/androidx/room/RoomDatabase#query(kotlin.String,kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html query, Object[] args)` Convenience method to query the database with arguments. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/Cursor.html` | `https://developer.android.com/reference/androidx/room/RoomDatabase#query(androidx.sqlite.db.SupportSQLiteQuery,android.os.CancellationSignal)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteQuery query, https://developer.android.com/reference/android/os/CancellationSignal.html signal)` Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#query(kotlin.String)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull V` | `<V extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/room/RoomDatabase#runInTransaction(java.util.concurrent.Callable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull V> body)` Executes the specified `https://developer.android.com/reference/java/util/concurrent/Callable.html` in a database transaction. |
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase#runInTransaction(java.lang.Runnable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html body)` Executes the specified `https://developer.android.com/reference/java/lang/Runnable.html` in a database transaction. |
| `void` | `[setTransactionSuccessful](https://developer.android.com/reference/androidx/room/RoomDatabase#setTransactionSuccessful())()` **This method is deprecated.** setTransactionSuccessful() is deprecated |

| ### Protected methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/InvalidationTracker` | `https://developer.android.com/reference/androidx/room/RoomDatabase#createInvalidationTracker()()` Creates the invalidation tracker |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper` | `[createOpenHelper](https://developer.android.com/reference/androidx/room/RoomDatabase#createOpenHelper(androidx.room.DatabaseConfiguration))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/DatabaseConfiguration config)` **This method is deprecated.** No longer implemented by generated |
| `void` | `[internalInitInvalidationTracker](https://developer.android.com/reference/androidx/room/RoomDatabase#internalInitInvalidationTracker(androidx.sqlite.db.SupportSQLiteDatabase))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase db)` **This method is deprecated.** No longer called by generated |

| ### Extension functions |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html>>` | `https://developer.android.com/reference/androidx/room/RoomDatabaseKt.[invalidationTrackerFlow](https://developer.android.com/reference/androidx/room/RoomDatabase#(androidx.room.RoomDatabase).invalidationTrackerFlow(kotlin.Array,kotlin.Boolean))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... tables, boolean emitInitialState )` **This method is deprecated.** Replaced by equivalent API in InvalidationTracker. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` | `https://developer.android.com/reference/androidx/room/RoomSupportSQLite.https://developer.android.com/reference/androidx/room/RoomDatabase#(androidx.room.RoomDatabase).getSupportWrapper()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase receiver)` Gets a new `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` implementation that is backed by a `https://developer.android.com/reference/androidx/room/RoomDatabase` for compatibility with existing usages of `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase`. |

## Protected fields

### mDatabase

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

```
protected final SupportSQLiteDatabase mDatabase
```

> [!CAUTION]
> **This field is deprecated.**   
> This property is always null and will be removed in a future version.

## Public constructors

### RoomDatabase

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public RoomDatabase()
```

You cannot create an instance of a database, instead, you should acquire it via #Room.databaseBuilder or #Room.inMemoryDatabaseBuilder.

### RoomDatabase

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public RoomDatabase()
```

## Public methods

### beginTransaction

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

```
public void [beginTransaction](https://developer.android.com/reference/androidx/room/RoomDatabase#beginTransaction())()
```

> [!CAUTION]
> **This method is deprecated.**   
> beginTransaction() is deprecated, use this instead:
>
> ```
> runInTransaction(Runnable)
> ```

Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#beginTransaction()`.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

### clearAllTables

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
@WorkerThread
public abstract void clearAllTables()
```

Deletes all rows from all the tables that are registered to this database as `https://developer.android.com/reference/androidx/room/Database#entities()`.

This does NOT reset the auto-increment value generated by `https://developer.android.com/reference/androidx/room/PrimaryKey#autoGenerate()`.

After deleting the rows, Room will set a WAL checkpoint and run VACUUM. This means that the data is completely erased. The space will be reclaimed by the system if the amount surpasses the threshold of database file size.

See SQLite documentation for details. [FileFormat](https://www.sqlite.org/fileformat.html)

### close

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public void close()
```

Closes the database.

Once a `https://developer.android.com/reference/androidx/room/RoomDatabase` is closed it should no longer be used.

### compileStatement

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull SupportSQLiteStatement compileStatement(@NonNull String sql)
```

Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#compileStatement(kotlin.String)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sql` | The query to compile. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteStatement` | The compiled query. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

### endTransaction

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

```
public void [endTransaction](https://developer.android.com/reference/androidx/room/RoomDatabase#endTransaction())()
```

> [!CAUTION]
> **This method is deprecated.**   
> endTransaction() is deprecated, use this instead:
>
> ```
> runInTransaction(Runnable)
> ```

Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#endTransaction()`.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

### getInvalidationTracker

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull InvalidationTracker getInvalidationTracker()
```

The invalidation tracker for this database.

You can use the invalidation tracker to get notified when certain tables in the database are modified.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/InvalidationTracker` | The invalidation tracker for the database. |

### getOpenHelper

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull SupportSQLiteOpenHelper getOpenHelper()
```

The SQLite open helper used by this database.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

### getQueryExecutor

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull Executor getQueryExecutor()
```

The Executor in use by this database for async queries.

### getTransactionExecutor

Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

```
public @NonNull Executor getTransactionExecutor()
```

The Executor in use by this database for async transactions.

### getTypeConverter

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0) Deprecated in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public T <T extends Object> [getTypeConverter](https://developer.android.com/reference/androidx/room/RoomDatabase#getTypeConverter(java.lang.Class))(@NonNull Class<@NonNull T> klass)
```

> [!CAUTION]
> **This method is deprecated.**   
> No longer called by generated implementation

Gets the instance of the given Type Converter.

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | The type of the expected Type Converter subclass. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> klass` | The Type Converter class. |

| Returns |
|---|---|
| `T` | An instance of T if it is provided in the builder. |

### inTransaction

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public boolean inTransaction()
```

Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#inTransaction()`. Returns true if current thread is in a transaction.

| Returns |
|---|---|
| `boolean` | True if there is an active transaction in current thread, false otherwise. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#inTransaction()` |   |

### init

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
@CallSuper
public void init(@NonNull DatabaseConfiguration configuration)
```

Called by Room when it is initialized.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/DatabaseConfiguration configuration` | The database configuration. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if initialization fails. |

### isOpen

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public boolean isOpen()
```

True if database connection is open and initialized.

When Room is configured with `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setAutoCloseTimeout(kotlin.Long,java.util.concurrent.TimeUnit)` the database is considered open even if internally the connection has been closed, unless manually closed.

| Returns |
|---|---|
| `boolean` | true if the database connection is open, false otherwise. |

### query

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull Cursor query(@NonNull String query, Object[] args)
```

Convenience method to query the database with arguments.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html query` | The sql query |
| `Object[] args` | The bind arguments for the placeholders in the query |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/Cursor.html` | A Cursor obtained by running the given query in the Room database. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

### query

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/room#2.2.0)

```
public @NonNull Cursor query(@NonNull SupportSQLiteQuery query, CancellationSignal signal)
```

Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#query(kotlin.String)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteQuery query` | The Query which includes the SQL and a bind callback for bind arguments. |
| `https://developer.android.com/reference/android/os/CancellationSignal.html signal` | The cancellation signal to be attached to the query. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/Cursor.html` | Result of the query. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

### runInTransaction

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull V <V extends Object> runInTransaction(@NonNull Callable<@NonNull V> body)
```

Executes the specified `https://developer.android.com/reference/java/util/concurrent/Callable.html` in a database transaction. The transaction will be marked as successful unless an exception is thrown in the `https://developer.android.com/reference/java/util/concurrent/Callable.html`.

Room will only perform at most one transaction at a time.

If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database, then it is best to use `https://developer.android.com/reference/androidx/room/package-summary#(androidx.room.RoomDatabase).useWriterConnection(kotlin.coroutines.SuspendFunction1)` along with `https://developer.android.com/reference/androidx/room/package-summary#(androidx.room.Transactor).immediateTransaction(kotlin.coroutines.SuspendFunction1)` to perform transactional operations.

| Parameters |
|---|---|
| `<V extends https://developer.android.com/reference/java/lang/Object.html>` | The type of the return value. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull V> body` | The piece of code to execute. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull V` | The value returned from the `https://developer.android.com/reference/java/util/concurrent/Callable.html`. |

### runInTransaction

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public void runInTransaction(@NonNull Runnable body)
```

Executes the specified `https://developer.android.com/reference/java/lang/Runnable.html` in a database transaction. The transaction will be marked as successful unless an exception is thrown in the `https://developer.android.com/reference/java/lang/Runnable.html`.

Room will only perform at most one transaction at a time.

If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database, then it is best to use `https://developer.android.com/reference/androidx/room/package-summary#(androidx.room.RoomDatabase).useWriterConnection(kotlin.coroutines.SuspendFunction1)` along with `https://developer.android.com/reference/androidx/room/package-summary#(androidx.room.Transactor).immediateTransaction(kotlin.coroutines.SuspendFunction1)` to perform transactional operations.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html body` | The piece of code to execute. |

### setTransactionSuccessful

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

```
public void [setTransactionSuccessful](https://developer.android.com/reference/androidx/room/RoomDatabase#setTransactionSuccessful())()
```

> [!CAUTION]
> **This method is deprecated.**   
> setTransactionSuccessful() is deprecated, use this instead:
>
> ```
> runInTransaction(Runnable)
> ```

Wrapper for `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase#setTransactionSuccessful()`.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If a `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` is configured with this database. |

## Protected methods

### createInvalidationTracker

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
protected abstract @NonNull InvalidationTracker createInvalidationTracker()
```

Creates the invalidation tracker

An implementation of this function is generated by the Room processor. Note that this function is called when the `https://developer.android.com/reference/androidx/room/RoomDatabase` is initialized.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/InvalidationTracker` | A new invalidation tracker. |

### createOpenHelper

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
protected @NonNull SupportSQLiteOpenHelper [createOpenHelper](https://developer.android.com/reference/androidx/room/RoomDatabase#createOpenHelper(androidx.room.DatabaseConfiguration))(@NonNull DatabaseConfiguration config)
```

> [!CAUTION]
> **This method is deprecated.**   
> No longer implemented by generated

Creates the open helper to access the database. Generated class already implements this method. Note that this method is called when the RoomDatabase is initialized.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/DatabaseConfiguration config` | The configuration of the Room database. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper` | A new SupportSQLiteOpenHelper to be used while connecting to the database. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-not-implemented-error/index.html` | by default |

### internalInitInvalidationTracker

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
protected void [internalInitInvalidationTracker](https://developer.android.com/reference/androidx/room/RoomDatabase#internalInitInvalidationTracker(androidx.sqlite.db.SupportSQLiteDatabase))(@NonNull SupportSQLiteDatabase db)
```

> [!CAUTION]
> **This method is deprecated.**   
> No longer called by generated

Initialize invalidation tracker. Note that this method is called when the `https://developer.android.com/reference/androidx/room/RoomDatabase` is initialized and opens a database connection.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase db` | The database instance. |

## Extension functions

### RoomDatabaseKt.invalidationTrackerFlow

Artifact: [androidx.room:room-runtime](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/RoomDatabase.android.kt+function:invalidationTrackerFlow)

```
public final @NonNull Flow<@NonNull Set<@NonNull String>> RoomDatabaseKt.[invalidationTrackerFlow](https://developer.android.com/reference/androidx/room/RoomDatabase#(androidx.room.RoomDatabase).invalidationTrackerFlow(kotlin.Array,kotlin.Boolean))(
    @NonNull RoomDatabase receiver,
    @NonNull String... tables,
    boolean emitInitialState
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Replaced by equivalent API in InvalidationTracker, use this instead:
>
> ```
> this.invalidationTracker.createFlow(*tables)
> ```

Creates a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` that listens for changes in the database via the `https://developer.android.com/reference/androidx/room/InvalidationTracker` and emits sets of the tables that were invalidated.

The Flow will emit at least one value, a set of all the tables registered for observation to kick-start the stream unless `https://developer.android.com/reference/androidx/room/package-summary#(androidx.room.RoomDatabase).invalidationTrackerFlow(kotlin.Array,kotlin.Boolean)` is set to `false`.

If one of the tables to observe does not exist in the database, this functions throws an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

The returned Flow can be used to create a stream that reacts to changes in the database:

```
fun getArtistTours(from: Date, to: Date): Flow<Map<Artist, TourState>> {
  return db.invalidationTrackerFlow("Artist").map { _ ->
    val artists = artistsDao.getAllArtists()
    val tours = tourService.fetchStates(artists.map { it.id })
    associateTours(artists, tours, from, to)
  }
}
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html... tables` | The name of the tables or views to observe. |
| `boolean emitInitialState` | Set to `false` if no initial emission is desired. Default value is `true`. |

### RoomSupportSQLite.getSupportWrapper

Artifact: [androidx.room:room-sqlite-wrapper](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/support/RoomSupportSQLite.kt+function:getSupportWrapper)

```
public final @NonNull SupportSQLiteDatabase RoomSupportSQLite.getSupportWrapper(@NonNull RoomDatabase receiver)
```

Gets a new `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase` implementation that is backed by a `https://developer.android.com/reference/androidx/room/RoomDatabase` for compatibility with existing usages of `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase`.