예제 #1
0
  @Override
  public void onCreate(SQLiteDatabase db) {
    if (databaseHelperListener != null) {
      databaseHelperListener.onCreate(db);
    }

    checkForeignKeySupport(db);
    executeCreations(db);
    executeMigrations(db, -1, databaseDefinition.getDatabaseVersion());
  }
예제 #2
0
  public FlowSQLiteOpenHelper(
      BaseDatabaseDefinition databaseDefinition, DatabaseHelperListener listener) {
    super(
        FlowManager.getContext(),
        databaseDefinition.isInMemory() ? null : databaseDefinition.getDatabaseFileName(),
        null,
        databaseDefinition.getDatabaseVersion());
    databaseHelperListener = listener;
    this.databaseDefinition = databaseDefinition;

    movePrepackagedDB(
        this.databaseDefinition.getDatabaseFileName(),
        this.databaseDefinition.getDatabaseFileName());

    if (databaseDefinition.backupEnabled()) {
      // Temp database mirrors existing
      backupHelper =
          new SQLiteOpenHelper(
              FlowManager.getContext(),
              getTempDbFileName(),
              null,
              databaseDefinition.getDatabaseVersion()) {
            @Override
            public void onOpen(SQLiteDatabase db) {
              FlowSQLiteOpenHelper.this.onOpen(db);
            }

            @Override
            public void onCreate(SQLiteDatabase db) {
              FlowSQLiteOpenHelper.this.onCreate(db);
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
              FlowSQLiteOpenHelper.this.onUpgrade(db, oldVersion, newVersion);
            }
          };
      restoreDatabase(getTempDbFileName(), this.databaseDefinition.getDatabaseFileName());
      backupHelper.getWritableDatabase();
    }
  }