1
0
Fork 0
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:
Nikolay Pultsin 2011-07-23 10:57:23 +01:00
parent d71d55e1da
commit 724d6fd313
3 changed files with 14 additions and 6 deletions

View file

@ -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();
}
}
}