Consistently use database transactions

To prevent hard to find problem
This commit is contained in:
M66B
2018-08-12 12:47:52 +00:00
parent f0cf9dafa4
commit 92e9120e06
11 changed files with 419 additions and 321 deletions

View File

@@ -157,15 +157,24 @@ public class FragmentSetup extends FragmentEx {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
DB db = DB.getInstance(context);
EntityFolder outbox = db.folder().getOutbox();
if (outbox == null) {
outbox = new EntityFolder();
outbox.name = "OUTBOX";
outbox.type = EntityFolder.OUTBOX;
outbox.synchronize = false;
outbox.after = 0;
outbox.id = db.folder().insertFolder(outbox);
try {
db.beginTransaction();
EntityFolder outbox = db.folder().getOutbox();
if (outbox == null) {
outbox = new EntityFolder();
outbox.name = "OUTBOX";
outbox.type = EntityFolder.OUTBOX;
outbox.synchronize = false;
outbox.after = 0;
outbox.id = db.folder().insertFolder(outbox);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}