mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 19:38:34 +00:00
Fix threading issue in RecipientDatabase.
This commit is contained in:
parent
acea24c19c
commit
5f993ed0f7
@ -188,18 +188,24 @@ public class RecipientDatabase extends Database {
|
|||||||
String query = PHONE + " = ?";
|
String query = PHONE + " = ?";
|
||||||
String[] args = new String[] { e164 };
|
String[] args = new String[] { e164 };
|
||||||
|
|
||||||
synchronized (this) {
|
db.beginTransaction();
|
||||||
|
|
||||||
try (Cursor cursor = db.query(TABLE_NAME, ID_PROJECTION, query, args, null, null, null)) {
|
try (Cursor cursor = db.query(TABLE_NAME, ID_PROJECTION, query, args, null, null, null)) {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
db.setTransactionSuccessful();
|
||||||
return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
||||||
} else {
|
} else {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(PHONE, e164);
|
values.put(PHONE, e164);
|
||||||
|
|
||||||
long id = db.insertOrThrow(TABLE_NAME, null, values);
|
long id = db.insertOrThrow(TABLE_NAME, null, values);
|
||||||
if (id < 0) throw new AssertionError("Failed to insert recipient!");
|
if (id < 0) throw new AssertionError("Failed to insert recipient!");
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
return RecipientId.from(id);
|
return RecipientId.from(id);
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,18 +218,24 @@ public class RecipientDatabase extends Database {
|
|||||||
String query = EMAIL + " = ?";
|
String query = EMAIL + " = ?";
|
||||||
String[] args = new String[] { email };
|
String[] args = new String[] { email };
|
||||||
|
|
||||||
synchronized (this) {
|
db.beginTransaction();
|
||||||
|
|
||||||
try (Cursor cursor = db.query(TABLE_NAME, ID_PROJECTION, query, args, null, null, null)) {
|
try (Cursor cursor = db.query(TABLE_NAME, ID_PROJECTION, query, args, null, null, null)) {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
db.setTransactionSuccessful();
|
||||||
return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
||||||
} else {
|
} else {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(EMAIL, email);
|
values.put(EMAIL, email);
|
||||||
|
|
||||||
long id = db.insertOrThrow(TABLE_NAME, null, values);
|
long id = db.insertOrThrow(TABLE_NAME, null, values);
|
||||||
if (id < 0) throw new AssertionError("Failed to insert recipient!");
|
if (id < 0) throw new AssertionError("Failed to insert recipient!");
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
return RecipientId.from(id);
|
return RecipientId.from(id);
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,18 +248,24 @@ public class RecipientDatabase extends Database {
|
|||||||
String query = GROUP_ID + " = ?";
|
String query = GROUP_ID + " = ?";
|
||||||
String[] args = new String[] { groupId };
|
String[] args = new String[] { groupId };
|
||||||
|
|
||||||
synchronized (this) {
|
db.beginTransaction();
|
||||||
|
|
||||||
try (Cursor cursor = db.query(TABLE_NAME, ID_PROJECTION, query, args, null, null, null)) {
|
try (Cursor cursor = db.query(TABLE_NAME, ID_PROJECTION, query, args, null, null, null)) {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
db.setTransactionSuccessful();
|
||||||
return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
return RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
||||||
} else {
|
} else {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(GROUP_ID, groupId);
|
values.put(GROUP_ID, groupId);
|
||||||
|
|
||||||
long id = db.insertOrThrow(TABLE_NAME, null, values);
|
long id = db.insertOrThrow(TABLE_NAME, null, values);
|
||||||
if (id < 0) throw new AssertionError("Failed to insert recipient!");
|
if (id < 0) throw new AssertionError("Failed to insert recipient!");
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
return RecipientId.from(id);
|
return RecipientId.from(id);
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user