RoomDatabase.Builder
public final class RoomDatabase.Builder<T extends RoomDatabase>
Builder for RoomDatabase.
| Parameters | |
|---|---|
<T extends RoomDatabase> |
The type of the abstract database class. |
Summary
Public methods |
|
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
addAutoMigrationSpec(@NonNull AutoMigrationSpec autoMigrationSpec)Adds an auto migration spec instance to the builder. |
@NonNull RoomDatabase.Builder<@NonNull T> |
addCallback(@NonNull RoomDatabase.Callback callback)Adds a |
@NonNull RoomDatabase.Builder<@NonNull T> |
addMigrations(@NonNull Migration... migrations)Adds a migration to the builder. |
@NonNull RoomDatabase.Builder<@NonNull T> |
addTypeConverter(@NonNull Object typeConverter)Adds a type converter instance to the builder. |
@NonNull RoomDatabase.Builder<@NonNull T> |
Disables the main thread query check for Room. |
@NonNull T |
build()Creates the database and initializes it. |
@NonNull RoomDatabase.Builder<@NonNull T> |
createFromAsset(@NonNull String databaseFilePath)Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder. |
@NonNull RoomDatabase.Builder<@NonNull T> |
createFromAsset(Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder. |
@NonNull RoomDatabase.Builder<@NonNull T> |
createFromFile(@NonNull File databaseFile)Configures Room to create and open the database using a pre-packaged database file. |
@NonNull RoomDatabase.Builder<@NonNull T> |
createFromFile(Configures Room to create and open the database using a pre-packaged database file. |
@NonNull RoomDatabase.Builder<@NonNull T> |
createFromInputStream(Configures Room to create and open the database using a pre-packaged database via an |
@NonNull RoomDatabase.Builder<@NonNull T> |
createFromInputStream(Configures Room to create and open the database using a pre-packaged database via an |
@NonNull RoomDatabase.Builder<@NonNull T> |
Sets whether table invalidation in this instance of |
@NonNull RoomDatabase.Builder<@NonNull T> |
This method is deprecated. Replace by overloaded version with parameter to indicate if all tables should be dropped or not. |
final @NonNull RoomDatabase.Builder<@NonNull T> |
fallbackToDestructiveMigration(boolean dropAllTables)Allows Room to destructively recreate database tables if |
@NonNull RoomDatabase.Builder<@NonNull T> |
This method is deprecated. Replace by overloaded version with parameter to indicate if all tables should be dropped or not. |
@NonNull RoomDatabase.Builder<@NonNull T> |
fallbackToDestructiveMigrationFrom(Informs Room that it is allowed to destructively recreate database tables from specific starting schema versions. |
@NonNull RoomDatabase.Builder<@NonNull T> |
This method is deprecated. Replace by overloaded version with parameter to indicate if all tables should be dropped or not. |
final @NonNull RoomDatabase.Builder<@NonNull T> |
fallbackToDestructiveMigrationOnDowngrade(boolean dropAllTables)Allows Room to destructively recreate database tables if |
@NonNull RoomDatabase.Builder<@NonNull T> |
Sets the database factory. |
@NonNull RoomDatabase.Builder<@NonNull T> |
@ExperimentalRoomApiEnables auto-closing for the database to free up unused resources. |
final @NonNull RoomDatabase.Builder<@NonNull T> |
setDriver(@NonNull SQLiteDriver driver)Sets the |
final @NonNull RoomDatabase.Builder<@NonNull T> |
@ExperimentalRoomApiSets whether Room will use an in-memory table or a persisted table to track invalidation. |
@NonNull RoomDatabase.Builder<@NonNull T> |
setJournalMode(@NonNull RoomDatabase.JournalMode journalMode)Sets the journal mode for this database. |
@NonNull RoomDatabase.Builder<@NonNull T> |
@ExperimentalRoomApiSets whether table invalidation in this instance of |
final @NonNull RoomDatabase.Builder<@NonNull T> |
setQueryCallback(Sets a |
@NonNull RoomDatabase.Builder<@NonNull T> |
setQueryCallback(Sets a |
final @NonNull RoomDatabase.Builder<@NonNull T> |
setQueryCoroutineContext(@NonNull CoroutineContext context)Sets the |
@NonNull RoomDatabase.Builder<@NonNull T> |
setQueryExecutor(@NonNull Executor executor)Sets the |
@NonNull RoomDatabase.Builder<@NonNull T> |
setTransactionExecutor(@NonNull Executor executor)Sets the |
Public methods
addAutoMigrationSpec
public @NonNull RoomDatabase.Builder<@NonNull T> addAutoMigrationSpec(@NonNull AutoMigrationSpec autoMigrationSpec)
Adds an auto migration spec instance to the builder.
| Parameters | |
|---|---|
@NonNull AutoMigrationSpec autoMigrationSpec |
The auto migration object that is annotated with |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
addCallback
public @NonNull RoomDatabase.Builder<@NonNull T> addCallback(@NonNull RoomDatabase.Callback callback)
Adds a Callback to this database.
| Parameters | |
|---|---|
@NonNull RoomDatabase.Callback callback |
The callback. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
addMigrations
public @NonNull RoomDatabase.Builder<@NonNull T> addMigrations(@NonNull Migration... migrations)
Adds a migration to the builder.
Each Migration has a start and end versions and Room runs these migrations to bring the database to the latest version.
A migration can handle more than 1 version (e.g. if you have a faster path to choose when going from version 3 to 5 without going to version 4). If Room opens a database at version 3 and latest version is >= 5, Room will use the migration object that can migrate from 3 to 5 instead of 3 to 4 and 4 to 5.
| Parameters | |
|---|---|
@NonNull Migration... migrations |
The migration objects that modify the database schema with the necessary changes for a version change. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
addTypeConverter
public @NonNull RoomDatabase.Builder<@NonNull T> addTypeConverter(@NonNull Object typeConverter)
Adds a type converter instance to the builder.
| Parameters | |
|---|---|
@NonNull Object typeConverter |
The converter instance that is annotated with |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
allowMainThreadQueries
public @NonNull RoomDatabase.Builder<@NonNull T> allowMainThreadQueries()
Disables the main thread query check for Room.
Room ensures that Database is never accessed on the main thread because it may lock the main thread and trigger an ANR. If you need to access the database from the main thread, you should always use async alternatives or manually move the call to a background thread.
You may want to turn this check off for testing.
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
build
public @NonNull T build()
Creates the database and initializes it.
| Returns | |
|---|---|
@NonNull T |
A new database instance. |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the builder was misconfigured. |
createFromAsset
public @NonNull RoomDatabase.Builder<@NonNull T> createFromAsset(@NonNull String databaseFilePath)
Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder.
Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The pre-packaged database file must be located in the "assets/" folder of your application. For example, the path for a file located in "assets/databases/products.db" would be "databases/products.db".
The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when Database.exportSchema is enabled.
This method is not supported for an in memory database Builder.
| Parameters | |
|---|---|
@NonNull String databaseFilePath |
The file path within the 'assets/' directory of where the database file is located. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
createFromAsset
public @NonNull RoomDatabase.Builder<@NonNull T> createFromAsset(
@NonNull String databaseFilePath,
@NonNull RoomDatabase.PrepackagedDatabaseCallback callback
)
Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder.
Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The pre-packaged database file must be located in the "assets/" folder of your application. For example, the path for a file located in "assets/databases/products.db" would be "databases/products.db".
The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when Database.exportSchema is enabled.
This method is not supported for an in memory database Builder.
| Parameters | |
|---|---|
@NonNull String databaseFilePath |
The file path within the 'assets/' directory of where the database file is located. |
@NonNull RoomDatabase.PrepackagedDatabaseCallback callback |
The pre-packaged callback. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
createFromFile
public @NonNull RoomDatabase.Builder<@NonNull T> createFromFile(@NonNull File databaseFile)
Configures Room to create and open the database using a pre-packaged database file.
Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The given file must be accessible and the right permissions must be granted for Room to copy the file.
The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when Database.exportSchema is enabled.
The Callback.onOpen method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.
This method is not supported for an in memory database Builder.
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
createFromFile
public @NonNull RoomDatabase.Builder<@NonNull T> createFromFile(
@NonNull File databaseFile,
@NonNull RoomDatabase.PrepackagedDatabaseCallback callback
)
Configures Room to create and open the database using a pre-packaged database file.
Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The given file must be accessible and the right permissions must be granted for Room to copy the file.
The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when Database.exportSchema is enabled.
The Callback.onOpen method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.
This method is not supported for an in memory database Builder.
| Parameters | |
|---|---|
@NonNull File databaseFile |
The database file. |
@NonNull RoomDatabase.PrepackagedDatabaseCallback callback |
The pre-packaged callback. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
createFromInputStream
public @NonNull RoomDatabase.Builder<@NonNull T> createFromInputStream(
@NonNull Callable<@NonNull InputStream> inputStreamCallable
)
Configures Room to create and open the database using a pre-packaged database via an InputStream.
This is useful for processing compressed database files. Room does not open the pre-packaged database, instead it copies it into the internal app database folder, and then open it. The InputStream will be closed once Room is done consuming it.
The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when Database.exportSchema is enabled.
The Callback.onOpen method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.
This method is not supported for an in memory database Builder.
| Parameters | |
|---|---|
@NonNull Callable<@NonNull InputStream> inputStreamCallable |
A callable that returns an InputStream from which to copy the database. The callable will be invoked in a thread from the Executor set via |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
createFromInputStream
public @NonNull RoomDatabase.Builder<@NonNull T> createFromInputStream(
@NonNull Callable<@NonNull InputStream> inputStreamCallable,
@NonNull RoomDatabase.PrepackagedDatabaseCallback callback
)
Configures Room to create and open the database using a pre-packaged database via an InputStream.
This is useful for processing compressed database files. Room does not open the pre-packaged database, instead it copies it into the internal app database folder, and then open it. The InputStream will be closed once Room is done consuming it.
The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when Database.exportSchema is enabled.
The Callback.onOpen method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.
This method is not supported for an in memory database Builder.
| Parameters | |
|---|---|
@NonNull Callable<@NonNull InputStream> inputStreamCallable |
A callable that returns an InputStream from which to copy the database. The callable will be invoked in a thread from the Executor set via |
@NonNull RoomDatabase.PrepackagedDatabaseCallback callback |
The pre-packaged callback. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
enableMultiInstanceInvalidation
public @NonNull RoomDatabase.Builder<@NonNull T> enableMultiInstanceInvalidation()
Sets whether table invalidation in this instance of RoomDatabase should be broadcast and synchronized with other instances of the same RoomDatabase, including those in a separate process. In order to enable multi-instance invalidation, this has to be turned on both ends.
This is not enabled by default.
This does not work for in-memory databases. This does not work between database instances targeting different database files.
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
public @NonNull RoomDatabase.Builder<@NonNull T>fallbackToDestructiveMigration()
Allows Room to destructively recreate database tables if Migrations that would migrate old database schemas to the latest schema version are not found.
When the database version on the device does not match the latest schema version, Room runs necessary Migrations on the database.
If it cannot find the set of Migrations that will bring the database to the current version, it will throw an IllegalStateException.
You can call this method to change this behavior to re-create the database tables instead of crashing.
If the database was create from an asset or a file then Room will try to use the same file to re-create the database, otherwise this will delete all of the data in the database tables managed by Room.
To let Room fallback to destructive migration only during a schema downgrade then use fallbackToDestructiveMigrationOnDowngrade.
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
fallbackToDestructiveMigration
public final @NonNull RoomDatabase.Builder<@NonNull T> fallbackToDestructiveMigration(boolean dropAllTables)
Allows Room to destructively recreate database tables if Migrations that would migrate old database schemas to the latest schema version are not found.
When the database version on the device does not match the latest schema version, Room runs necessary Migrations on the database. If it cannot find the set of Migrations that will bring the database to the current version, it will throw an IllegalStateException. You can call this method to change this behavior to re-create the database tables instead of crashing.
To let Room fallback to destructive migration only during a schema downgrade then use fallbackToDestructiveMigrationOnDowngrade.
| Parameters | |
|---|---|
boolean dropAllTables |
Set to |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
public @NonNull RoomDatabase.Builder<@NonNull T>fallbackToDestructiveMigrationFrom(int... startVersions)
Informs Room that it is allowed to destructively recreate database tables from specific starting schema versions.
This functionality is the same as that provided by fallbackToDestructiveMigration, except that this method allows the specification of a set of schema versions for which destructive recreation is allowed.
Using this method is preferable to fallbackToDestructiveMigration if you want to allow destructive migrations from some schema versions while still taking advantage of exceptions being thrown due to unintentionally missing migrations.
Note: No versions passed to this method may also exist as either starting or ending versions in the Migrations provided to addMigrations. If a version passed to this method is found as a starting or ending version in a Migration, an exception will be thrown.
| Parameters | |
|---|---|
int... startVersions |
The set of schema versions from which Room should use a destructive migration. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
fallbackToDestructiveMigrationFrom
public @NonNull RoomDatabase.Builder<@NonNull T> fallbackToDestructiveMigrationFrom(
boolean dropAllTables,
int... startVersions
)
Informs Room that it is allowed to destructively recreate database tables from specific starting schema versions.
This functionality is the same fallbackToDestructiveMigration, except that this method allows the specification of a set of schema versions for which destructive recreation is allowed.
Using this method is preferable to fallbackToDestructiveMigration if you want to allow destructive migrations from some schema versions while still taking advantage of exceptions being thrown due to unintentionally missing migrations.
Note: No versions passed to this method may also exist as either starting or ending versions in the Migrations provided via addMigrations. If a version passed to this method is found as a starting or ending version in a Migration, an exception will be thrown.
| Parameters | |
|---|---|
boolean dropAllTables |
Set to |
int... startVersions |
The set of schema versions from which Room should use a destructive migration. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
public @NonNull RoomDatabase.Builder<@NonNull T>fallbackToDestructiveMigrationOnDowngrade()
Allows Room to destructively recreate database tables if Migrations are not available when downgrading to old schema versions.
For details, see Builder.fallbackToDestructiveMigration.
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
fallbackToDestructiveMigrationOnDowngrade
public final @NonNull RoomDatabase.Builder<@NonNull T> fallbackToDestructiveMigrationOnDowngrade(boolean dropAllTables)
Allows Room to destructively recreate database tables if Migrations are not available when downgrading to old schema versions.
For details, see Builder.fallbackToDestructiveMigration.
| Parameters | |
|---|---|
boolean dropAllTables |
Set to |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
openHelperFactory
public @NonNull RoomDatabase.Builder<@NonNull T> openHelperFactory(SupportSQLiteOpenHelper.Factory factory)
Sets the database factory. If not set, it defaults to FrameworkSQLiteOpenHelperFactory.
| Parameters | |
|---|---|
SupportSQLiteOpenHelper.Factory factory |
The factory to use to access the database. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
setAutoCloseTimeout
@ExperimentalRoomApi
public @NonNull RoomDatabase.Builder<@NonNull T> setAutoCloseTimeout(
@IntRange(from = 0) long autoCloseTimeout,
@NonNull TimeUnit autoCloseTimeUnit
)
Enables auto-closing for the database to free up unused resources. The underlying database will be closed after it's last use after the specified autoCloseTimeout has elapsed since its last usage. The database will be automatically re-opened the next time it is accessed.
Auto-closing is not compatible with in-memory databases since the data will be lost when the database is auto-closed.
Also, temp tables and temp triggers will be cleared each time the database is auto-closed. If you need to use them, please include them in your callback RoomDatabase.Callback.onOpen.
All configuration should happen in your RoomDatabase.Callback.onOpen callback so it is re-applied every time the database is re-opened. Note that the RoomDatabase.Callback.onOpen will be called every time the database is re-opened.
The auto-closing database operation runs on the query executor.
The database will not be re-opened if the RoomDatabase or the SupportSqliteOpenHelper is closed manually (by calling RoomDatabase.close or SupportSQLiteOpenHelper.close. If the database is closed manually, you must create a new database using RoomDatabase.Builder.build.
| Parameters | |
|---|---|
@IntRange(from = 0) long autoCloseTimeout |
the amount of time after the last usage before closing the database. Must greater or equal to zero. |
@NonNull TimeUnit autoCloseTimeUnit |
the timeunit for autoCloseTimeout. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
setDriver
public final @NonNull RoomDatabase.Builder<@NonNull T> setDriver(@NonNull SQLiteDriver driver)
Sets the SQLiteDriver implementation to be used by Room to open database connections.
| Parameters | |
|---|---|
@NonNull SQLiteDriver driver |
The driver |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
setInMemoryTrackingMode
@ExperimentalRoomApi
public final @NonNull RoomDatabase.Builder<@NonNull T> setInMemoryTrackingMode(boolean inMemory)
Sets whether Room will use an in-memory table or a persisted table to track invalidation.
An in-memory table is used by default. Using an in-memory tables is more performant, reduces the journal file size but has an increased memory footprint, where as using a real table has the opposite effect.
| Parameters | |
|---|---|
boolean inMemory |
True if in-memory tables should be used, false otherwise. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This |
setJournalMode
public @NonNull RoomDatabase.Builder<@NonNull T> setJournalMode(@NonNull RoomDatabase.JournalMode journalMode)
Sets the journal mode for this database.
The value is ignored if the builder is for an 'in-memory database'. The journal mode should be consistent across multiple instances of RoomDatabase for a single SQLite database file.
The default value is JournalMode.WRITE_AHEAD_LOGGING.
| Parameters | |
|---|---|
@NonNull RoomDatabase.JournalMode journalMode |
The journal mode. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
setMultiInstanceInvalidationServiceIntent
@ExperimentalRoomApi
public @NonNull RoomDatabase.Builder<@NonNull T> setMultiInstanceInvalidationServiceIntent(
@NonNull Intent invalidationServiceIntent
)
Sets whether table invalidation in this instance of RoomDatabase should be broadcast and synchronized with other instances of the same RoomDatabase, including those in a separate process. In order to enable multi-instance invalidation, this has to be turned on both ends and need to point to the same MultiInstanceInvalidationService.
This is not enabled by default.
This does not work for in-memory databases. This does not work between database instances targeting different database files.
| Parameters | |
|---|---|
@NonNull Intent invalidationServiceIntent |
Intent to bind to the |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
setQueryCallback
public final @NonNull RoomDatabase.Builder<@NonNull T> setQueryCallback(
@NonNull CoroutineContext context,
@NonNull RoomDatabase.QueryCallback queryCallback
)
Sets a QueryCallback to be invoked when queries are executed.
The callback is invoked whenever a query is executed, note that adding this callback has a small cost and should be avoided in production builds unless needed.
A use case for providing a callback is to allow logging executed queries. When the callback implementation simply logs then it is recommended to use kotlinx.coroutines.Dispatchers.Unconfined.
If a previous callback was set with setQueryCallback then this call will override it, including removing the executor previously set, if any.
| Parameters | |
|---|---|
@NonNull CoroutineContext context |
The coroutine context on which the query callback will be invoked. |
@NonNull RoomDatabase.QueryCallback queryCallback |
The query callback. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
setQueryCallback
public @NonNull RoomDatabase.Builder<@NonNull T> setQueryCallback(
@NonNull RoomDatabase.QueryCallback queryCallback,
@NonNull Executor executor
)
Sets a QueryCallback to be invoked when queries are executed.
The callback is invoked whenever a query is executed, note that adding this callback has a small cost and should be avoided in production builds unless needed.
A use case for providing a callback is to allow logging executed queries. When the callback implementation logs then it is recommended to use an immediate executor.
If a previous callback was set with setQueryCallback then this call will override it, including removing the Coroutine context previously set, if any.
| Parameters | |
|---|---|
@NonNull RoomDatabase.QueryCallback queryCallback |
The query callback. |
@NonNull Executor executor |
The executor on which the query callback will be invoked. |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
setQueryCoroutineContext
public final @NonNull RoomDatabase.Builder<@NonNull T> setQueryCoroutineContext(@NonNull CoroutineContext context)
Sets the CoroutineContext that will be used to execute all asynchronous queries and tasks, such as Flow emissions and InvalidationTracker notifications.
If no CoroutineDispatcher is present in the context then this function will throw an IllegalArgumentException
| Parameters | |
|---|---|
@NonNull CoroutineContext context |
The context |
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if the |
setQueryExecutor
public @NonNull RoomDatabase.Builder<@NonNull T> setQueryExecutor(@NonNull Executor executor)
Sets the Executor that will be used to execute all non-blocking asynchronous queries and tasks, including LiveData invalidation, Flowable scheduling and ListenableFuture tasks.
When both the query executor and transaction executor are unset, then a default Executor will be used. The default Executor allocates and shares threads amongst Architecture Components libraries. If the query executor is unset but a transaction executor was set via setTransactionExecutor, then the same Executor will be used for queries.
For best performance the given Executor should be bounded (max number of threads is limited).
The input Executor cannot run tasks on the UI thread.
If either setQueryCoroutineContext has been called, then this function will throw an IllegalArgumentException.
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if this builder was already configured with a |
setTransactionExecutor
public @NonNull RoomDatabase.Builder<@NonNull T> setTransactionExecutor(@NonNull Executor executor)
Sets the Executor that will be used to execute all non-blocking asynchronous transaction queries and tasks, including LiveData invalidation, Flowable scheduling and ListenableFuture tasks.
When both the transaction executor and query executor are unset, then a default Executor will be used. The default Executor allocates and shares threads amongst Architecture Components libraries. If the transaction executor is unset but a query executor was set using setQueryExecutor, then the same Executor will be used for transactions.
If the given Executor is shared then it should be unbounded to avoid the possibility of a deadlock. Room will not use more than one thread at a time from this executor since only one transaction at a time can be executed, other transactions will be queued on a first come, first serve order.
The input Executor cannot run tasks on the UI thread.
If either setQueryCoroutineContext has been called, then this function will throw an IllegalArgumentException.
| Returns | |
|---|---|
@NonNull RoomDatabase.Builder<@NonNull T> |
This builder instance. |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if this builder was already configured with a |