コード例 #1
0
ファイル: VizProvider.java プロジェクト: elevenfive/Viz
  /** {@inheritDoc} */
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    Log.v("delete(uri=" + uri + ")");

    final int match = getUriMatcher().match(uri);
    switch (match) {
      case RESOURCES_ID:
        deleteResourceSideEffect(uri);
        break;
      case DOWNLOADS_ID:
        deleteDownloadSideEffect(uri);
        break;
      default:
        break;
    }

    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final SelectionBuilder builder = buildSimpleSelection(uri);
    int retVal;
    synchronized (mutex) {
      retVal = builder.where(selection, selectionArgs).delete(db);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return retVal;
  }
コード例 #2
0
ファイル: VizProvider.java プロジェクト: elevenfive/Viz
  /** {@inheritDoc} */
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    Log.v("update(uri=" + uri + ")");

    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final SelectionBuilder builder = buildSimpleSelection(uri);
    int rowsChanged;
    synchronized (mutex) {
      rowsChanged = builder.where(selection, selectionArgs).update(db, values);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return rowsChanged;
  }
コード例 #3
0
ファイル: VizProvider.java プロジェクト: elevenfive/Viz
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Log.v("query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");

    final SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    final int match = getUriMatcher().match(uri);

    final SelectionBuilder builder = buildExpandedSelection(uri, match);
    Cursor query;
    synchronized (mutex) {
      query = builder.where(selection, selectionArgs).query(db, projection, sortOrder);
    }
    query.setNotificationUri(getContext().getContentResolver(), uri);
    return query;
  }
コード例 #4
0
ファイル: VizProvider.java プロジェクト: elevenfive/Viz
 /**
  * Build a simple {@link SelectionBuilder} to match the requested {@link Uri}. This is usually
  * enough to support {@link #insert}, {@link #update}, and {@link #delete} operations.
  */
 private SelectionBuilder buildSimpleSelection(Uri uri) {
   final SelectionBuilder builder = new SelectionBuilder();
   final int match = getUriMatcher().match(uri);
   switch (match) {
     case FAVORITES_ID:
       {
         final String favoriteId = Favorites.getFavoriteId(uri);
         return builder.table(Tables.FAVORITES).where(Favorites._ID + "=?", favoriteId);
       }
     case RESOURCES_ID:
       {
         final String resourceId = Resources.getResourceId(uri);
         return builder.table(Tables.RESOURCES).where(Resources._ID + "=?", resourceId);
       }
     case DOWNLOADS_ID:
       {
         final String downloadId = Downloads.getDownloadId(uri);
         return builder.table(Tables.DOWNLOADS).where(Downloads._ID + "=?", downloadId);
       }
     case DOWNLOADS:
       {
         return builder.table(Tables.DOWNLOADS);
       }
     case RESOURCES:
       {
         return builder.table(Tables.RESOURCES);
       }
     default:
       {
         throw new UnsupportedOperationException("Unknown uri( " + match + "): " + uri);
       }
   }
 }