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

The following are Jave code examples for showing how to use apply() of the android.content.ContentProviderOperation class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Phoenix-for-VK   File: MessengerContentProvider.java   Source Code and License Vote up 5 votes
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) {
    if(Utils.safeIsEmpty(operations)) {
        return new ContentProviderResult[0];
    }

    validateUris(operations);

    int aid = extractAidFromUri(operations.get(0).getUri());

    ContentProviderResult[] result = new ContentProviderResult[operations.size()];
    int i = 0;
    // Opens the database object in "write" mode.
    SQLiteDatabase db = getDbHelper(aid).getWritableDatabase();
    // Begin a transaction
    db.beginTransaction();
    try {
        for (ContentProviderOperation operation : operations) {
            // Chain the result for back references
            result[i++] = operation.apply(this, result, i);
        }

        db.setTransactionSuccessful();
    } catch (OperationApplicationException e) {
        Logger.d("DATABASE", "batch failed: " + e.getLocalizedMessage());
    } finally {
        db.endTransaction();
    }

    return result;
}