Wrap transactions in try-finally.

This commit is contained in:
Greyson Parrelli 2019-04-28 11:41:48 -07:00
parent c0982293bf
commit 5977e9141d

View File

@ -87,6 +87,7 @@ public class JobDatabase extends Database {
db.beginTransaction(); db.beginTransaction();
try {
for (FullSpec fullSpec : fullSpecs) { for (FullSpec fullSpec : fullSpecs) {
insertJobSpec(db, fullSpec.getJobSpec()); insertJobSpec(db, fullSpec.getJobSpec());
insertConstraintSpecs(db, fullSpec.getConstraintSpecs()); insertConstraintSpecs(db, fullSpec.getConstraintSpecs());
@ -94,8 +95,10 @@ public class JobDatabase extends Database {
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally {
db.endTransaction(); db.endTransaction();
} }
}
public synchronized @NonNull List<JobSpec> getAllJobSpecs() { public synchronized @NonNull List<JobSpec> getAllJobSpecs() {
List<JobSpec> jobs = new LinkedList<>(); List<JobSpec> jobs = new LinkedList<>();
@ -142,6 +145,8 @@ public class JobDatabase extends Database {
SQLiteDatabase db = databaseHelper.getWritableDatabase(); SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.beginTransaction(); db.beginTransaction();
try {
for (String jobId : jobIds) { for (String jobId : jobIds) {
String[] arg = new String[]{jobId}; String[] arg = new String[]{jobId};
@ -152,8 +157,10 @@ public class JobDatabase extends Database {
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally {
db.endTransaction(); db.endTransaction();
} }
}
public synchronized @NonNull List<ConstraintSpec> getAllConstraintSpecs() { public synchronized @NonNull List<ConstraintSpec> getAllConstraintSpecs() {
List<ConstraintSpec> constraints = new LinkedList<>(); List<ConstraintSpec> constraints = new LinkedList<>();