Creates a RoomDatabase.Builder for a persistent database. Once a database is built, you should keep a reference to it and re-use it. @param context The context for the database. This is usually the Application context. @param klass The abstract class which is annotated with Database and e
(
@NonNull Context context, @NonNull Class<T> klass, @NonNull String name)
| 45 | * @return A {@code RoomDatabaseBuilder<T>} which you can use to create the database. |
| 46 | */ |
| 47 | @SuppressWarnings("WeakerAccess") |
| 48 | @NonNull |
| 49 | public static <T extends RoomDatabase> RoomDatabase.Builder<T> databaseBuilder( |
| 50 | @NonNull Context context, @NonNull Class<T> klass, @NonNull String name) { |
| 51 | //noinspection ConstantConditions |
| 52 | if (name == null || name.trim().length() == 0) { |
| 53 | throw new IllegalArgumentException("Cannot build a database with null or empty name." |
| 54 | + " If you are trying to create an in memory database, use Room" |
| 55 | + ".inMemoryDatabaseBuilder"); |
| 56 | } |
| 57 | return new RoomDatabase.Builder<>(context, klass, name); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a RoomDatabase.Builder for an in memory database. Information stored in an in memory |
no test coverage detected