Skip to content

Commit

Permalink
Use only one SQLiteDatabase and enable write-ahead logging (fix #1268)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Aug 23, 2019
1 parent 292a526 commit b7d9f01
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions app/src/main/java/org/kontalk/provider/UsersProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ static class DatabaseHelper extends SQLiteOpenHelper {
SCHEMA_KEYS,
};

private Context mContext;

/** This will be set to true when database is new. */
private boolean mNew;
/** A read-only connection to the database. */
private SQLiteDatabase dbReader;

DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
mContext = context;
}

@Override
public void onOpen(SQLiteDatabase db) {
db.enableWriteAheadLogging();
}

@Override
Expand Down Expand Up @@ -227,34 +227,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}

@Override
public void onOpen(SQLiteDatabase db) {
String path = mContext.getDatabasePath(DATABASE_NAME).getPath();
SQLiteDatabaseConfiguration configuration =
createConfiguration(path, SQLiteDatabase.OPEN_READONLY);
dbReader = SQLiteDatabase.openDatabase(configuration, null, null);
}

public boolean isNew() {
return mNew;
}

@Override
public synchronized void close() {
try {
dbReader.close();
}
catch (Exception e) {
// ignored
}
dbReader = null;
super.close();
}

@Override
public synchronized SQLiteDatabase getReadableDatabase() {
return (dbReader != null) ? dbReader : super.getReadableDatabase();
}
}

@Override
Expand Down

0 comments on commit b7d9f01

Please sign in to comment.