Example usage for android.content ContentProviderOperation isYieldAllowed

List of usage examples for android.content ContentProviderOperation isYieldAllowed

Introduction

In this page you can find the example usage for android.content ContentProviderOperation isYieldAllowed.

Prototype

public boolean isYieldAllowed() 

Source Link

Document

Returns true if the operation allows yielding the database to other transactions if the database is contended.

Usage

From source file:com.manning.androidhacks.hack043.provider.SQLiteContentProvider.java

@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    mDb = mOpenHelper.getWritableDatabase();
    mDb.beginTransactionWithListener(this);
    try {/*from   w w w  .  j a v a2s . c om*/
        mApplyingBatch.set(true);
        final int numOperations = operations.size();
        final ContentProviderResult[] results = new ContentProviderResult[numOperations];
        for (int i = 0; i < numOperations; i++) {
            final ContentProviderOperation operation = operations.get(i);
            if (i > 0 && operation.isYieldAllowed()) {
                mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY);
            }
            results[i] = operation.apply(this, results, i);
        }
        mDb.setTransactionSuccessful();
        return results;
    } finally {
        mApplyingBatch.set(false);
        mDb.endTransaction();
        onEndTransaction();
    }
}