Search in sources :

Example 11 with DatabaseStatement

use of org.greenrobot.greendao.database.DatabaseStatement in project greenDAO by greenrobot.

the class AbstractDao method deleteInTxInternal.

private void deleteInTxInternal(Iterable<T> entities, Iterable<K> keys) {
    assertSinglePk();
    DatabaseStatement stmt = statements.getDeleteStatement();
    List<K> keysToRemoveFromIdentityScope = null;
    db.beginTransaction();
    try {
        synchronized (stmt) {
            if (identityScope != null) {
                identityScope.lock();
                keysToRemoveFromIdentityScope = new ArrayList<K>();
            }
            try {
                if (entities != null) {
                    for (T entity : entities) {
                        K key = getKeyVerified(entity);
                        deleteByKeyInsideSynchronized(key, stmt);
                        if (keysToRemoveFromIdentityScope != null) {
                            keysToRemoveFromIdentityScope.add(key);
                        }
                    }
                }
                if (keys != null) {
                    for (K key : keys) {
                        deleteByKeyInsideSynchronized(key, stmt);
                        if (keysToRemoveFromIdentityScope != null) {
                            keysToRemoveFromIdentityScope.add(key);
                        }
                    }
                }
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        db.setTransactionSuccessful();
        if (keysToRemoveFromIdentityScope != null && identityScope != null) {
            identityScope.remove(keysToRemoveFromIdentityScope);
        }
    } finally {
        db.endTransaction();
    }
}
Also used : DatabaseStatement(org.greenrobot.greendao.database.DatabaseStatement)

Aggregations

DatabaseStatement (org.greenrobot.greendao.database.DatabaseStatement)11 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 Database (org.greenrobot.greendao.database.Database)1