@Override
  public Uri insert(Uri uri, ContentValues values) {
    // Find matching path.
    final int match = sUriMatcher.match(uri);

    // Avoid the expensive string concatenation below if not loggable
    if (BuildConfig.DEBUG) {
      Log.v(TAG, "insert(uri=" + uri + ", values=" + values.toString() + ")");
    }

    // Get the database and run the insert
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    switch (match) {
      case PAYMENTS:
        {
          db.insertOrThrow(AppDatabase.Tables.PAYMENTS, null, values);
          getContext().getContentResolver().notifyChange(uri, null);
          // Generate Uri with remote id.
          return AppContract.Payments.buildUri(values.getAsString(AppContract.Payments.ID));
        }
      default:
        {
          throw new UnsupportedOperationException("Unknown insert uri: " + uri);
        }
    }
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    // Find matching path.
    final int match = sUriMatcher.match(uri);

    // Avoid the expensive string concatenation below if not loggable
    if (BuildConfig.DEBUG) {
      Log.v(TAG, "update(uri=" + uri + ", values=" + values.toString() + ")");
    }

    // Create a selection builder from Uri.
    final SelectionBuilder builder = buildSimpleSelection(uri, match);

    // Get the database and run the update
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count = builder.where(selection, selectionArgs).update(db, values);
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
 /** Transactional implementation of applyBatch. */
 @Override
 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
     throws OperationApplicationException {
   ContentProviderResult[] result = new ContentProviderResult[operations.size()];
   // Opens the database object in "write" mode.
   SQLiteDatabase db = mOpenHelper.getWritableDatabase();
   // Begin a transaction
   db.beginTransaction();
   try {
     int i = 0;
     for (ContentProviderOperation operation : operations) {
       // Chain the result for back references
       result[i++] = operation.apply(this, result, i);
     }
     db.setTransactionSuccessful();
   } finally {
     db.endTransaction();
   }
   return result;
 }