Room


public static class Room


Entry point for building and initializing a RoomDatabase.

Summary

Public fields

@NonNull Room

Public methods

final @NonNull RoomDatabase.Builder<@NonNull T>
<T extends RoomDatabase> databaseBuilder(
    @NonNull String name,
    @NonNull Function0<@NonNull T> factory
)

Creates a RoomDatabase.Builder for a persistent database.

final @NonNull String

The master table name where Room keeps its metadata information.

final @NonNull RoomDatabase.Builder<@NonNull T>
<T extends RoomDatabase> inMemoryDatabaseBuilder(
    @NonNull Function0<@NonNull T> factory
)

Creates a RoomDatabase.Builder for an in memory database.

Public fields

INSTANCE

Added in 2.5.0
public @NonNull Room INSTANCE

Public methods

databaseBuilder

public final @NonNull RoomDatabase.Builder<@NonNull T> <T extends RoomDatabase> databaseBuilder(
    @NonNull String name,
    @NonNull Function0<@NonNull T> factory
)

Creates a RoomDatabase.Builder for a persistent database. Once a database is built, you should keep a reference to it and re-use it.

Parameters
<T extends RoomDatabase>

The type of the database class.

@NonNull String name

The name of the database file.

@NonNull Function0<@NonNull T> factory

An optional lambda calling initializeImpl() on the database class which returns the generated database implementation. If not provided then reflection is used to find and instantiate the database implementation class.

Returns
@NonNull RoomDatabase.Builder<@NonNull T>

A RoomDatabaseBuilder<T> which you can use to create the database.

getMASTER_TABLE_NAME

public final @NonNull String getMASTER_TABLE_NAME()

The master table name where Room keeps its metadata information.

inMemoryDatabaseBuilder

public final @NonNull RoomDatabase.Builder<@NonNull T> <T extends RoomDatabase> inMemoryDatabaseBuilder(
    @NonNull Function0<@NonNull T> factory
)

Creates a RoomDatabase.Builder for an in memory database. Information stored in an in memory database disappears when the process is killed. Once a database is built, you should keep a reference to it and re-use it.

Parameters
<T extends RoomDatabase>

The type of the database class.

@NonNull Function0<@NonNull T> factory

An optional lambda calling initializeImpl() on the database class which returns the generated database implementation. If not provided then reflection is used to find and instantiate the database implementation class.

Returns
@NonNull RoomDatabase.Builder<@NonNull T>

A RoomDatabaseBuilder<T> which you can use to create the database.