/** * Run the given Runnable inside a database transaction. If you except a result, consider callInTx. */ public void runInTx(Runnable runnable) { db.beginTransaction(); try { runnable.run(); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
/** * Calls the given Callable inside a database transaction and returns the result of the Callable. If you don't * except a result, consider runInTx. */ public <V> V callInTx(Callable<V> callable) throws Exception { db.beginTransaction(); try { V result = callable.call(); db.setTransactionSuccessful(); return result; } finally { db.endTransaction(); } }
@SuppressWarnings("unchecked") private void executeTransactionCallable(AsyncOperation operation) throws Exception { Database db = operation.getDatabase(); db.beginTransaction(); try { operation.result = ((Callable<Object>) operation.parameter).call(); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
private void executeTransactionRunnable(AsyncOperation operation) { Database db = operation.getDatabase(); db.beginTransaction(); try { ((Runnable) operation.parameter).run(); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
/** * Like {@link #callInTx(Callable)} but does not require Exception handling (rethrows an Exception as a runtime * DaoException). */ public <V> V callInTxNoException(Callable<V> callable) { db.beginTransaction(); try { V result; try { result = callable.call(); } catch (Exception e) { throw new DaoException("Callable failed", e); } db.setTransactionSuccessful(); return result; } finally { db.endTransaction(); } }
public static int executeSqlStatementsInTx(Database db, String[] statements) { db.beginTransaction(); try { int count = executeSqlStatements(db, statements); db.setTransactionSuccessful(); return count; } finally { db.endTransaction(); } }
db.endTransaction(); } catch (RuntimeException e) { DaoLog.i("Async transaction could not be ended, success so far was: " + success, e);
db.setTransactionSuccessful(); } finally { db.endTransaction();
private long executeInsert(T entity, DatabaseStatement stmt, boolean setKeyAndAttach) { long rowId; if (db.isDbLockedByCurrentThread()) { rowId = insertInsideTx(entity, stmt); } else { // Do TX to acquire a connection before locking the stmt to avoid deadlocks db.beginTransaction(); try { rowId = insertInsideTx(entity, stmt); db.setTransactionSuccessful(); } finally { db.endTransaction(); } } if (setKeyAndAttach) { updateKeyAfterInsertAndAttach(entity, rowId, true); } return rowId; }
/** Deletes an entity with the given PK from the database. Currently, only single value PK entities are supported. */ public void deleteByKey(K key) { assertSinglePk(); DatabaseStatement stmt = statements.getDeleteStatement(); if (db.isDbLockedByCurrentThread()) { synchronized (stmt) { deleteByKeyInsideSynchronized(key, stmt); } } else { // Do TX to acquire a connection before locking the stmt to avoid deadlocks db.beginTransaction(); try { synchronized (stmt) { deleteByKeyInsideSynchronized(key, stmt); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } if (identityScope != null) { identityScope.remove(key); } }
public void update(T entity) { assertSinglePk(); DatabaseStatement stmt = statements.getUpdateStatement(); if (db.isDbLockedByCurrentThread()) { synchronized (stmt) { if (isStandardSQLite) { updateInsideSynchronized(entity, (SQLiteStatement) stmt.getRawStatement(), true); } else { updateInsideSynchronized(entity, stmt, true); } } } else { // Do TX to acquire a connection before locking the stmt to avoid deadlocks db.beginTransaction(); try { synchronized (stmt) { updateInsideSynchronized(entity, stmt, true); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } }
/** * Deletes all matching entities without detaching them from the identity scope (aka session/cache). Note that this * method may lead to stale entity objects in the session cache. Stale entities may be returned when loaded by * their * primary key, but not using queries. */ public void executeDeleteWithoutDetachingEntities() { checkThread(); Database db = dao.getDatabase(); if (db.isDbLockedByCurrentThread()) { dao.getDatabase().execSQL(sql, parameters); } else { // Do TX to acquire a connection before locking this to avoid deadlocks // Locking order as described in AbstractDao db.beginTransaction(); try { dao.getDatabase().execSQL(sql, parameters); db.setTransactionSuccessful(); } finally { db.endTransaction(); } } }
} finally { try { db.endTransaction(); } catch (RuntimeException e) { if (txEx != null) {
/** * Run the given Runnable inside a database transaction. If you except a result, consider callInTx. */ public void runInTx(Runnable runnable) { db.beginTransaction(); try { runnable.run(); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
/** * Calls the given Callable inside a database transaction and returns the result of the Callable. If you don't * except a result, consider runInTx. */ public <V> V callInTx(Callable<V> callable) throws Exception { db.beginTransaction(); try { V result = callable.call(); db.setTransactionSuccessful(); return result; } finally { db.endTransaction(); } }
private void executeTransactionRunnable(AsyncOperation operation) { Database db = operation.getDatabase(); db.beginTransaction(); try { ((Runnable) operation.parameter).run(); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
@SuppressWarnings("unchecked") private void executeTransactionCallable(AsyncOperation operation) throws Exception { Database db = operation.getDatabase(); db.beginTransaction(); try { operation.result = ((Callable<Object>) operation.parameter).call(); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
public static int executeSqlStatementsInTx(Database db, String[] statements) { db.beginTransaction(); try { int count = executeSqlStatements(db, statements); db.setTransactionSuccessful(); return count; } finally { db.endTransaction(); } }