Пример #1
0
  private Cursor getReviewsByMovieId(Uri uri, String[] projection, String sortOrder) {
    String movieId = MoviesContract.ReviewEntry.getMovieIdFromUri(uri);

    String[] selectionArgs = new String[] {movieId};
    String selection = sMovieSelection;

    return sReviewByMovieIdQueryBuilder.query(
        moviesDbHelper.getReadableDatabase(),
        projection,
        selection,
        selectionArgs,
        null,
        null,
        sortOrder);
  }
 @Override
 public Cursor query(
     Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
   Cursor cursor;
   SQLiteDatabase db = mOpenHelper.getReadableDatabase();
   switch (sUriMatcher.match(uri)) {
     case MOVIES_LIST:
       cursor =
           db.query(
               MoviesContract.MoviesEntry.TABLE_NAME,
               projection,
               selection,
               selectionArgs,
               null,
               null,
               sortOrder);
       break;
     case TRAILERS:
       cursor =
           db.query(
               MoviesContract.TrailersEntry.TABLE_NAME,
               projection,
               selection,
               selectionArgs,
               null,
               null,
               null);
       break;
     case REVIEWS:
       cursor =
           db.query(
               MoviesContract.ReviewsEntry.TABLE_NAME,
               projection,
               selection,
               selectionArgs,
               null,
               null,
               null);
       break;
     default:
       throw new UnsupportedOperationException("Unknown uri: " + uri);
   }
   cursor.setNotificationUri(getContext().getContentResolver(), uri);
   return cursor;
 }
Пример #3
0
  @Nullable
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor retCursor;
    switch (sUriMatcher.match(uri)) {
      case MOVIE:
        {
          retCursor =
              moviesDbHelper
                  .getReadableDatabase()
                  .query(
                      MoviesContract.MovieEntry.TABLE_NAME,
                      projection,
                      selection,
                      selectionArgs,
                      null,
                      null,
                      sortOrder);
          break;
        }
      case MOVIE_WITH_ID:
        {
          String movieId = MoviesContract.ReviewEntry.getMovieIdFromUri(uri);

          selectionArgs = new String[] {movieId};
          selection = sMovieSelection;
          retCursor =
              moviesDbHelper
                  .getReadableDatabase()
                  .query(
                      MoviesContract.MovieEntry.TABLE_NAME,
                      projection,
                      selection,
                      selectionArgs,
                      null,
                      null,
                      sortOrder);
          break;
        }
      case TRAILER:
        {
          retCursor = getTrailersByMovieId(uri, projection, sortOrder);
          break;
        }
      case REVIEW:
        {
          retCursor = getReviewsByMovieId(uri, projection, sortOrder);
          break;
        }
      case REVIEW_WITH_ID:
        {
          String movieId = MoviesContract.ReviewEntry.getMovieIdFromUri(uri);
          retCursor =
              sReviewByMovieIdQueryBuilder.query(
                  moviesDbHelper.getReadableDatabase(),
                  projection,
                  sMovieSelection,
                  new String[] {movieId},
                  null,
                  null,
                  sortOrder);
          break;
        }
      case TRAILER_WITH_ID:
        {
          String movieId = MoviesContract.TrailerEntry.getMovieIdFromUri(uri);
          retCursor =
              sTrailerByMovieIdQueryBuilder.query(
                  moviesDbHelper.getReadableDatabase(),
                  projection,
                  sMovieSelection,
                  new String[] {movieId},
                  null,
                  null,
                  sortOrder);
          break;
        }
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    retCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return retCursor;
  }