Example #1
0
 private static void validateColumns(
     String keyspace,
     String columnFamilyName,
     ByteBuffer superColumnName,
     Iterable<ByteBuffer> column_names)
     throws InvalidRequestException {
   if (superColumnName != null) {
     if (superColumnName.remaining() > IColumn.MAX_NAME_LENGTH)
       throw new InvalidRequestException(
           "supercolumn name length must not be greater than " + IColumn.MAX_NAME_LENGTH);
     if (superColumnName.remaining() == 0)
       throw new InvalidRequestException("supercolumn name must not be empty");
     if (DatabaseDescriptor.getColumnFamilyType(keyspace, columnFamilyName)
         == ColumnFamilyType.Standard)
       throw new InvalidRequestException(
           "supercolumn specified to ColumnFamily "
               + columnFamilyName
               + " containing normal columns");
   }
   AbstractType comparator =
       ColumnFamily.getComparatorFor(keyspace, columnFamilyName, superColumnName);
   for (ByteBuffer name : column_names) {
     if (name.remaining() > IColumn.MAX_NAME_LENGTH)
       throw new InvalidRequestException(
           "column name length must not be greater than " + IColumn.MAX_NAME_LENGTH);
     if (name.remaining() == 0) throw new InvalidRequestException("column name must not be empty");
     try {
       comparator.validate(name);
     } catch (MarshalException e) {
       throw new InvalidRequestException(e.getMessage());
     }
   }
 }
Example #2
0
  public static void validateRange(String keyspace, ColumnParent column_parent, SliceRange range)
      throws InvalidRequestException {
    AbstractType comparator =
        ColumnFamily.getComparatorFor(
            keyspace, column_parent.column_family, column_parent.super_column);
    try {
      comparator.validate(range.start);
      comparator.validate(range.finish);
    } catch (MarshalException e) {
      throw new InvalidRequestException(e.getMessage());
    }

    if (range.count < 0) throw new InvalidRequestException("get_slice requires non-negative count");

    Comparator<ByteBuffer> orderedComparator =
        range.isReversed() ? comparator.getReverseComparator() : comparator;
    if (range.start.remaining() > 0
        && range.finish.remaining() > 0
        && orderedComparator.compare(range.start, range.finish) > 0) {
      throw new InvalidRequestException(
          "range finish must come after start in the order of traversal");
    }
  }
Example #3
0
 public static void validateColumn(String keyspace, ColumnParent column_parent, Column column)
     throws InvalidRequestException {
   validateTtl(column);
   validateColumns(keyspace, column_parent, Arrays.asList(column.name));
   try {
     AbstractType validator =
         DatabaseDescriptor.getValueValidator(keyspace, column_parent.column_family, column.name);
     if (validator != null) validator.validate(column.value);
   } catch (MarshalException me) {
     throw new InvalidRequestException(
         String.format(
             "[%s][%s][%s] = [%s] failed validation (%s)",
             keyspace,
             column_parent.getColumn_family(),
             FBUtilities.bytesToHex(column.name),
             FBUtilities.bytesToHex(column.value),
             me.getMessage()));
   }
 }
 /**
  * An alternative validation function used by CollectionsType in conjunction with CompositeType.
  *
  * <p>This is similar to the compare function above.
  */
 public void validateCollectionMember(ByteBuffer bytes, ByteBuffer collectionName)
     throws MarshalException {
   validate(bytes);
 }