From 5977e9141df840426f9bfe8fa9451fb0db437559 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Sun, 28 Apr 2019 11:41:48 -0700 Subject: [PATCH] Wrap transactions in try-finally. --- .../securesms/database/JobDatabase.java | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/JobDatabase.java b/src/org/thoughtcrime/securesms/database/JobDatabase.java index 6b5f4f15e7..d9a05e29cc 100644 --- a/src/org/thoughtcrime/securesms/database/JobDatabase.java +++ b/src/org/thoughtcrime/securesms/database/JobDatabase.java @@ -87,14 +87,17 @@ public class JobDatabase extends Database { db.beginTransaction(); - for (FullSpec fullSpec : fullSpecs) { - insertJobSpec(db, fullSpec.getJobSpec()); - insertConstraintSpecs(db, fullSpec.getConstraintSpecs()); - insertDependencySpecs(db, fullSpec.getDependencySpecs()); - } + try { + for (FullSpec fullSpec : fullSpecs) { + insertJobSpec(db, fullSpec.getJobSpec()); + insertConstraintSpecs(db, fullSpec.getConstraintSpecs()); + insertDependencySpecs(db, fullSpec.getDependencySpecs()); + } - db.setTransactionSuccessful(); - db.endTransaction(); + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } } public synchronized @NonNull List getAllJobSpecs() { @@ -142,17 +145,21 @@ public class JobDatabase extends Database { SQLiteDatabase db = databaseHelper.getWritableDatabase(); db.beginTransaction(); - for (String jobId : jobIds) { - String[] arg = new String[]{jobId}; - db.delete(Jobs.TABLE_NAME, Jobs.JOB_SPEC_ID + " = ?", arg); - db.delete(Constraints.TABLE_NAME, Constraints.JOB_SPEC_ID + " = ?", arg); - db.delete(Dependencies.TABLE_NAME, Dependencies.JOB_SPEC_ID + " = ?", arg); - db.delete(Dependencies.TABLE_NAME, Dependencies.DEPENDS_ON_JOB_SPEC_ID + " = ?", arg); + try { + for (String jobId : jobIds) { + String[] arg = new String[]{jobId}; + + db.delete(Jobs.TABLE_NAME, Jobs.JOB_SPEC_ID + " = ?", arg); + db.delete(Constraints.TABLE_NAME, Constraints.JOB_SPEC_ID + " = ?", arg); + db.delete(Dependencies.TABLE_NAME, Dependencies.JOB_SPEC_ID + " = ?", arg); + db.delete(Dependencies.TABLE_NAME, Dependencies.DEPENDS_ON_JOB_SPEC_ID + " = ?", arg); + } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); } - - db.setTransactionSuccessful(); - db.endTransaction(); } public synchronized @NonNull List getAllConstraintSpecs() {