@Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   final SQLiteDatabase db = dbHelper.getWritableDatabase();
   final int match = uriMatcher.match(uri);
   int rowsDeleted;
   switch (match) {
     case BOOK:
       rowsDeleted =
           db.delete(
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME,
               selection,
               selectionArgs);
       break;
     case AUTHOR:
       rowsDeleted =
           db.delete(
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.TABLE_NAME,
               selection,
               selectionArgs);
       break;
     case CATEGORY:
       rowsDeleted =
           db.delete(
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry
                   .TABLE_NAME,
               selection,
               selectionArgs);
       break;
     case BOOK_ID:
       rowsDeleted =
           db.delete(
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME,
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry._ID
                   + " = '"
                   + ContentUris.parseId(uri)
                   + "'",
               selectionArgs);
       break;
     default:
       throw new UnsupportedOperationException("Unknown uri: " + uri);
   }
   // Because a null deletes all rows
   if (selection == null || rowsDeleted != 0) {
     getContext().getContentResolver().notifyChange(uri, null);
   }
   return rowsDeleted;
 }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = dbHelper.getWritableDatabase();
    final int match = uriMatcher.match(uri);
    int rowsUpdated;
    switch (match) {
      case BOOK:
        rowsUpdated =
            db.update(
                com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME,
                values,
                selection,
                selectionArgs);
        break;
      case AUTHOR:
        rowsUpdated =
            db.update(
                com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.TABLE_NAME,
                values,
                selection,
                selectionArgs);
        break;
      case CATEGORY:
        rowsUpdated =
            db.update(
                com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry
                    .TABLE_NAME,
                values,
                selection,
                selectionArgs);
        break;

      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    if (rowsUpdated != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsUpdated;
  }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor retCursor;
    switch (uriMatcher.match(uri)) {
      case BOOK:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry
                        .TABLE_NAME,
                    projection,
                    selection,
                    selection == null ? null : selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case AUTHOR:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry
                        .TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case CATEGORY:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry
                        .TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case BOOK_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry
                        .TABLE_NAME,
                    projection,
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry._ID
                        + " = '"
                        + ContentUris.parseId(uri)
                        + "'",
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case AUTHOR_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry
                        .TABLE_NAME,
                    projection,
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry._ID
                        + " = '"
                        + ContentUris.parseId(uri)
                        + "'",
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case CATEGORY_ID:
        retCursor =
            dbHelper
                .getReadableDatabase()
                .query(
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry
                        .TABLE_NAME,
                    projection,
                    com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry._ID
                        + " = '"
                        + ContentUris.parseId(uri)
                        + "'",
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      case BOOK_FULLDETAIL:
        String[] bfd_projection = {
          com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
              + "."
              + AlexandriaContract.BookEntry._ID,
          com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TITLE,
          com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.SUBTITLE,
          com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.IMAGE_URL,
          com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.DESC,
          "group_concat(DISTINCT "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.AUTHOR
              + ") as "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.AUTHOR,
          "group_concat(DISTINCT "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry.CATEGORY
              + ") as "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry.CATEGORY
        };
        retCursor =
            bookFull.query(
                dbHelper.getReadableDatabase(),
                bfd_projection,
                com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
                    + "."
                    + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry._ID
                    + " = '"
                    + ContentUris.parseId(uri)
                    + "'",
                selectionArgs,
                com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
                    + "."
                    + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry._ID,
                null,
                sortOrder);
        break;
      case BOOK_FULL:
        String[] bf_projection = {
          com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TITLE,
          com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.IMAGE_URL,
          "group_concat(DISTINCT "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.AUTHOR
              + ") as "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry.AUTHOR,
          "group_concat(DISTINCT "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry.TABLE_NAME
              + "."
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry.CATEGORY
              + ") as "
              + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry.CATEGORY
        };
        retCursor =
            bookFull.query(
                dbHelper.getReadableDatabase(),
                bf_projection,
                null,
                selectionArgs,
                com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME
                    + "."
                    + com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry._ID,
                null,
                sortOrder);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    retCursor.setNotificationUri(getContext().getContentResolver(), uri);

    return retCursor;
  }
 @Override
 public Uri insert(Uri uri, ContentValues values) {
   final SQLiteDatabase db = dbHelper.getWritableDatabase();
   final int match = uriMatcher.match(uri);
   Uri returnUri;
   switch (match) {
     case BOOK:
       {
         long _id =
             db.insert(
                 com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.TABLE_NAME,
                 null,
                 values);
         if (_id > 0) {
           returnUri =
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry.buildBookUri(
                   _id);
         } else {
           throw new android.database.SQLException("Failed to insert row into " + uri);
         }
         getContext()
             .getContentResolver()
             .notifyChange(
                 com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.BookEntry
                     .buildFullBookUri(_id),
                 null);
         break;
       }
     case AUTHOR:
       {
         long _id =
             db.insert(
                 com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry
                     .TABLE_NAME,
                 null,
                 values);
         if (_id > 0)
           returnUri =
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.AuthorEntry
                   .buildAuthorUri(values.getAsLong("_id"));
         else throw new android.database.SQLException("Failed to insert row into " + uri);
         break;
       }
     case CATEGORY:
       {
         long _id =
             db.insert(
                 com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry
                     .TABLE_NAME,
                 null,
                 values);
         if (_id > 0)
           returnUri =
               com.awesome.byunghwa.app.alexandria.data.AlexandriaContract.CategoryEntry
                   .buildCategoryUri(values.getAsLong("_id"));
         else throw new android.database.SQLException("Failed to insert row into " + uri);
         break;
       }
     default:
       throw new UnsupportedOperationException("Unknown uri: " + uri);
   }
   return returnUri;
 }