Java Code Examples for android.database.sqlite.SQLiteDatabase.yieldIfContendedSafely()

The following are Jave code examples for showing how to use yieldIfContendedSafely() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: aos-MediaLib   File: VideoProvider.java   View Source Code Vote up 5 votes
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    if (DBG) Log.d(TAG, "bulkInsert " + uri);
    int match = URI_MATCHER.match(uri);

    // let ScraperProvider handle that
    if (ScraperProvider.handles(match))
        return mScraperProvider.bulkInsert(uri, values);

    if (match != -1) {
        int result = 0;
        mVobHandler.onBeginTransaction();
        SQLiteDatabase db = mDbHolder.get();
        db.beginTransactionNonExclusive();
        try {
            int numValues = values.length;
            int yield = 100;
            for (int i = 0; i < numValues; i++) {
                insert(uri, values[i]);
                if (yield-- < 0) {
                    yield = 100;
                    db.yieldIfContendedSafely();
                }
            }
            result = numValues;
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
            mVobHandler.onEndTransaction();
        }
        if (result > 0)
            mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
        return result;
    }
    return 0;
}
 
Example 2
Project: aos-MediaLib   File: VideoProvider.java   View Source Code Vote up 5 votes
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
        throws OperationApplicationException {
    if (DBG) Log.d(TAG, "applyBatch");
    ContentProviderResult[] result = null;
    SQLiteDatabase db = mDbHolder.get();
    mVobHandler.onBeginTransaction();
    db.beginTransactionNonExclusive();
    try {
        final int numOperations = operations.size();
        final ContentProviderResult[] results = new ContentProviderResult[numOperations];
        int yield = 100;
        for (int i = 0; i < numOperations; i++) {
            results[i] = operations.get(i).apply(this, results, i);
            if (yield-- < 0) {
                yield = 100;
                db.yieldIfContendedSafely();
            }
        }
        result = results;
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        mVobHandler.onEndTransaction();
    }
    if (result != null) {
        mCr.notifyChange(VideoStore.ALL_CONTENT_URI, null);
        mCr.notifyChange(ScraperStore.ALL_CONTENT_URI, null);
    }
    return result;
}