Пример #1
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    int match = sURIMatcher.match(uri);
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Cursor c;
    switch (match) {
      case GRAVES:
        return handleQuery(uri, projection, db);
      case GRAVE_URI_ID:
        long departedId = ContentUris.parseId(uri);
        c =
            db.query(
                DepartedTableHelper.TABLE_NAME,
                projection,
                Columns._ID
                    + " = "
                    + departedId
                    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
                selectionArgs,
                null,
                null,
                sortOrder);

        c.setNotificationUri(getContext().getContentResolver(), CONTENT_URI);
        return c;
      default:
        throw new IllegalArgumentException("unsupported uri: " + uri);
    }
  }
Пример #2
0
 @Override
 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
   if (sURIMatcher.match(uri) == GRAVES) {
     final SQLiteDatabase db = dbHelper.getWritableDatabase();
     getContext().getContentResolver().notifyChange(uri, null);
     return db.update(DepartedTableHelper.TABLE_NAME, values, selection, selectionArgs);
   } else {
     throw new IllegalArgumentException("Unknown uri: " + uri);
   }
 }
Пример #3
0
 @Override
 public Uri insert(Uri uri, ContentValues values) {
   if (sURIMatcher.match(uri) == GRAVES) {
     final SQLiteDatabase db = dbHelper.getWritableDatabase();
     long id = db.insert(DepartedTableHelper.TABLE_NAME, null, values);
     Uri insertUri = ContentUris.withAppendedId(CONTENT_URI, id);
     getContext().getContentResolver().notifyChange(insertUri, null);
     return insertUri;
   } else {
     throw new IllegalArgumentException("Unknown uri: " + uri);
   }
 }
Пример #4
0
 @Override
 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
     throws OperationApplicationException {
   SQLiteDatabase db = dbHelper.getWritableDatabase();
   db.beginTransaction();
   try {
     ContentProviderResult[] results = super.applyBatch(operations);
     db.setTransactionSuccessful();
     return results;
   } finally {
     db.endTransaction();
   }
 }
Пример #5
0
 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   int match = sURIMatcher.match(uri);
   SQLiteDatabase db = dbHelper.getWritableDatabase();
   int count = 0;
   switch (match) {
     case GRAVES:
       StringBuilder builder = new StringBuilder();
       String[] whereArgs = createWhere(uri, builder);
       count = db.delete(DepartedTableHelper.TABLE_NAME, builder.toString(), whereArgs);
       getContext().getContentResolver().notifyChange(uri, null);
       break;
     case GRAVE_URI_ID:
       long departedId = ContentUris.parseId(uri);
       count = db.delete(DepartedTableHelper.TABLE_NAME, Columns._ID + " = " + departedId, null);
       getContext().getContentResolver().notifyChange(uri, null);
       break;
   }
   return count;
 }