コード例 #1
0
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    String table = null;

    switch (uriMatcher.match(uri)) {
      case CONTACT:
        table = ContactTable.TABLE_NAME;
        break;

      case CONTACT_REQUEST:
        table = ContactRequestTable.TABLE_NAME;
        break;

      case CONTACT_REQUEST_ID:
        table = ContactRequestTable.TABLE_NAME;
        where =
            DatabaseUtils.concatenateWhere(
                ContactRequestTable._ID + " = " + ContentUris.parseId(uri), where);
        break;

      case CHAT_MESSAGE_ID:
        table = ChatMessageTable.TABLE_NAME;
        where =
            DatabaseUtils.concatenateWhere(
                ChatMessageTable._ID + " = " + ContentUris.parseId(uri), where);
        break;

      case CONVERSATION:
        table = ConversationTable.TABLE_NAME;
        break;

      case CONVERSATION_ID:
        table = ConversationTable.TABLE_NAME;
        where =
            DatabaseUtils.concatenateWhere(
                ConversationTable._ID + " = " + ContentUris.parseId(uri), where);
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int count = db.update(table, values, where, whereArgs);
    getContext().getContentResolver().notifyChange(uri, null);

    return count;
  }
コード例 #2
0
  @Override
  public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    db.beginTransaction();
    try {
      ContentProviderResult[] results = super.applyBatch(operations);
      db.setTransactionSuccessful();

      return results;
    } catch (OperationApplicationException e) {
      e.printStackTrace();
      return null;
    } finally {
      db.endTransaction();
    }
  }
コード例 #3
0
  @Override
  public Uri insert(Uri uri, ContentValues values) {
    Uri contentUri = null;
    String table = null;
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    switch (uriMatcher.match(uri)) {
      case CONTACT:
        table = ContactTable.TABLE_NAME;
        contentUri = ContactTable.CONTENT_URI;
        break;

      case CONTACT_REQUEST:
        table = ContactRequestTable.TABLE_NAME;
        contentUri = ContactRequestTable.CONTENT_URI;
        break;

      case CHAT_MESSAGE:
        table = ChatMessageTable.TABLE_NAME;
        contentUri = ChatMessageTable.CONTENT_URI;
        break;

      case CONVERSATION:
        table = ConversationTable.TABLE_NAME;
        contentUri = ConversationTable.CONTENT_URI;
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    long rowId = db.insert(table, null, values);
    if (rowId > 0) {
      Uri noteUri = ContentUris.withAppendedId(contentUri, rowId);
      getContext().getContentResolver().notifyChange(noteUri, null);
      return noteUri;
    }

    throw new SQLException("Failed to insert row into " + uri);
  }