/** {@inheritDoc} */ @Override public int delete(Uri uri, String selection, String[] selectionArgs) { if (LOGV) Log.v(TAG, "delete(uri=" + uri + ")"); final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); final SelectionBuilder builder = buildSimpleSelection(uri); int retVal = builder.where(selection, selectionArgs).delete(db); getContext().getContentResolver().notifyChange(uri, null); return retVal; }
/** * Apply the given set of {@link ContentProviderOperation}, executing inside a {@link * SQLiteDatabase} transaction. All changes will be rolled back if any single one fails. */ @Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { final int numOperations = operations.size(); final ContentProviderResult[] results = new ContentProviderResult[numOperations]; for (int i = 0; i < numOperations; i++) { results[i] = operations.get(i).apply(this, results, i); } db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } }
/** {@inheritDoc} */ @Override public Uri insert(Uri uri, ContentValues values) { if (LOGV) Log.v(TAG, "insert(uri=" + uri + ", values=" + values.toString() + ")"); final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); final int match = sUriMatcher.match(uri); switch (match) { case BLOCKS: { db.insertOrThrow(Tables.BLOCKS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Blocks.buildBlockUri(values.getAsString(Blocks.BLOCK_ID)); } case TRACKS: { db.insertOrThrow(Tables.TRACKS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Tracks.buildTrackUri(values.getAsString(Tracks.TRACK_ID)); } case ROOMS: { db.insertOrThrow(Tables.ROOMS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Rooms.buildRoomUri(values.getAsString(Rooms.ROOM_ID)); } case SESSIONS: { db.insertOrThrow(Tables.SESSIONS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Sessions.buildSessionUri(values.getAsString(Sessions.SESSION_ID)); } case SESSIONS_ID_SPEAKERS: { db.insertOrThrow(Tables.SESSIONS_SPEAKERS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Speakers.buildSpeakerUri(values.getAsString(SessionsSpeakers.SPEAKER_ID)); } case SESSIONS_ID_TAGS: { db.insertOrThrow(Tables.SESSIONS_TAGS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Tags.buildTagUri(values.getAsString(SessionsTags.TAG_ID)); } case SPEAKERS: { db.insertOrThrow(Tables.SPEAKERS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Speakers.buildSpeakerUri(values.getAsString(Speakers.SPEAKER_ID)); } case TAGS: { db.insertOrThrow(Tables.TAGS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Tags.buildTagUri(values.getAsString(Tags.TAG_ID)); } case SESSION_TYPES: { db.insertOrThrow(Tables.SESSION_TYPES, null, values); getContext().getContentResolver().notifyChange(uri, null); return SessionTypes.buildSessionTypeUri(values.getAsString(SessionTypes.SESSION_TYPE_ID)); } case TWEETS: { db.insertOrThrow(Tables.TWEETS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Tweets.buildTweetUri(values.getAsString(Tweets.TWEET_ID)); } case NEWS: { db.insertOrThrow(Tables.NEWS, null, values); getContext().getContentResolver().notifyChange(uri, null); return News.buildNewsUri(values.getAsString(News.NEWS_ID)); } case PARLEYS: { db.insertOrThrow(Tables.PARLEYS_PRESENTATIONS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Sessions.buildSessionUri(values.getAsString(ParleysPresentations.PRESENTATION_ID)); } case PARLEYS_ID_TAGS: { db.insertOrThrow(Tables.PARLEYS_PRESENTATIONS_TAGS, null, values); getContext().getContentResolver().notifyChange(uri, null); return Tags.buildTagUri(values.getAsString(ParleysPresentationsTags.TAG_ID)); } case SEARCH_SUGGEST: { db.insertOrThrow(Tables.SEARCH_SUGGEST, null, values); getContext().getContentResolver().notifyChange(uri, null); return SearchSuggest.CONTENT_URI; } default: { throw new UnsupportedOperationException("Unknown uri: " + uri); } } }