RoomDatabase

public abstract class RoomDatabase
extends Object

java.lang.Object
   ↳ androidx.room.RoomDatabase


Base class for all Room databases. All classes that are annotated with Database must extend this class.

RoomDatabase provides direct access to the underlying database implementation but you should prefer using Dao classes.

See also:

Summary

Nested classes

class RoomDatabase.Builder<T extends RoomDatabase>

Builder for RoomDatabase. 

class RoomDatabase.Callback

Callback for RoomDatabase

enum RoomDatabase.JournalMode

Journal modes for SQLite database. 

class RoomDatabase.MigrationContainer

A container to hold migrations. 

class RoomDatabase.PrepackagedDatabaseCallback

Callback for RoomDatabase.Builder.createFromAsset(String), RoomDatabase.Builder.createFromFile(File) and RoomDatabase.Builder.createFromInputStream(Callable)

This callback will be invoked after the pre-package DB is copied but before Room had a chance to open it and therefore before the RoomDatabase.Callback methods are invoked. 

interface RoomDatabase.QueryCallback

Callback interface for when SQLite queries are executed. 

Fields

protected SupportSQLiteDatabase mDatabase

This field is deprecated. Will be hidden in the next release.

Public constructors

RoomDatabase()

Creates a RoomDatabase.

Public methods

void beginTransaction()

This method is deprecated. Use runInTransaction(Runnable)

abstract void clearAllTables()

Deletes all rows from all the tables that are registered to this database as Database.entities().

void close()

Closes the database if it is already open.

SupportSQLiteStatement compileStatement(String sql)

Wrapper for SupportSQLiteDatabase.compileStatement(String).

void endTransaction()

This method is deprecated. Use runInTransaction(Runnable)

InvalidationTracker getInvalidationTracker()

Returns the invalidation tracker for this database.

SupportSQLiteOpenHelper getOpenHelper()

Returns the SQLite open helper used by this database.

Executor getQueryExecutor()
Executor getTransactionExecutor()
<T> T getTypeConverter(Class<T> klass)

Gets the instance of the given Type Converter.

boolean inTransaction()

Returns true if current thread is in a transaction.

void init(DatabaseConfiguration configuration)

Called by Room when it is initialized.

boolean isOpen()

Returns true if database connection is open and initialized.

Cursor query(String query, Object[] args)

Convenience method to query the database with arguments.

Cursor query(SupportSQLiteQuery query, CancellationSignal signal)

Wrapper for SupportSQLiteDatabase.query(SupportSQLiteQuery).

Cursor query(SupportSQLiteQuery query)

Wrapper for SupportSQLiteDatabase.query(SupportSQLiteQuery).

<V> V runInTransaction(Callable<V> body)

Executes the specified Callable in a database transaction.

void runInTransaction(Runnable body)

Executes the specified Runnable in a database transaction.

void setTransactionSuccessful()

This method is deprecated. Use runInTransaction(Runnable)

Protected methods

abstract InvalidationTracker createInvalidationTracker()

Called when the RoomDatabase is created.

abstract SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config)

Creates the open helper to access the database.

Map<Class<?>, List<Class<?>>> getRequiredTypeConverters()

Returns a Map of String -> List<Class> where each entry has the `key` as the DAO name and `value` as the list of type converter classes that are necessary for the database to function.

void internalInitInvalidationTracker(SupportSQLiteDatabase db)

Called by the generated code when database is open.