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.

static final @NonNull RoomDatabase.Builder<@NonNull T>
<T extends RoomDatabase> databaseBuilder(
    @NonNull Context context,
    @NonNull Class<@NonNull T> klass,
    String name
)

Creates a RoomDatabase.Builder for a persistent database.

final @NonNull RoomDatabase.Builder<@NonNull T>
<T extends RoomDatabase> databaseBuilder(
    @NonNull Context context,
    @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.

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

Creates a RoomDatabase.Builder for an in memory database.

static final @NonNull RoomDatabase.Builder<@NonNull T>
<T extends RoomDatabase> inMemoryDatabaseBuilder(
    @NonNull Context context,
    @NonNull Class<@NonNull T> klass
)

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.

databaseBuilder

Added in 2.0.0
public static final @NonNull RoomDatabase.Builder<@NonNull T> <T extends RoomDatabase> databaseBuilder(
    @NonNull Context context,
    @NonNull Class<@NonNull T> klass,
    String name
)

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 Context context

The context for the database. This is usually the Application context.

@NonNull Class<@NonNull T> klass

The abstract class which is annotated with Database and extends RoomDatabase.

String name

The name of the database file.

Returns
@NonNull RoomDatabase.Builder<@NonNull T>

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

databaseBuilder

public final @NonNull RoomDatabase.Builder<@NonNull T> <T extends RoomDatabase> databaseBuilder(
    @NonNull Context context,
    @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 Context context

The context for the database. This is usually the Application context.

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

inMemoryDatabaseBuilder

public final @NonNull RoomDatabase.Builder<@NonNull T> <T extends RoomDatabase> inMemoryDatabaseBuilder(
    @NonNull Context context,
    @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 Context context

The context for the database. This is usually the Application context.

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

inMemoryDatabaseBuilder

Added in 2.0.0
public static final @NonNull RoomDatabase.Builder<@NonNull T> <T extends RoomDatabase> inMemoryDatabaseBuilder(
    @NonNull Context context,
    @NonNull Class<@NonNull T> klass
)

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 Context context

The context for the database. This is usually the Application context.

@NonNull Class<@NonNull T> klass

The abstract class which is annotated with Database and extends RoomDatabase.

Returns
@NonNull RoomDatabase.Builder<@NonNull T>

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