2017-08-07 06:02:30 -07:00
|
|
|
package org.schabi.newpipe;
|
|
|
|
|
|
|
|
import android.arch.persistence.room.Room;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.database.AppDatabase;
|
|
|
|
|
|
|
|
import static org.schabi.newpipe.database.AppDatabase.DATABASE_NAME;
|
2018-01-17 13:24:59 -08:00
|
|
|
import static org.schabi.newpipe.database.Migrations.MIGRATION_11_12;
|
2017-08-07 06:02:30 -07:00
|
|
|
|
2017-09-03 03:04:18 -03:00
|
|
|
public final class NewPipeDatabase {
|
2017-08-07 06:02:30 -07:00
|
|
|
|
2017-09-03 03:04:18 -03:00
|
|
|
private static AppDatabase databaseInstance;
|
2017-08-07 06:02:30 -07:00
|
|
|
|
2017-09-03 03:04:18 -03:00
|
|
|
private NewPipeDatabase() {
|
|
|
|
//no instance
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void init(Context context) {
|
2018-01-17 13:24:59 -08:00
|
|
|
databaseInstance = Room
|
|
|
|
.databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME)
|
|
|
|
.addMigrations(MIGRATION_11_12)
|
2018-01-17 13:53:32 -08:00
|
|
|
.fallbackToDestructiveMigration()
|
2018-01-17 13:24:59 -08:00
|
|
|
.build();
|
2017-09-03 03:04:18 -03:00
|
|
|
}
|
2017-08-07 06:02:30 -07:00
|
|
|
|
|
|
|
@NonNull
|
2018-01-17 13:53:32 -08:00
|
|
|
@Deprecated
|
2017-09-03 03:04:18 -03:00
|
|
|
public static AppDatabase getInstance() {
|
|
|
|
if (databaseInstance == null) throw new RuntimeException("Database not initialized");
|
|
|
|
|
|
|
|
return databaseInstance;
|
2017-08-07 06:02:30 -07:00
|
|
|
}
|
2018-01-15 12:30:52 -08:00
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public static AppDatabase getInstance(Context context) {
|
|
|
|
if (databaseInstance == null) init(context);
|
|
|
|
return databaseInstance;
|
|
|
|
}
|
2017-08-07 06:02:30 -07:00
|
|
|
}
|