mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
another solution for executeAsATransaction
This commit is contained in:
parent
d71d55e1da
commit
724d6fd313
3 changed files with 14 additions and 6 deletions
|
@ -50,13 +50,21 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
protected void executeAsATransaction(Runnable actions) {
|
||||
myDatabase.execSQL("BEGIN IMMEDIATE");
|
||||
boolean transactionStarted = false;
|
||||
try {
|
||||
myDatabase.beginTransaction();
|
||||
transactionStarted = true;
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
try {
|
||||
actions.run();
|
||||
} catch (Throwable t) {
|
||||
myDatabase.execSQL("ROLLBACK");
|
||||
if (transactionStarted) {
|
||||
myDatabase.setTransactionSuccessful();
|
||||
}
|
||||
} finally {
|
||||
myDatabase.execSQL("END");
|
||||
if (transactionStarted) {
|
||||
myDatabase.endTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue