mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-03-04 15:28:21 +03:00
42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
package org.schabi.newpipe;
|
|
|
|
import androidx.room.Room;
|
|
import android.content.Context;
|
|
import androidx.annotation.NonNull;
|
|
|
|
import org.schabi.newpipe.database.AppDatabase;
|
|
|
|
import static org.schabi.newpipe.database.AppDatabase.DATABASE_NAME;
|
|
import static org.schabi.newpipe.database.Migrations.MIGRATION_11_12;
|
|
|
|
public final class NewPipeDatabase {
|
|
|
|
private static volatile AppDatabase databaseInstance;
|
|
|
|
private NewPipeDatabase() {
|
|
//no instance
|
|
}
|
|
|
|
private static AppDatabase getDatabase(Context context) {
|
|
return Room
|
|
.databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME)
|
|
.addMigrations(MIGRATION_11_12)
|
|
.fallbackToDestructiveMigration()
|
|
.build();
|
|
}
|
|
|
|
@NonNull
|
|
public static AppDatabase getInstance(@NonNull Context context) {
|
|
AppDatabase result = databaseInstance;
|
|
if (result == null) {
|
|
synchronized (NewPipeDatabase.class) {
|
|
result = databaseInstance;
|
|
if (result == null) {
|
|
databaseInstance = (result = getDatabase(context));
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|