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; }
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; }