@Override public boolean isDbLockedByCurrentThread() { return delegate.isDbLockedByCurrentThread(); }
public SqliteDatabaseAssert isNotLockedByCurrentThread() { isNotNull(); assertThat(actual.isDbLockedByCurrentThread()) // .overridingErrorMessage("Expected DB to not be locked but current thread but was.") // .isFalse(); return this; }
public SqliteDatabaseAssert isLockedByCurrentThread() { isNotNull(); assertThat(actual.isDbLockedByCurrentThread()) // .overridingErrorMessage("Expected DB to be locked by current thread but was not.") // .isTrue(); return this; }
@Override public boolean isDbLockedByCurrentThread() { return db.isDbLockedByCurrentThread(); }
@Override public boolean isDbLockedByCurrentThread() { return delegate.isDbLockedByCurrentThread(); }
@Override public boolean isDbLockedByCurrentThread() { return delegate.isDbLockedByCurrentThread(); }
@Override public boolean isDbLockedByCurrentThread() { return mDelegate.isDbLockedByCurrentThread(); }
public boolean isDbLockedByCurrentThread() { return database.isDbLockedByCurrentThread(); }
/** * Close the connection to the database to avoid database leaks. */ public void destroy() { if (this.database != null && this.database.isDbLockedByCurrentThread()) { this.database.close(); } }
/** * <p> * return true if database is already opened. * </p> * * @return true if database is opened, otherwise false */ public boolean isOpen() { return database != null && database.isOpen() && database.isDbLockedByCurrentThread(); }
/** * <p> * return true if database is already opened. * </p> * * @return true if database is opened, otherwise false */ public boolean isOpen() { return database != null && database.isOpen() && database.isDbLockedByCurrentThread(); }
/** * <p> * return true if database is already opened in write mode. * </p> * * @return true if database is opened, otherwise false */ public boolean isOpenInWriteMode() { // return database != null && database.isOpen() && // !database.isReadOnly() && database.isDbLockedByCurrentThread(); return database != null && !database.isReadOnly() && database.isDbLockedByCurrentThread(); }
/** * <p> * return true if database is already opened in write mode. * </p> * * @return true if database is opened, otherwise false */ public boolean isOpenInWriteMode() { // return database != null && database.isOpen() && // !database.isReadOnly() && database.isDbLockedByCurrentThread(); return database != null && !database.isReadOnly() && database.isDbLockedByCurrentThread(); }
public SqliteDatabaseAssert isNotLockedByCurrentThread() { isNotNull(); assertThat(actual.isDbLockedByCurrentThread()) // .overridingErrorMessage("Expected DB to not be locked but current thread but was.") // .isFalse(); return this; }
public SqliteDatabaseAssert isLockedByCurrentThread() { isNotNull(); assertThat(actual.isDbLockedByCurrentThread()) // .overridingErrorMessage("Expected DB to be locked by current thread but was not.") // .isTrue(); return this; }
/** * 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(); SQLiteDatabase 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(); SQLiteStatement stmt = statements.getUpdateStatement(); if (db.isDbLockedByCurrentThread()) { synchronized (stmt) { 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, SQLiteStatement stmt) { long rowId; if (db.isDbLockedByCurrentThread()) { synchronized (stmt) { bindValues(stmt, entity); rowId = stmt.executeInsert(); } } else { // Do TX to acquire a connection before locking the stmt to avoid deadlocks db.beginTransaction(); try { synchronized (stmt) { bindValues(stmt, entity); rowId = stmt.executeInsert(); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } 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(); SQLiteStatement 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); } }
/** * Insert an entity into the table associated with a concrete DAO <b>without</b> setting key property. Warning: This * may be faster, but the entity should not be used anymore. The entity also won't be attached to identy scope. * * @return row ID of newly inserted entity */ public long insertWithoutSettingPk(T entity) { SQLiteStatement stmt = statements.getInsertStatement(); long rowId; if (db.isDbLockedByCurrentThread()) { synchronized (stmt) { bindValues(stmt, entity); rowId = stmt.executeInsert(); } } else { // Do TX to acquire a connection before locking the stmt to avoid deadlocks db.beginTransaction(); try { synchronized (stmt) { bindValues(stmt, entity); rowId = stmt.executeInsert(); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } return rowId; }