Ejemplo n.º 1
0
 @Override
 public int bulkInsert(Uri uri, ContentValues[] values) {
   final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
   final int match = sUriMatcher.match(uri);
   switch (match) {
     case USER:
       db.beginTransaction();
       int returnCount = 0;
       try {
         for (ContentValues value : values) {
           long _id = db.insert(MovieContract.UserEntry.TABLE_NAME, null, value);
           if (_id != -1) {
             returnCount++;
           }
         }
         db.setTransactionSuccessful();
       } finally {
         db.endTransaction();
       }
       getContext().getContentResolver().notifyChange(uri, null);
       return returnCount;
     default:
       return super.bulkInsert(uri, values);
   }
 }
Ejemplo n.º 2
0
  /*
     Student: Add the ability to insert Locations to the implementation of this function.
  */
  @Override
  public Uri insert(Uri uri, ContentValues values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    Uri returnUri;

    switch (match) {
      case USER:
        {
          long _id = db.insert(MovieContract.UserEntry.TABLE_NAME, null, values);
          if (_id > 0) returnUri = MovieContract.UserEntry.buildUserUri(_id);
          else throw new android.database.SQLException("Failed to insert row into " + uri);
          break;
        }
      case MOVIEID:
        {
          long _id = db.insert(MovieContract.MovieEntry.TABLE_NAME, null, values);
          if (_id > 0) returnUri = MovieContract.MovieEntry.buildMovieUri(_id);
          else throw new android.database.SQLException("Failed to insert row into " + uri);
          break;
        }
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return returnUri;
  }
Ejemplo n.º 3
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int rowsUpdated;

    switch (match) {
      case USER:
        rowsUpdated =
            db.update(MovieContract.UserEntry.TABLE_NAME, values, selection, selectionArgs);
        break;
      case MOVIEID:
        rowsUpdated =
            db.update(MovieContract.MovieEntry.TABLE_NAME, values, selection, selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    if (rowsUpdated != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsUpdated;
  }
Ejemplo n.º 4
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int rowsDeleted;
    // this makes delete all rows return the number of rows deleted
    if (null == selection) selection = "1";
    switch (match) {
      case USER:
        rowsDeleted = db.delete(MovieContract.UserEntry.TABLE_NAME, selection, selectionArgs);
        break;

      case MOVIEID:
        rowsDeleted = db.delete(MovieContract.MovieEntry.TABLE_NAME, selection, selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    // Because a null deletes all rows
    if (rowsDeleted != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsDeleted;
  }