@Override public int delete(Uri uri, String selection, String[] selectionArgs) { SelectionBuilder builder = new SelectionBuilder(); final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); final int match = sUriMatcher.match(uri); int count; switch (match) { case ROUTE_EMOTES: count = builder .table(EmotesContract.Emote.TABLE_NAME) .where(selection, selectionArgs) .delete(db); break; case ROUTE_EMOTES_ID: String id = uri.getLastPathSegment(); count = builder .table(EmotesContract.Emote.TABLE_NAME) .where(EmotesContract.Emote._ID + "=?", id) .where(selection, selectionArgs) .delete(db); break; default: throw new UnsupportedOperationException("Unknown uri: " + uri); } // Send broadcast to registered ContentObservers, to refresh UI. Context ctx = getContext(); assert ctx != null; ctx.getContentResolver().notifyChange(uri, null, false); return count; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteDatabase db = mDatabaseHelper.getReadableDatabase(); SelectionBuilder builder = new SelectionBuilder(); Context ctx = getContext(); assert ctx != null; Cursor c; int uriMatch = sUriMatcher.match(uri); switch (uriMatch) { case ROUTE_EMOTES_ID: // Return a single entry, by ID String id = uri.getLastPathSegment(); builder.where(EmotesContract.Emote._ID + "=?", id); case ROUTE_EMOTES: // Return all known entries builder.table(EmotesContract.Emote.TABLE_NAME).where(selection, selectionArgs); c = builder.query(db, projection, sortOrder); // Note: Notification URI must be manually set here for loaders to // correctly register ContentObservers. c.setNotificationUri(ctx.getContentResolver(), uri); return c; case ROUTE_EMOTES_DISTINCT: // Return all known entries builder.table(EmotesContract.Emote.TABLE_NAME).where(selection, selectionArgs); c = builder.query(true, db, projection, sortOrder); // Note: Notification URI must be manually set here for loaders to // correctly register ContentObservers. c.setNotificationUri(ctx.getContentResolver(), uri); return c; default: throw new UnsupportedOperationException("Unknown uri: " + uri); } }