public void executeMany(String sql, List<Object[]> list) { mMod = true; mDatabase.beginTransaction(); try { for (Object[] o : list) { mDatabase.execSQL(sql, o); } mDatabase.setTransactionSuccessful(); } finally { mDatabase.endTransaction(); } }
public synchronized void close(boolean save) { if (mDb != null) { try { SupportSQLiteDatabase db = mDb.getDatabase(); if (save) { db.beginTransaction(); try { save(); db.setTransactionSuccessful(); } finally { db.endTransaction(); } } else { if (db.inTransaction()) { db.endTransaction(); } } } catch (RuntimeException e) { AnkiDroidApp.sendExceptionReport(e, "closeDB"); } if (!mServer) { CompatHelper.getCompat().disableDatabaseWriteAheadLogging(mDb.getDatabase()); } mDb.close(); mDb = null; mMedia.close(); _closeLog(); Timber.i("Collection closed"); } }
throw new RuntimeException(e); } finally { mDb.getDatabase().endTransaction();
mCol.getDb().getDatabase().setTransactionSuccessful(); } finally { mCol.getDb().getDatabase().endTransaction();
private void answerCard(Collection col, Sched sched, Card cardToAnswer, int ease, long timeTaken) { try { DB db = col.getDb(); db.getDatabase().beginTransaction(); try { if (cardToAnswer != null) { if(timeTaken != -1){ cardToAnswer.setTimerStarted(Utils.now()-timeTaken/1000); } sched.answerCard(cardToAnswer, ease); } db.getDatabase().setTransactionSuccessful(); } finally { db.getDatabase().endTransaction(); } } catch (RuntimeException e) { Timber.e(e, "answerCard - RuntimeException on answering card"); AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard"); return; } }
private void buryOrSuspendCard(Collection col, Sched sched, Card card, boolean bury) { try { DB db = col.getDb(); db.getDatabase().beginTransaction(); try { if (card != null) { if(bury) { // bury sched.buryCards(new long[] {card.getId()}); } else { // suspend sched.suspendCards(new long[] {card.getId()}); } } db.getDatabase().setTransactionSuccessful(); } finally { db.getDatabase().endTransaction(); } } catch (RuntimeException e) { Timber.e(e, "buryOrSuspendCard - RuntimeException on burying or suspending card"); AnkiDroidApp.sendExceptionReport(e, "doInBackgroundBurySuspendCard"); return; } }
private void _import() { mDecks = new HashMap<>(); try { // Use transactions for performance and rollbacks in case of error mDst.getDb().getDatabase().beginTransaction(); mDst.getMedia().getDb().getDatabase().beginTransaction(); if (!TextUtils.isEmpty(mDeckPrefix)) { long id = mDst.getDecks().id(mDeckPrefix); mDst.getDecks().select(id); } _prepareTS(); _prepareModels(); _importNotes(); _importCards(); _importStaticMedia(); publishProgress(100, 100, 25); _postImport(); publishProgress(100, 100, 50); mDst.getDb().getDatabase().setTransactionSuccessful(); mDst.getMedia().getDb().getDatabase().setTransactionSuccessful(); } finally { mDst.getDb().getDatabase().endTransaction(); mDst.getMedia().getDb().getDatabase().endTransaction(); } mDst.getDb().execute("vacuum"); publishProgress(100, 100, 65); mDst.getDb().execute("analyze"); publishProgress(100, 100, 75); }
col.getDb().getDatabase().endTransaction();
return result; } finally { sqldb.endTransaction();
private TaskData doInBackgroundAddNote(TaskData[] params) { Timber.d("doInBackgroundAddNote"); Note note = params[0].getNote(); Collection col = CollectionHelper.getInstance().getCol(mContext); try { DB db = col.getDb(); db.getDatabase().beginTransaction(); try { publishProgress(new TaskData(col.addNote(note))); db.getDatabase().setTransactionSuccessful(); } finally { db.getDatabase().endTransaction(); } } catch (RuntimeException e) { Timber.e(e, "doInBackgroundAddNote - RuntimeException on adding fact"); AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAddNote"); return new TaskData(false); } return new TaskData(true); }
db.getDatabase().setTransactionSuccessful(); } finally { db.getDatabase().endTransaction();
private TaskData doInBackgroundUpdateNotes(TaskData[] params) { Timber.d("doInBackgroundUpdateNotes"); // Save the note Collection col = CollectionHelper.getInstance().getCol(mContext); Object[] data = params[0].getObjArray(); Card[] cards = (Card[]) data[0]; try { col.getDb().getDatabase().beginTransaction(); try { for (Card card : cards) { Note note = card.note(); // TODO: undo integration note.flush(); // flush card too, in case, did has been changed card.flush(); publishProgress(new TaskData(card, note.stringTags())); } col.getDb().getDatabase().setTransactionSuccessful(); } finally { col.getDb().getDatabase().endTransaction(); } } catch (RuntimeException e) { Timber.e(e, "doInBackgroundUpdateNote - RuntimeException on updating fact"); AnkiDroidApp.sendExceptionReport(e, "doInBackgroundUpdateNote"); return new TaskData(false); } return new TaskData(true); }
col.getDb().getDatabase().endTransaction();
col.getDb().getDatabase().setTransactionSuccessful(); } finally { col.getDb().getDatabase().endTransaction();
col.getDb().getDatabase().setTransactionSuccessful(); } finally { col.getDb().getDatabase().endTransaction();
database.endTransaction();
database.endTransaction();
database.endTransaction();