コード例 #1
0
ファイル: UpdateStatement.java プロジェクト: placrosse/ACaZoo
    protected ModificationStatement prepareInternal(
        CFDefinition cfDef, VariableSpecifications boundNames, Attributes attrs)
        throws InvalidRequestException {
      UpdateStatement stmt = new UpdateStatement(boundNames.size(), cfDef.cfm, attrs);

      for (Pair<ColumnIdentifier, Operation.RawUpdate> entry : updates) {
        CFDefinition.Name name = cfDef.get(entry.left);
        if (name == null)
          throw new InvalidRequestException(String.format("Unknown identifier %s", entry.left));

        Operation operation = entry.right.prepare(name);
        operation.collectMarkerSpecification(boundNames);

        switch (name.kind) {
          case KEY_ALIAS:
          case COLUMN_ALIAS:
            throw new InvalidRequestException(
                String.format("PRIMARY KEY part %s found in SET part", entry.left));
          case VALUE_ALIAS:
          case COLUMN_METADATA:
            stmt.addOperation(operation);
            break;
        }
      }

      stmt.processWhereClause(whereClause, boundNames);
      return stmt;
    }
コード例 #2
0
  public Collection<RowMutation> getMutations(
      List<ByteBuffer> variables, boolean local, ConsistencyLevel cl, long now)
      throws RequestExecutionException, RequestValidationException {
    // keys
    List<ByteBuffer> keys = UpdateStatement.buildKeyNames(cfDef, processedKeys, variables);

    // columns
    ColumnNameBuilder builder = cfDef.getColumnNameBuilder();
    CFDefinition.Name firstEmpty =
        UpdateStatement.buildColumnNames(cfDef, processedKeys, builder, variables, false);

    boolean fullKey = builder.componentCount() == cfDef.columns.size();
    boolean isRange = cfDef.isCompact ? !fullKey : (!fullKey || toRemove.isEmpty());

    if (!toRemove.isEmpty() && isRange)
      throw new InvalidRequestException(
          String.format(
              "Missing mandatory PRIMARY KEY part %s since %s specified",
              firstEmpty, toRemove.iterator().next().left));

    // Lists DISCARD operation incurs a read. Do that now.
    Set<ByteBuffer> toRead = null;
    for (Pair<CFDefinition.Name, Term> p : toRemove) {
      CFDefinition.Name name = p.left;
      Term value = p.right;

      if ((name.type instanceof ListType) && value != null) {
        if (toRead == null) toRead = new TreeSet<ByteBuffer>(UTF8Type.instance);
        toRead.add(name.name.key);
      }
    }

    Map<ByteBuffer, ColumnGroupMap> rows =
        toRead != null
            ? readRows(keys, builder, toRead, (CompositeType) cfDef.cfm.comparator, local, cl)
            : null;

    Collection<RowMutation> rowMutations = new ArrayList<RowMutation>(keys.size());
    UpdateParameters params = new UpdateParameters(variables, getTimestamp(now), -1);

    for (ByteBuffer key : keys)
      rowMutations.add(
          mutationForKey(
              cfDef, key, builder, isRange, params, rows == null ? null : rows.get(key)));

    return rowMutations;
  }
コード例 #3
0
ファイル: UpdateStatement.java プロジェクト: placrosse/ACaZoo
    protected ModificationStatement prepareInternal(
        CFDefinition cfDef, VariableSpecifications boundNames, Attributes attrs)
        throws InvalidRequestException {
      UpdateStatement stmt = new UpdateStatement(boundNames.size(), cfDef.cfm, attrs);

      // Created from an INSERT
      if (stmt.isCounter())
        throw new InvalidRequestException(
            "INSERT statement are not allowed on counter tables, use UPDATE instead");
      if (columnNames.size() != columnValues.size())
        throw new InvalidRequestException("Unmatched column names/values");
      if (columnNames.isEmpty()) throw new InvalidRequestException("No columns provided to INSERT");

      for (int i = 0; i < columnNames.size(); i++) {
        CFDefinition.Name name = cfDef.get(columnNames.get(i));
        if (name == null)
          throw new InvalidRequestException(
              String.format("Unknown identifier %s", columnNames.get(i)));

        for (int j = 0; j < i; j++)
          if (name.name.equals(columnNames.get(j)))
            throw new InvalidRequestException(
                String.format("Multiple definitions found for column %s", name));

        Term.Raw value = columnValues.get(i);

        switch (name.kind) {
          case KEY_ALIAS:
          case COLUMN_ALIAS:
            Term t = value.prepare(name);
            t.collectMarkerSpecification(boundNames);
            stmt.addKeyValue(name.name, t);
            break;
          case VALUE_ALIAS:
          case COLUMN_METADATA:
            Operation operation = new Operation.SetValue(value).prepare(name);
            operation.collectMarkerSpecification(boundNames);
            stmt.addOperation(operation);
            break;
        }
      }
      return stmt;
    }
コード例 #4
0
  public ParsedStatement.Prepared prepare(ColumnSpecification[] boundNames)
      throws InvalidRequestException {
    CFMetaData metadata = ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
    type = metadata.getDefaultValidator().isCommutative() ? Type.COUNTER : Type.LOGGED;

    cfDef = metadata.getCfDef();
    UpdateStatement.processKeys(cfDef, whereClause, processedKeys, boundNames);

    for (Selector column : columns) {
      CFDefinition.Name name = cfDef.get(column.id());
      if (name == null)
        throw new InvalidRequestException(String.format("Unknown identifier %s", column));

      // For compact, we only have one value except the key, so the only form of DELETE that make
      // sense is without a column
      // list. However, we support having the value name for coherence with the static/sparse case
      if (name.kind != CFDefinition.Name.Kind.COLUMN_METADATA
          && name.kind != CFDefinition.Name.Kind.VALUE_ALIAS)
        throw new InvalidRequestException(
            String.format(
                "Invalid identifier %s for deletion (should not be a PRIMARY KEY part)", column));

      if (column.key() != null) {
        if (name.type instanceof ListType) {
          if (column.key().isBindMarker())
            boundNames[column.key().bindIndex] = ListOperation.indexSpecOf(name);
        } else if (name.type instanceof MapType) {
          if (column.key().isBindMarker())
            boundNames[column.key().bindIndex] = MapOperation.keySpecOf(name, (MapType) name.type);
        } else {
          throw new InvalidRequestException(
              String.format(
                  "Invalid selection %s since %s is neither a list or a map", column, column.id()));
        }
      }

      toRemove.add(Pair.create(name, column.key()));
    }

    return new ParsedStatement.Prepared(this, Arrays.<ColumnSpecification>asList(boundNames));
  }