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