Java Code Examples for android.content.ContentProviderOperation#apply()

The following examples show how to use android.content.ContentProviderOperation#apply() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    Log_OC.d("FileContentProvider", "applying batch in provider " + this +
            " (temporary: " + isTemporary() + ")" );
    ContentProviderResult[] results = new ContentProviderResult[operations.size()];
    int i=0;

    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    db.beginTransaction();  // it's supposed that transactions can be nested
    try {
        for (ContentProviderOperation operation : operations) {
            results[i] = operation.apply(this, results, i);
            i++;
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    Log_OC.d("FileContentProvider", "applied batch in provider " + this);
    return results;
}
 
Example 2
@Override
@NonNull
public ContentProviderResult[] applyBatch(@NonNull final ArrayList<ContentProviderOperation> operations)
		throws OperationApplicationException {
	int ypCount = 0;
	int opCount = 0;
	final LogTransaction transaction = startTransaction(true);
	try {
		final int numOperations = operations.size();
		final ContentProviderResult[] results = new ContentProviderResult[numOperations];
		for (int i = 0; i < numOperations; i++) {
			if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
				throw new OperationApplicationException(
						"Too many content provider operations between yield points. " +
						"The maximum number of operations per yield point is " +
						MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
			}
			final ContentProviderOperation operation = operations.get(i);
			if (i > 0 && operation.isYieldAllowed()) {
				opCount = 0;
				try {
					if (yield(transaction)) {
						ypCount++;
					}
				} catch (RuntimeException re) {
					transaction.markYieldFailed();
					throw re;
				}
			}
			results[i] = operation.apply(this, results, i);
		}
		transaction.markSuccessful(true);
		return results;
	} finally {
		endTransaction(LogContract.Session.CONTENT_URI, true);
	}
}
 
Example 3
@Override
public ContentProviderResult[] applyBatch(
        ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    int ypCount = 0;
    int opCount = 0;
    mDb = mOpenHelper.getWritableDatabase();
    mDb.beginTransactionWithListener(this);
    try {
        mApplyingBatch.set(true);
        final int numOperations = operations.size();
        final ContentProviderResult[] results = new ContentProviderResult[numOperations];
        for (int i = 0; i < numOperations; i++) {
            if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
                throw new OperationApplicationException(
                        "Too many content provider operations between yield points. "
                                + "The maximum number of operations per yield point is "
                                + MAX_OPERATIONS_PER_YIELD_POINT, ypCount
                );
            }
            final ContentProviderOperation operation = operations.get(i);
            if (i > 0 && operation.isYieldAllowed()) {
                opCount = 0;
                boolean savedNotifyChange = mNotifyChange;
                if (mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
                    mDb = mOpenHelper.getWritableDatabase();
                    mNotifyChange = savedNotifyChange;
                    ypCount++;
                }
            }

            results[i] = operation.apply(this, results, i);
        }
        mDb.setTransactionSuccessful();
        return results;
    } finally {
        mApplyingBatch.set(false);
        mDb.endTransaction();
        onEndTransaction();
    }
}
 
Example 4
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException
{
	int ypCount = 0;
	int opCount = 0;
	boolean callerIsSyncAdapter = false;
	SQLiteDatabase db = mOpenHelper.getWritableDatabase();
	db.beginTransaction();
	try
	{
		mApplyingBatch.set(true);
		final int numOperations = operations.size();
		final ContentProviderResult[] results = new ContentProviderResult[numOperations];
		for (int i = 0; i < numOperations; i++)
		{
			if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT)
			{
				throw new OperationApplicationException("Too many content provider operations between yield points. "
					+ "The maximum number of operations per yield point is " + MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
			}
			final ContentProviderOperation operation = operations.get(i);
			if (!callerIsSyncAdapter && isCallerSyncAdapter(operation.getUri()))
			{
				callerIsSyncAdapter = true;
			}
			if (i > 0 && operation.isYieldAllowed())
			{
				opCount = 0;
				if (db.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY))
				{
					ypCount++;
				}
			}
			results[i] = operation.apply(this, results, i);
		}
		db.setTransactionSuccessful();
		return results;
	}
	finally
	{
		mApplyingBatch.set(false);
		db.endTransaction();
		onEndTransaction(callerIsSyncAdapter);
	}
}