Java Code Examples for android.content.ContentProviderOperation#isYieldAllowed()
The following examples show how to use
android.content.ContentProviderOperation#isYieldAllowed() .
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 check out the related API usage on the sidebar.
Example 1
Source File: LocalLogContentProvider.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 2
Source File: SQLiteContentProvider.java From Android-Next with Apache License 2.0 | 4 votes |
@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 3
Source File: SQLiteContentProvider.java From opentasks-provider with Apache License 2.0 | 4 votes |
@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); } }