RoomDatabase.Builder

public static class RoomDatabase.Builder
extends Object

java.lang.Object
   ↳ androidx.room.RoomDatabase.Builder<T extends androidx.room.RoomDatabase>


Builder for RoomDatabase.

Summary

Public methods

Builder<T> addAutoMigrationSpec(AutoMigrationSpec autoMigrationSpec)

Adds an auto migration spec to the builder.

Builder<T> addCallback(RoomDatabase.Callback callback)

Adds a RoomDatabase.Callback to this database.

Builder<T> addMigrations(Migration... migrations)

Adds a migration to the builder.

Builder<T> addTypeConverter(Object typeConverter)

Adds a type converter instance to this database.

Builder<T> allowMainThreadQueries()

Disables the main thread query check for Room.

T build()

Creates the databases and initializes it.

Builder<T> createFromAsset(String databaseFilePath, RoomDatabase.PrepackagedDatabaseCallback callback)

Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder.

Builder<T> createFromAsset(String databaseFilePath)

Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder.

Builder<T> createFromFile(File databaseFile)

Configures Room to create and open the database using a pre-packaged database file.

Builder<T> createFromFile(File databaseFile, RoomDatabase.PrepackagedDatabaseCallback callback)

Configures Room to create and open the database using a pre-packaged database file.

Builder<T> createFromInputStream(Callable<InputStream> inputStreamCallable, RoomDatabase.PrepackagedDatabaseCallback callback)

Configures Room to create and open the database using a pre-packaged database via an InputStream.

Builder<T> createFromInputStream(Callable<InputStream> inputStreamCallable)

Configures Room to create and open the database using a pre-packaged database via an InputStream.

Builder<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.

Builder<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.

Builder<T> fallbackToDestructiveMigrationFrom(int... startVersions)

Informs Room that it is allowed to destructively recreate database tables from specific starting schema versions.

Builder<T> fallbackToDestructiveMigrationOnDowngrade()

Allows Room to destructively recreate database tables if Migrations are not available when downgrading to old schema versions.

Builder<T> openHelperFactory(SupportSQLiteOpenHelper.Factory factory)

Sets the database factory.

Builder<T> setAutoCloseTimeout(long autoCloseTimeout, TimeUnit autoCloseTimeUnit)

Enables auto-closing for the database to free up unused resources.

Builder<T> setJournalMode(RoomDatabase.JournalMode journalMode)

Sets the journal mode for this database.

Builder<T> setMultiInstanceInvalidationServiceIntent(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.

Builder<T> setQueryCallback(RoomDatabase.QueryCallback queryCallback, Executor executor)

Sets a RoomDatabase.QueryCallback to be invoked when queries are executed.

Builder<T> setQueryExecutor(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.

Builder<T> setTransactionExecutor(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.

Inherited methods

Public methods

addAutoMigrationSpec

public Builder<T> addAutoMigrationSpec (AutoMigrationSpec autoMigrationSpec)

Adds an auto migration spec to the builder.

Pa