Java Code Examples for androidx.sqlite.db.SupportSQLiteOpenHelper#Factory

The following examples show how to use androidx.sqlite.db.SupportSQLiteOpenHelper#Factory . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SafeFactoryProvider.java    From cwac-saferoom with Apache License 2.0 6 votes vote down vote up
@Override
public void tearDownDatabase(Context ctxt,
                             SupportSQLiteOpenHelper.Factory factory,
                             SupportSQLiteOpenHelper helper) {
  String name=helper.getDatabaseName();

  if (name!=null) {
    File db=ctxt.getDatabasePath(name);

    if (db.exists()) {
      db.delete();
    }

    File journal=new File(db.getParentFile(), name+"-journal");

    if (journal.exists()) {
      journal.delete();
    }
  }
}
 
Example 2
Source File: SQLiteCopyOpenHelperFactory.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
SQLiteCopyOpenHelperFactory(
        @Nullable String copyFromAssetPath,
        @Nullable File copyFromFile,
        @NonNull SupportSQLiteOpenHelper.Factory factory) {
    mCopyFromAssetPath = copyFromAssetPath;
    mCopyFromFile = copyFromFile;
    mDelegate = factory;
}
 
Example 3
Source File: DatabaseConfiguration.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 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.
 *
 * @hide
 */
@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,
        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) {
    this.sqliteOpenHelperFactory = sqliteOpenHelperFactory;
    this.context = context;
    this.name = name;
    this.migrationContainer = migrationContainer;
    this.callbacks = callbacks;
    this.allowMainThreadQueries = allowMainThreadQueries;
    this.journalMode = journalMode;
    this.queryExecutor = queryExecutor;
    this.transactionExecutor = transactionExecutor;
    this.multiInstanceInvalidation = multiInstanceInvalidation;
    this.requireMigration = requireMigration;
    this.allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade;
    this.mMigrationNotRequiredFrom = migrationNotRequiredFrom;
    this.copyFromAssetPath = copyFromAssetPath;
    this.copyFromFile = copyFromFile;
}
 
Example 4
Source File: DatabaseConfiguration.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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)}
 *
 * @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 requireMigration True if Room should require a valid migration if version changes,
 *                        instead of recreating the tables.
 * @param migrationNotRequiredFrom The collection of schema versions from which migrations
 *                                 aren't required.
 *
 * @hide
 */
@Deprecated
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
public DatabaseConfiguration(@NonNull Context context, @Nullable String name,
        @NonNull SupportSQLiteOpenHelper.Factory sqliteOpenHelperFactory,
        @NonNull RoomDatabase.MigrationContainer migrationContainer,
        @Nullable List<androidx.room.RoomDatabase.Callback> callbacks,
        boolean allowMainThreadQueries,
        RoomDatabase.JournalMode journalMode,
        @NonNull Executor queryExecutor,
        boolean requireMigration,
        @Nullable Set<Integer> migrationNotRequiredFrom) {
    this(context, name, sqliteOpenHelperFactory, migrationContainer, callbacks,
            allowMainThreadQueries, journalMode, queryExecutor, queryExecutor, false,
            requireMigration, false, migrationNotRequiredFrom, null, null);
}
 
Example 5
Source File: DatabaseConfiguration.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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)}
 *
 * @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.
 *
 * @hide
 */
@Deprecated
@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,
        RoomDatabase.JournalMode journalMode,
        @NonNull Executor queryExecutor,
        @NonNull Executor transactionExecutor,
        boolean multiInstanceInvalidation,
        boolean requireMigration,
        boolean allowDestructiveMigrationOnDowngrade,
        @Nullable Set<Integer> migrationNotRequiredFrom) {
    this(context, name, sqliteOpenHelperFactory, migrationContainer, callbacks,
            allowMainThreadQueries, journalMode, queryExecutor, transactionExecutor,
            multiInstanceInvalidation, requireMigration, allowDestructiveMigrationOnDowngrade,
            migrationNotRequiredFrom, null, null);
}
 
Example 6
Source File: SafeFactoryProvider.java    From cwac-saferoom with Apache License 2.0 4 votes vote down vote up
@Override
public SupportSQLiteOpenHelper.Factory getFactory() {
  return SafeHelperFactory.fromUser(new SpannableStringBuilder("sekrit"));
}
 
Example 7
Source File: RoomDatabase.java    From FairEmail with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the database factory. If not set, it defaults to
 * {@link FrameworkSQLiteOpenHelperFactory}.
 *
 * @param factory The factory to use to access the database.
 * @return This {@link Builder} instance.
 */
@NonNull
public Builder<T> openHelperFactory(@Nullable SupportSQLiteOpenHelper.Factory factory) {
    mFactory = factory;
    return this;
}