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,14 +87,17 @@ public class JobDatabase extends Database {
db.beginTransaction(); db.beginTransaction();
for (FullSpec fullSpec : fullSpecs) { try {
insertJobSpec(db, fullSpec.getJobSpec()); for (FullSpec fullSpec : fullSpecs) {
insertConstraintSpecs(db, fullSpec.getConstraintSpecs()); insertJobSpec(db, fullSpec.getJobSpec());
insertDependencySpecs(db, fullSpec.getDependencySpecs()); insertConstraintSpecs(db, fullSpec.getConstraintSpecs());
} insertDependencySpecs(db, fullSpec.getDependencySpecs());
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
db.endTransaction(); } finally {
db.endTransaction();
}
} }
public synchronized @NonNull List<JobSpec> getAllJobSpecs() { public synchronized @NonNull List<JobSpec> getAllJobSpecs() {
@ -142,17 +145,21 @@ public class JobDatabase extends Database {
SQLiteDatabase db = databaseHelper.getWritableDatabase(); SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.beginTransaction(); db.beginTransaction();
for (String jobId : jobIds) {
String[] arg = new String[]{jobId};
db.delete(Jobs.TABLE_NAME, Jobs.JOB_SPEC_ID + " = ?", arg); try {
db.delete(Constraints.TABLE_NAME, Constraints.JOB_SPEC_ID + " = ?", arg); for (String jobId : jobIds) {
db.delete(Dependencies.TABLE_NAME, Dependencies.JOB_SPEC_ID + " = ?", arg); String[] arg = new String[]{jobId};
db.delete(Dependencies.TABLE_NAME, Dependencies.DEPENDS_ON_JOB_SPEC_ID + " = ?", arg);
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<ConstraintSpec> getAllConstraintSpecs() { public synchronized @NonNull List<ConstraintSpec> getAllConstraintSpecs() {