/** {@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 Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (LOGV) Log.v(TAG, "query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");
    final SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    final ContentResolver contentResolver = getContext().getContentResolver();
    final int match = sUriMatcher.match(uri);
    switch (match) {
      default:
        {
          // Most cases are handled with simple SelectionBuilder
          final SelectionBuilder builder = buildExpandedSelection(uri, match);
          final Cursor c = builder.where(selection, selectionArgs).query(db, projection, sortOrder);
          c.setNotificationUri(contentResolver, uri);
          return c;
        }
      case SEARCH_SUGGEST:
        {
          final SelectionBuilder builder = new SelectionBuilder();

          // Adjust incoming query to become SQL text match
          selectionArgs[0] = selectionArgs[0] + "%";
          builder.table(Tables.SEARCH_SUGGEST);
          builder.where(selection, selectionArgs);
          builder.map(SearchManager.SUGGEST_COLUMN_QUERY, SearchManager.SUGGEST_COLUMN_TEXT_1);

          projection =
              new String[] {
                BaseColumns._ID,
                SearchManager.SUGGEST_COLUMN_TEXT_1,
                SearchManager.SUGGEST_COLUMN_QUERY
              };

          final String limit = uri.getQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT);
          final Cursor c =
              builder.query(db, projection, null, null, SearchSuggest.DEFAULT_SORT, limit);
          c.setNotificationUri(contentResolver, uri);
          return c;
        }
    }
  }
 /** {@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);
       }
   }
 }