Example usage for android.content ContentProviderOperation apply

List of usage examples for android.content ContentProviderOperation apply

Introduction

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

Prototype

public ContentProviderResult apply(ContentProvider provider, ContentProviderResult[] backRefs, int numBackRefs)
        throws OperationApplicationException 

Source Link

Document

Applies this operation using the given provider.

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 ww  w  .  j a v a 2s .  c o  m
        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();
    }
}