/** * Checks that the specified object is <code>null</code>. * If it is not an <code>InvalidRequestException</code> will be throws. * * @param object the object to test * @param message the error message * @return the object * @throws InvalidRequestException if the specified object is not <code>null</code>. */ public static <T> T checkNull(T object, String message) throws InvalidRequestException { return checkNull(object, message, EMPTY_OBJECT_ARRAY); }
/** * Checks that the specified expression is <code>false</code>. If not an <code>InvalidRequestException</code> will * be thrown. * * @param expression the expression to test * @param message the error message * @throws InvalidRequestException if the specified expression is <code>true</code>. */ public static void checkFalse(boolean expression, String message) throws InvalidRequestException { checkTrue(!expression, message); }
@Override public SingleRestriction doMergeWith(SingleRestriction otherRestriction) { throw invalidRequest("%s cannot be restricted by a relation if it includes an IS NOT NULL", columnDef.name); }
public void validate() { checkNotNull(value, "Unsupported null value for column %s", column.name); checkBindValueSet(value, "Unsupported unset value for column %s", column.name); }
checkTrue(columnDefs.containsAll(cfm.partitionKeyColumns()), "The token() function must be applied to all partition key components or none of them"); checkContainsNoDuplicates(columnDefs, "The token() function contains duplicate partition key components"); checkContainsOnly(columnDefs, cfm.partitionKeyColumns(), "The token() function must contains only partition key components"); throw invalidRequest("The token function arguments must be in the partition key order: %s", Joiner.on(", ").join(ColumnDefinition.toIdentifiers(cfm.partitionKeyColumns())));
/** * Returns the column conditions. * * @param metadata the column family meta data * @param boundNames the bound names * @return the column conditions. */ private ColumnConditions prepareColumnConditions(CFMetaData metadata, VariableSpecifications boundNames) { checkNull(attrs.timestamp, "Cannot provide custom timestamp for conditional updates"); ColumnConditions.Builder builder = ColumnConditions.newBuilder(); for (Pair<ColumnDefinition.Raw, ColumnCondition.Raw> entry : conditions) { ColumnDefinition def = entry.left.prepare(metadata); ColumnCondition condition = entry.right.prepare(keyspace(), def, metadata); condition.collectMarkerSpecification(boundNames); checkFalse(def.isPrimaryKeyColumn(), "PRIMARY KEY column '%s' cannot have IF conditions", def.name); builder.add(condition); } return builder.build(); }
@Override protected List<ByteBuffer> getValues(QueryOptions options) { Terminal term = marker.bind(options); checkNotNull(term, "Invalid null value for column %s", columnDef.name); checkFalse(term == Constants.UNSET_VALUE, "Invalid unset value for column %s", columnDef.name); Term.MultiItemTerminal lval = (Term.MultiItemTerminal) term; return lval.getElements(); }
@Override public SingleRestriction doMergeWith(SingleRestriction otherRestriction) { checkTrue(otherRestriction.isSlice(), "Column \"%s\" cannot be restricted by both an equality and an inequality relation", columnDef.name); SingleColumnRestriction.SliceRestriction otherSlice = (SingleColumnRestriction.SliceRestriction) otherRestriction; checkFalse(hasBound(Bound.START) && otherSlice.hasBound(Bound.START), "More than one restriction was found for the start bound on %s", columnDef.name); checkFalse(hasBound(Bound.END) && otherSlice.hasBound(Bound.END), "More than one restriction was found for the end bound on %s", columnDef.name); return new SliceRestriction(columnDef, slice.merge(otherSlice.slice)); }
private void validateSecondaryIndexSelections(boolean selectsOnlyStaticColumns) { checkFalse(keyIsInRelation(), "Select on indexed columns and with IN clause for the PRIMARY KEY are not supported"); // When the user only select static columns, the intent is that we don't query the whole partition but just // the static parts. But 1) we don't have an easy way to do that with 2i and 2) since we don't support index on // static columns // so far, 2i means that you've restricted a non static column, so the query is somewhat non-sensical. checkFalse(selectsOnlyStaticColumns, "Queries using 2ndary indexes don't support selecting only static columns"); }
protected void setArg(int i, ByteBuffer value) throws InvalidRequestException { RequestValidations.checkBindValueSet(value, "Invalid unset value for argument in call to function %s", fun.name().name); args.set(i, value); }
checkFalse(cfm.isCounter(), "INSERT statements are not allowed on counter tables, use UPDATE instead"); checkFalse(columnNames == null, "Column names for INSERT must be provided when using VALUES"); checkFalse(columnNames.isEmpty(), "No columns provided to INSERT"); checkFalse(columnNames.size() != columnValues.size(), "Unmatched column names/values"); checkContainsNoDuplicates(columnNames, "The column names contains duplicates");
private void validateOperationOnDurations(AbstractType<?> type) { if (type.referencesDuration() && operator.isSlice()) { checkFalse(type.isCollection(), "Slice conditions are not supported on collections containing durations"); checkFalse(type.isTuple(), "Slice conditions are not supported on tuples containing durations"); checkFalse(type.isUDT(), "Slice conditions are not supported on UDTs containing durations"); throw invalidRequest("Slice conditions are not supported on durations", operator); } } }
@Override protected List<List<ByteBuffer>> splitValues(QueryOptions options) { Tuples.InMarker inMarker = (Tuples.InMarker) marker; Tuples.InValue inValue = inMarker.bind(options); checkNotNull(inValue, "Invalid null value for IN restriction"); return inValue.getSplitValues(); } }
checkTrue(columnDefs.containsAll(cfm.partitionKeyColumns()), "The token() function must be applied to all partition key components or none of them"); checkContainsNoDuplicates(columnDefs, "The token() function contains duplicate partition key components"); checkContainsOnly(columnDefs, cfm.partitionKeyColumns(), "The token() function must contains only partition key components"); throw invalidRequest("The token function arguments must be in the partition key order: %s", Joiner.on(", ").join(ColumnDefinition.toIdentifiers(cfm.partitionKeyColumns())));
/** * Returns the column conditions. * * @param metadata the column family meta data * @param boundNames the bound names * @return the column conditions. */ private ColumnConditions prepareColumnConditions(CFMetaData metadata, VariableSpecifications boundNames) { checkNull(attrs.timestamp, "Cannot provide custom timestamp for conditional updates"); ColumnConditions.Builder builder = ColumnConditions.newBuilder(); for (Pair<ColumnDefinition.Raw, ColumnCondition.Raw> entry : conditions) { ColumnDefinition def = entry.left.prepare(metadata); ColumnCondition condition = entry.right.prepare(keyspace(), def, metadata); condition.collectMarkerSpecification(boundNames); checkFalse(def.isPrimaryKeyColumn(), "PRIMARY KEY column '%s' cannot have IF conditions", def.name); builder.add(condition); } return builder.build(); }
@Override public void validate() throws InvalidRequestException { checkNotNull(key, "Unsupported null map key for column %s", column.name); checkBindValueSet(key, "Unsupported unset map key for column %s", column.name); checkNotNull(value, "Unsupported null map value for column %s", column.name); checkBindValueSet(value, "Unsupported unset map value for column %s", column.name); }
public List<ByteBuffer> getValues(QueryOptions options) throws InvalidRequestException { Terminal term = marker.bind(options); checkNotNull(term, "Invalid null value for column %s", columnDef.name); checkFalse(term == Constants.UNSET_VALUE, "Invalid unset value for column %s", columnDef.name); Term.MultiItemTerminal lval = (Term.MultiItemTerminal) term; return lval.getElements(); } }
@Override public SingleRestriction doMergeWith(SingleRestriction otherRestriction) { checkTrue(otherRestriction.isSlice(), "Column \"%s\" cannot be restricted by both an equality and an inequality relation", columnDef.name); SingleColumnRestriction.SliceRestriction otherSlice = (SingleColumnRestriction.SliceRestriction) otherRestriction; checkFalse(hasBound(Bound.START) && otherSlice.hasBound(Bound.START), "More than one restriction was found for the start bound on %s", columnDef.name); checkFalse(hasBound(Bound.END) && otherSlice.hasBound(Bound.END), "More than one restriction was found for the end bound on %s", columnDef.name); return new SliceRestriction(columnDef, slice.merge(otherSlice.slice)); }
private void validateSecondaryIndexSelections(boolean selectsOnlyStaticColumns) { checkFalse(keyIsInRelation(), "Select on indexed columns and with IN clause for the PRIMARY KEY are not supported"); // When the user only select static columns, the intent is that we don't query the whole partition but just // the static parts. But 1) we don't have an easy way to do that with 2i and 2) since we don't support index on // static columns // so far, 2i means that you've restricted a non static column, so the query is somewhat non-sensical. checkFalse(selectsOnlyStaticColumns, "Queries using 2ndary indexes don't support selecting only static columns"); }
protected void setArg(int i, ByteBuffer value) throws InvalidRequestException { RequestValidations.checkBindValueSet(value, "Invalid unset value for argument in call to function %s", fun.name().name); args.set(i, value); }