RoomDatabase


public abstract class 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
Database

Summary

Nested types

public final class RoomDatabase.Builder<T extends RoomDatabase>

Builder for RoomDatabase.

public abstract class RoomDatabase.Callback

Callback for RoomDatabase

public enum RoomDatabase.JournalMode extends Enum

Journal modes for SQLite database.

A container to hold migrations.

Callback for Builder.createFromAsset, Builder.createFromFile and Builder.createFromInputStream

Public methods

abstract void

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

void

Closes the database.

@NonNull InvalidationTracker

The invalidation tracker for this database.

void

Called by Room when it is initialized.

Protected methods

abstract @NonNull InvalidationTracker

Creates the invalidation tracker

Extension functions

final @NonNull ERROR CLASS: Symbol not found for SupportSQLiteDatabase

Gets a new SupportSQLiteDatabase implementation that is backed by a RoomDatabase for compatibility with existing usages of SupportSQLiteDatabase.

Public methods

clearAllTables

Added in 3.0.0-alpha01
@WorkerThread
public abstract void clearAllTables()

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

This does NOT reset the auto-increment value generated by 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

close

Added in 3.0.0-alpha01
public void close()

Closes the database.

Once a RoomDatabase is closed it should no longer be used.

getInvalidationTracker

Added in 3.0.0-alpha01
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
@NonNull InvalidationTracker

The invalidation tracker for the database.

init

Added in 3.0.0-alpha01
@CallSuper
public void init(@NonNull DatabaseConfiguration configuration)

Called by Room when it is initialized.

Parameters
@NonNull DatabaseConfiguration configuration

The database configuration.

Throws
IllegalArgumentException

if initialization fails.

Protected methods

createInvalidationTracker

Added in 3.0.0-alpha01
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 RoomDatabase is initialized.

Returns
@NonNull InvalidationTracker

A new invalidation tracker.

Extension functions

RoomSupportSQLite.getSupportWrapper

public final @NonNull ERROR CLASS: Symbol not found for SupportSQLiteDatabase RoomSupportSQLite.getSupportWrapper(@NonNull RoomDatabase receiver)

Gets a new SupportSQLiteDatabase implementation that is backed by a RoomDatabase for compatibility with existing usages of SupportSQLiteDatabase.