@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { if (sURIMatcher.match(uri) == GRAVES) { final SQLiteDatabase db = dbHelper.getWritableDatabase(); getContext().getContentResolver().notifyChange(uri, null); return db.update(DepartedTableHelper.TABLE_NAME, values, selection, selectionArgs); } else { throw new IllegalArgumentException("Unknown uri: " + uri); } }
@Override public Uri insert(Uri uri, ContentValues values) { if (sURIMatcher.match(uri) == GRAVES) { final SQLiteDatabase db = dbHelper.getWritableDatabase(); long id = db.insert(DepartedTableHelper.TABLE_NAME, null, values); Uri insertUri = ContentUris.withAppendedId(CONTENT_URI, id); getContext().getContentResolver().notifyChange(insertUri, null); return insertUri; } else { throw new IllegalArgumentException("Unknown uri: " + uri); } }
@Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { SQLiteDatabase db = dbHelper.getWritableDatabase(); db.beginTransaction(); try { ContentProviderResult[] results = super.applyBatch(operations); db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { int match = sURIMatcher.match(uri); SQLiteDatabase db = dbHelper.getWritableDatabase(); int count = 0; switch (match) { case GRAVES: StringBuilder builder = new StringBuilder(); String[] whereArgs = createWhere(uri, builder); count = db.delete(DepartedTableHelper.TABLE_NAME, builder.toString(), whereArgs); getContext().getContentResolver().notifyChange(uri, null); break; case GRAVE_URI_ID: long departedId = ContentUris.parseId(uri); count = db.delete(DepartedTableHelper.TABLE_NAME, Columns._ID + " = " + departedId, null); getContext().getContentResolver().notifyChange(uri, null); break; } return count; }