Room

public static class Room


Utility functions for Room.

Summary

Constants

static final @NonNull String

The master table where room keeps its metadata information.

Public fields

static @NonNull Room

Public methods

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.

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.

Constants

MASTER_TABLE_NAME

public static final @NonNull String MASTER_TABLE_NAME

The master table where room keeps its metadata information.

Public fields

INSTANCE

public static @NonNull Room INSTANCE

Public methods

databaseBuilder

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.

inMemoryDatabaseBuilder

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.