Refactoring

This commit is contained in:
M66B 2020-01-20 20:39:50 +01:00
parent 4f636fb870
commit fb2c1e21ca
1 changed files with 4 additions and 5 deletions

View File

@ -110,13 +110,12 @@ public abstract class DB extends RoomDatabase {
@Override @Override
public void init(@NonNull DatabaseConfiguration configuration) { public void init(@NonNull DatabaseConfiguration configuration) {
// https://www.sqlite.org/pragma.html#pragma_wal_autocheckpoint // https://www.sqlite.org/pragma.html#pragma_wal_autocheckpoint
String dbpath = configuration.context.getDatabasePath(DB_NAME).getPath(); File dbfile = configuration.context.getDatabasePath(DB_NAME);
if (new File(dbpath).exists()) { if (dbfile.exists()) {
try (SQLiteDatabase db = SQLiteDatabase.openDatabase(dbpath, null, SQLiteDatabase.OPEN_READWRITE)) { try (SQLiteDatabase db = SQLiteDatabase.openDatabase(dbfile.getPath(), null, SQLiteDatabase.OPEN_READWRITE)) {
Log.i("DB checkpoint=" + DB_CHECKPOINT); Log.i("DB checkpoint=" + DB_CHECKPOINT);
try (Cursor cursor = db.rawQuery("PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT + ";", null)) { try (Cursor cursor = db.rawQuery("PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT + ";", null)) {
cursor.moveToNext(); cursor.moveToNext(); // required
} }
} }
} }