|
|
|
@ -18,10 +18,12 @@ package androidx.room;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.annotation.RestrictTo;
|
|
|
|
|
import androidx.room.migration.AutoMigrationSpec;
|
|
|
|
|
import androidx.sqlite.db.SupportSQLiteOpenHelper;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
@ -69,6 +71,9 @@ public class DatabaseConfiguration {
|
|
|
|
|
@NonNull
|
|
|
|
|
public final List<Object> typeConverters;
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
|
public final List<AutoMigrationSpec> autoMigrationSpecs;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether Room should throw an exception for queries run on the main thread.
|
|
|
|
|
*/
|
|
|
|
@ -98,6 +103,15 @@ public class DatabaseConfiguration {
|
|
|
|
|
*/
|
|
|
|
|
public final boolean multiInstanceInvalidation;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Intent that should be bound to acquire the invalidation service or {@code null} if not used.
|
|
|
|
|
*
|
|
|
|
|
* @see {@link #multiInstanceInvalidation}
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
|
|
|
|
|
public final Intent multiInstanceInvalidationServiceIntent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If true, Room should crash if a migration is missing.
|
|
|
|
|
*/
|
|
|
|
@ -133,14 +147,13 @@ public class DatabaseConfiguration {
|
|
|
|
|
@Nullable
|
|
|
|
|
public final Callable<InputStream> copyFromInputStream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a database configuration with the given values.
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use {@link #DatabaseConfiguration(Context, String,
|
|
|
|
|
* SupportSQLiteOpenHelper.Factory, RoomDatabase.MigrationContainer, List, boolean,
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, boolean, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List<Object>)}
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, Intent, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List, List)}
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
@ -170,7 +183,8 @@ public class DatabaseConfiguration {
|
|
|
|
|
@Nullable Set<Integer> migrationNotRequiredFrom) {
|
|
|
|
|
this(context, name, sqliteOpenHelperFactory, migrationContainer, callbacks,
|
|
|
|
|
allowMainThreadQueries, journalMode, queryExecutor, queryExecutor, false,
|
|
|
|
|
requireMigration, false, migrationNotRequiredFrom, null, null, null, null, null);
|
|
|
|
|
requireMigration, false, migrationNotRequiredFrom, null, null, null, null, null,
|
|
|
|
|
null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -178,8 +192,8 @@ public class DatabaseConfiguration {
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use {@link #DatabaseConfiguration(Context, String,
|
|
|
|
|
* SupportSQLiteOpenHelper.Factory, RoomDatabase.MigrationContainer, List, boolean,
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, boolean, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List<Object>)}
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, Intent, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List, List)}
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
@ -216,7 +230,7 @@ public class DatabaseConfiguration {
|
|
|
|
|
this(context, name, sqliteOpenHelperFactory, migrationContainer, callbacks,
|
|
|
|
|
allowMainThreadQueries, journalMode, queryExecutor, transactionExecutor,
|
|
|
|
|
multiInstanceInvalidation, requireMigration, allowDestructiveMigrationOnDowngrade,
|
|
|
|
|
migrationNotRequiredFrom, null, null, null, null, null);
|
|
|
|
|
migrationNotRequiredFrom, null, null, null, null, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -224,8 +238,8 @@ public class DatabaseConfiguration {
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use {@link #DatabaseConfiguration(Context, String,
|
|
|
|
|
* SupportSQLiteOpenHelper.Factory, RoomDatabase.MigrationContainer, List, boolean,
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, boolean, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List<Object>)}
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, Intent, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List, List)}
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
@ -266,7 +280,7 @@ public class DatabaseConfiguration {
|
|
|
|
|
this(context, name, sqliteOpenHelperFactory, migrationContainer, callbacks,
|
|
|
|
|
allowMainThreadQueries, journalMode, queryExecutor, transactionExecutor,
|
|
|
|
|
multiInstanceInvalidation, requireMigration, allowDestructiveMigrationOnDowngrade,
|
|
|
|
|
migrationNotRequiredFrom, copyFromAssetPath, copyFromFile, null, null, null);
|
|
|
|
|
migrationNotRequiredFrom, copyFromAssetPath, copyFromFile, null, null, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -274,8 +288,8 @@ public class DatabaseConfiguration {
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use {@link #DatabaseConfiguration(Context, String,
|
|
|
|
|
* SupportSQLiteOpenHelper.Factory, RoomDatabase.MigrationContainer, List, boolean,
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, boolean, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List<Object>)}
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, Intent, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List, List)}
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
@ -320,7 +334,7 @@ public class DatabaseConfiguration {
|
|
|
|
|
allowMainThreadQueries, journalMode, queryExecutor, transactionExecutor,
|
|
|
|
|
multiInstanceInvalidation, requireMigration, allowDestructiveMigrationOnDowngrade,
|
|
|
|
|
migrationNotRequiredFrom, copyFromAssetPath, copyFromFile, copyFromInputStream,
|
|
|
|
|
null, null);
|
|
|
|
|
null, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -328,8 +342,8 @@ public class DatabaseConfiguration {
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use {@link #DatabaseConfiguration(Context, String,
|
|
|
|
|
* SupportSQLiteOpenHelper.Factory, RoomDatabase.MigrationContainer, List, boolean,
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, boolean, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List<Object>)}
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, Intent, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List, List)}
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
@ -377,12 +391,17 @@ public class DatabaseConfiguration {
|
|
|
|
|
allowMainThreadQueries, journalMode, queryExecutor, transactionExecutor,
|
|
|
|
|
multiInstanceInvalidation, requireMigration, allowDestructiveMigrationOnDowngrade,
|
|
|
|
|
migrationNotRequiredFrom, copyFromAssetPath, copyFromFile, copyFromInputStream,
|
|
|
|
|
prepackagedDatabaseCallback, null);
|
|
|
|
|
prepackagedDatabaseCallback, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a database configuration with the given values.
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use {@link #DatabaseConfiguration(Context, String,
|
|
|
|
|
* SupportSQLiteOpenHelper.Factory, RoomDatabase.MigrationContainer, List, boolean,
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, Intent, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List, List)}
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
|
* @param sqliteOpenHelperFactory The open helper factory to use.
|
|
|
|
@ -407,6 +426,7 @@ public class DatabaseConfiguration {
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@Deprecated
|
|
|
|
|
@SuppressLint("LambdaLast")
|
|
|
|
|
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
|
|
|
|
|
public DatabaseConfiguration(@NonNull Context context, @Nullable String name,
|
|
|
|
@ -426,6 +446,126 @@ public class DatabaseConfiguration {
|
|
|
|
|
@Nullable Callable<InputStream> copyFromInputStream,
|
|
|
|
|
@Nullable RoomDatabase.PrepackagedDatabaseCallback prepackagedDatabaseCallback,
|
|
|
|
|
@Nullable List<Object> typeConverters) {
|
|
|
|
|
this(context, name, sqliteOpenHelperFactory, migrationContainer, callbacks,
|
|
|
|
|
allowMainThreadQueries, journalMode, queryExecutor, transactionExecutor,
|
|
|
|
|
multiInstanceInvalidation, requireMigration, allowDestructiveMigrationOnDowngrade,
|
|
|
|
|
migrationNotRequiredFrom, copyFromAssetPath, copyFromFile, copyFromInputStream,
|
|
|
|
|
prepackagedDatabaseCallback, typeConverters, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a database configuration with the given values.
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Use {@link #DatabaseConfiguration(Context, String,
|
|
|
|
|
* SupportSQLiteOpenHelper.Factory, RoomDatabase.MigrationContainer, List, boolean,
|
|
|
|
|
* RoomDatabase.JournalMode, Executor, Executor, Intent, boolean, boolean, Set, String, File,
|
|
|
|
|
* Callable, RoomDatabase.PrepackagedDatabaseCallback, List, List)}
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
|
* @param sqliteOpenHelperFactory The open helper factory to use.
|
|
|
|
|
* @param migrationContainer The migration container for migrations.
|
|
|
|
|
* @param callbacks The list of callbacks for database events.
|
|
|
|
|
* @param allowMainThreadQueries Whether to allow main thread reads/writes or not.
|
|
|
|
|
* @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING.
|
|
|
|
|
* @param queryExecutor The Executor used to execute asynchronous queries.
|
|
|
|
|
* @param transactionExecutor The Executor used to execute asynchronous transactions.
|
|
|
|
|
* @param multiInstanceInvalidation True if Room should perform multi-instance invalidation.
|
|
|
|
|
* @param requireMigration True if Room should require a valid migration if version changes,
|
|
|
|
|
* @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no
|
|
|
|
|
* migration is supplied during a downgrade.
|
|
|
|
|
* @param migrationNotRequiredFrom The collection of schema versions from which migrations
|
|
|
|
|
* aren't required.
|
|
|
|
|
* @param copyFromAssetPath The assets path to the pre-packaged database.
|
|
|
|
|
* @param copyFromFile The pre-packaged database file.
|
|
|
|
|
* @param copyFromInputStream The callable to get the input stream from which a
|
|
|
|
|
* pre-package database file will be copied from.
|
|
|
|
|
* @param prepackagedDatabaseCallback The pre-packaged callback.
|
|
|
|
|
* @param typeConverters The type converters.
|
|
|
|
|
* @param autoMigrationSpecs The auto migration specs.
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@Deprecated
|
|
|
|
|
@SuppressLint("LambdaLast")
|
|
|
|
|
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
|
|
|
|
|
public DatabaseConfiguration(@NonNull Context context, @Nullable String name,
|
|
|
|
|
@NonNull SupportSQLiteOpenHelper.Factory sqliteOpenHelperFactory,
|
|
|
|
|
@NonNull RoomDatabase.MigrationContainer migrationContainer,
|
|
|
|
|
@Nullable List<RoomDatabase.Callback> callbacks,
|
|
|
|
|
boolean allowMainThreadQueries,
|
|
|
|
|
@NonNull RoomDatabase.JournalMode journalMode,
|
|
|
|
|
@NonNull Executor queryExecutor,
|
|
|
|
|
@NonNull Executor transactionExecutor,
|
|
|
|
|
boolean multiInstanceInvalidation,
|
|
|
|
|
boolean requireMigration,
|
|
|
|
|
boolean allowDestructiveMigrationOnDowngrade,
|
|
|
|
|
@Nullable Set<Integer> migrationNotRequiredFrom,
|
|
|
|
|
@Nullable String copyFromAssetPath,
|
|
|
|
|
@Nullable File copyFromFile,
|
|
|
|
|
@Nullable Callable<InputStream> copyFromInputStream,
|
|
|
|
|
@Nullable RoomDatabase.PrepackagedDatabaseCallback prepackagedDatabaseCallback,
|
|
|
|
|
@Nullable List<Object> typeConverters,
|
|
|
|
|
@Nullable List<AutoMigrationSpec> autoMigrationSpecs) {
|
|
|
|
|
this(context, name, sqliteOpenHelperFactory, migrationContainer, callbacks,
|
|
|
|
|
allowMainThreadQueries, journalMode, queryExecutor, transactionExecutor,
|
|
|
|
|
multiInstanceInvalidation ? new Intent(context,
|
|
|
|
|
MultiInstanceInvalidationService.class) : null,
|
|
|
|
|
requireMigration, allowDestructiveMigrationOnDowngrade, migrationNotRequiredFrom,
|
|
|
|
|
copyFromAssetPath, copyFromFile, copyFromInputStream, prepackagedDatabaseCallback,
|
|
|
|
|
typeConverters, autoMigrationSpecs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a database configuration with the given values.
|
|
|
|
|
*
|
|
|
|
|
* @param context The application context.
|
|
|
|
|
* @param name Name of the database, can be null if it is in memory.
|
|
|
|
|
* @param sqliteOpenHelperFactory The open helper factory to use.
|
|
|
|
|
* @param migrationContainer The migration container for migrations.
|
|
|
|
|
* @param callbacks The list of callbacks for database events.
|
|
|
|
|
* @param allowMainThreadQueries Whether to allow main thread reads/writes or not.
|
|
|
|
|
* @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING.
|
|
|
|
|
* @param queryExecutor The Executor used to execute asynchronous queries.
|
|
|
|
|
* @param transactionExecutor The Executor used to execute asynchronous transactions.
|
|
|
|
|
* @param multiInstanceInvalidationServiceIntent The intent to use to bind to the
|
|
|
|
|
* invalidation service or {@code null} if not
|
|
|
|
|
* used.
|
|
|
|
|
* @param requireMigration True if Room should require a valid migration if version changes,
|
|
|
|
|
* @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no
|
|
|
|
|
* migration is supplied during a downgrade.
|
|
|
|
|
* @param migrationNotRequiredFrom The collection of schema versions from which migrations
|
|
|
|
|
* aren't required.
|
|
|
|
|
* @param copyFromAssetPath The assets path to the pre-packaged database.
|
|
|
|
|
* @param copyFromFile The pre-packaged database file.
|
|
|
|
|
* @param copyFromInputStream The callable to get the input stream from which a
|
|
|
|
|
* pre-package database file will be copied from.
|
|
|
|
|
* @param prepackagedDatabaseCallback The pre-packaged callback.
|
|
|
|
|
* @param typeConverters The type converters.
|
|
|
|
|
* @param autoMigrationSpecs The auto migration specs.
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@SuppressLint("LambdaLast")
|
|
|
|
|
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
|
|
|
|
|
public DatabaseConfiguration(@NonNull Context context, @Nullable String name,
|
|
|
|
|
@NonNull SupportSQLiteOpenHelper.Factory sqliteOpenHelperFactory,
|
|
|
|
|
@NonNull RoomDatabase.MigrationContainer migrationContainer,
|
|
|
|
|
@Nullable List<RoomDatabase.Callback> callbacks,
|
|
|
|
|
boolean allowMainThreadQueries,
|
|
|
|
|
@NonNull RoomDatabase.JournalMode journalMode,
|
|
|
|
|
@NonNull Executor queryExecutor,
|
|
|
|
|
@NonNull Executor transactionExecutor,
|
|
|
|
|
@Nullable Intent multiInstanceInvalidationServiceIntent,
|
|
|
|
|
boolean requireMigration,
|
|
|
|
|
boolean allowDestructiveMigrationOnDowngrade,
|
|
|
|
|
@Nullable Set<Integer> migrationNotRequiredFrom,
|
|
|
|
|
@Nullable String copyFromAssetPath,
|
|
|
|
|
@Nullable File copyFromFile,
|
|
|
|
|
@Nullable Callable<InputStream> copyFromInputStream,
|
|
|
|
|
@Nullable RoomDatabase.PrepackagedDatabaseCallback prepackagedDatabaseCallback,
|
|
|
|
|
@Nullable List<Object> typeConverters,
|
|
|
|
|
@Nullable List<AutoMigrationSpec> autoMigrationSpecs) {
|
|
|
|
|
this.sqliteOpenHelperFactory = sqliteOpenHelperFactory;
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.name = name;
|
|
|
|
@ -435,7 +575,9 @@ public class DatabaseConfiguration {
|
|
|
|
|
this.journalMode = journalMode;
|
|
|
|
|
this.queryExecutor = queryExecutor;
|
|
|
|
|
this.transactionExecutor = transactionExecutor;
|
|
|
|
|
this.multiInstanceInvalidation = multiInstanceInvalidation;
|
|
|
|
|
this.multiInstanceInvalidationServiceIntent =
|
|
|
|
|
multiInstanceInvalidationServiceIntent;
|
|
|
|
|
this.multiInstanceInvalidation = multiInstanceInvalidationServiceIntent != null;
|
|
|
|
|
this.requireMigration = requireMigration;
|
|
|
|
|
this.allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade;
|
|
|
|
|
this.mMigrationNotRequiredFrom = migrationNotRequiredFrom;
|
|
|
|
@ -444,6 +586,8 @@ public class DatabaseConfiguration {
|
|
|
|
|
this.copyFromInputStream = copyFromInputStream;
|
|
|
|
|
this.prepackagedDatabaseCallback = prepackagedDatabaseCallback;
|
|
|
|
|
this.typeConverters = typeConverters == null ? Collections.emptyList() : typeConverters;
|
|
|
|
|
this.autoMigrationSpecs = autoMigrationSpecs == null
|
|
|
|
|
? Collections.emptyList() : autoMigrationSpecs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|