room/testing/src/main/java/androidx/room/testing/MigrationTestHelper.java
@SuppressWarnings("SameParameterValue")
    public SupportSQLiteDatabase createDatabase(String name, int version) throws IOException {
        File dbPath = mInstrumentation.getTargetContext().getDatabasePath(name);
        if (dbPath.exists()) {
            Log.d(TAG, "deleting database file " + name);
            if (!dbPath.delete()) {
                throw new IllegalStateException("there is a database file and i could not delete"
                        + " it. Make sure you don't have any open connections to that database"
                        + " before calling this method.");
            }
        }
        SchemaBundle schemaBundle = loadSchema(version);
        RoomDatabase.MigrationContainer container = new RoomDatabase.MigrationContainer();
        DatabaseConfiguration configuration = new DatabaseConfiguration(
                mInstrumentation.getTargetContext(), name, mOpenFactory, container, null, true,
                RoomDatabase.JournalMode.TRUNCATE, true, Collections.<Integer>emptySet());
        RoomOpenHelper roomOpenHelper = new RoomOpenHelper(configuration,
                new CreatingDelegate(schemaBundle.getDatabase()),
                schemaBundle.getDatabase().getIdentityHash(),
                // we pass the same hash twice since an old schema does not necessarily have
                // a legacy hash and we would not even persist it.
                schemaBundle.getDatabase().getIdentityHash());
        return openDatabase(name, roomOpenHelper);
    }
/**
     * Creates the database in the given version.
     * If the database file already exists, it tries to delete it first. If delete fails, throws
     * an exception.
     *
     * @param name    The name of the database.
     * @param version The version in which the database should be created.
     * @return A database connection which has the schema in the requested version.
     * @throws IOException If it cannot find the schema description in the assets folder.
     */
Creates the database in the given version.
If the database file already exists, it tries to delete it first. If delete fails, throws
an exception.

@param name    The name of the database.
@param version The version in which the database should be created.
@return A database connection which has the schema in the requested version.
@throws IOException If it cannot find the schema description in the assets folder.
Creates the database in the given version . If the database file already exists it tries to delete it first . If delete fails throws an exception . @param name The name of the database . @param version The version in which the database should be created . @return A database connection which has the schema in the requested version . @throws IOException If it cannot find the schema description in the assets folder .
@SuppressWarnings("SameParameterValue")
    public SupportSQLiteDatabase createDatabase(String name, int version) throws IOException {
        File dbPath = mInstrumentation.getTargetContext().getDatabasePath(name);
        if (dbPath.exists()) {
            Log.d(TAG, "deleting database file " + name);
            if (!dbPath.delete()) {
                throw new IllegalStateException("there is a database file and i could not delete"
                        + " it. Make sure you don't have any open connections to that database"
                        + " before calling this method.");
            }
        }
        SchemaBundle schemaBundle = loadSchema(version);
        RoomDatabase.MigrationContainer container = new RoomDatabase.MigrationContainer();
        DatabaseConfiguration configuration = new DatabaseConfiguration(
                mInstrumentation.getTargetContext(), name, mOpenFactory, container, null, true,
                RoomDatabase.JournalMode.TRUNCATE, true, Collections.<Integer>emptySet());
        RoomOpenHelper roomOpenHelper = new RoomOpenHelper(configuration,
                new CreatingDelegate(schemaBundle.getDatabase()),
                schemaBundle.getDatabase().getIdentityHash(),
                schemaBundle.getDatabase().getIdentityHash());
        return openDatabase(name, roomOpenHelper);
    }
@ SuppressWarnings ( "SameParameterValue" ) public SupportSQLiteDatabase createDatabase ( String name , int version ) throws IOException { File dbPath = mInstrumentation . getTargetContext ( ) . getDatabasePath ( name ) ; if ( dbPath . exists ( ) ) { Log . d ( TAG , "deleting database file " + name ) ; if ( ! dbPath . delete ( ) ) { throw new IllegalStateException ( "there is a database file and i could not delete" + " it. Make sure you don't have any open connections to that database" + " before calling this method." ) ; } } SchemaBundle schemaBundle = loadSchema ( version ) ; RoomDatabase . MigrationContainer container = new RoomDatabase . MigrationContainer ( ) ; DatabaseConfiguration configuration = new DatabaseConfiguration ( mInstrumentation . getTargetContext ( ) , name , mOpenFactory , container , null , true , RoomDatabase . JournalMode . TRUNCATE , true , Collections . < Integer > emptySet ( ) ) ; RoomOpenHelper roomOpenHelper = new RoomOpenHelper ( configuration , new CreatingDelegate ( schemaBundle . getDatabase ( ) ) , schemaBundle . getDatabase ( ) . getIdentityHash ( ) , schemaBundle . getDatabase ( ) . getIdentityHash ( ) ) ; return openDatabase ( name , roomOpenHelper ) ; }
Creates the database in the given version.
Creates the database in the given version .
// we pass the same hash twice since an old schema does not necessarily have // a legacy hash and we would not even persist it.