Java Code Examples for org.apache.cassandra.serializers.MarshalException#getMessage()
The following examples show how to use
org.apache.cassandra.serializers.MarshalException#getMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Sets.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public static Value fromSerialized(ByteBuffer value, SetType type, int version) throws InvalidRequestException { try { // Collections have this small hack that validate cannot be called on a serialized object, // but compose does the validation (so we're fine). Set<?> s = (Set<?>)type.getSerializer().deserializeForNativeProtocol(value, version); SortedSet<ByteBuffer> elements = new TreeSet<ByteBuffer>(type.getElementsType()); for (Object element : s) elements.add(type.getElementsType().decompose(element)); return new Value(elements); } catch (MarshalException e) { throw new InvalidRequestException(e.getMessage()); } }
Example 2
Source File: Lists.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public static Value fromSerialized(ByteBuffer value, ListType type, int version) throws InvalidRequestException { try { // Collections have this small hack that validate cannot be called on a serialized object, // but compose does the validation (so we're fine). List<?> l = (List<?>)type.getSerializer().deserializeForNativeProtocol(value, version); List<ByteBuffer> elements = new ArrayList<ByteBuffer>(l.size()); for (Object element : l) // elements can be null in lists that represent a set of IN values elements.add(element == null ? null : type.getElementsType().decompose(element)); return new Value(elements); } catch (MarshalException e) { throw new InvalidRequestException(e.getMessage()); } }
Example 3
Source File: Constants.java From stratio-cassandra with Apache License 2.0 | 6 votes |
private ByteBuffer parsedValue(AbstractType<?> validator) throws InvalidRequestException { if (validator instanceof ReversedType<?>) validator = ((ReversedType<?>) validator).baseType; try { // BytesType doesn't want it's input prefixed by '0x'. if (type == Type.HEX && validator instanceof BytesType) return validator.fromString(text.substring(2)); if (validator instanceof CounterColumnType) return LongType.instance.fromString(text); return validator.fromString(text); } catch (MarshalException e) { throw new InvalidRequestException(e.getMessage()); } }
Example 4
Source File: Maps.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public static Value fromSerialized(ByteBuffer value, MapType type, int version) throws InvalidRequestException { try { // Collections have this small hack that validate cannot be called on a serialized object, // but compose does the validation (so we're fine). Map<?, ?> m = (Map<?, ?>)type.getSerializer().deserializeForNativeProtocol(value, version); Map<ByteBuffer, ByteBuffer> map = new LinkedHashMap<ByteBuffer, ByteBuffer>(m.size()); for (Map.Entry<?, ?> entry : m.entrySet()) map.put(type.getKeysType().decompose(entry.getKey()), type.getValuesType().decompose(entry.getValue())); return new Value(map); } catch (MarshalException e) { throw new InvalidRequestException(e.getMessage()); } }
Example 5
Source File: Term.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Returns the typed value, serialized to a ByteBuffer according to a * comparator/validator. * * @return a ByteBuffer of the value. * @throws InvalidRequestException if unable to coerce the string to its type. */ public ByteBuffer getByteBuffer(AbstractType<?> validator, List<ByteBuffer> variables) throws InvalidRequestException { try { if (!isBindMarker()) return validator.fromStringCQL2(text); // must be a marker term so check for a CqlBindValue stored in the term if (bindIndex == null) throw new AssertionError("a marker Term was encountered with no index value"); return variables.get(bindIndex); } catch (MarshalException e) { throw new InvalidRequestException(e.getMessage()); } }
Example 6
Source File: ThriftValidation.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public static void validateKey(CFMetaData metadata, ByteBuffer key) throws org.apache.cassandra.exceptions.InvalidRequestException { if (key == null || key.remaining() == 0) { throw new org.apache.cassandra.exceptions.InvalidRequestException("Key may not be empty"); } // check that key can be handled by FBUtilities.writeShortByteArray if (key.remaining() > FBUtilities.MAX_UNSIGNED_SHORT) { throw new org.apache.cassandra.exceptions.InvalidRequestException("Key length of " + key.remaining() + " is longer than maximum of " + FBUtilities.MAX_UNSIGNED_SHORT); } try { metadata.getKeyValidator().validate(key); } catch (MarshalException e) { throw new org.apache.cassandra.exceptions.InvalidRequestException(e.getMessage()); } }
Example 7
Source File: Constants.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Override public ByteBuffer bindAndGet(QueryOptions options) throws InvalidRequestException { try { ByteBuffer value = options.getValues().get(bindIndex); if (value != null) receiver.type.validate(value); return value; } catch (MarshalException e) { throw new InvalidRequestException(e.getMessage()); } }
Example 8
Source File: ThriftValidation.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public static void validateRange(CFMetaData metadata, ColumnParent column_parent, SliceRange range) throws org.apache.cassandra.exceptions.InvalidRequestException { if (range.count < 0) throw new org.apache.cassandra.exceptions.InvalidRequestException("get_slice requires non-negative count"); int maxNameLength = Cell.MAX_NAME_LENGTH; if (range.start.remaining() > maxNameLength) throw new org.apache.cassandra.exceptions.InvalidRequestException("range start length cannot be larger than " + maxNameLength); if (range.finish.remaining() > maxNameLength) throw new org.apache.cassandra.exceptions.InvalidRequestException("range finish length cannot be larger than " + maxNameLength); AbstractType<?> comparator = SuperColumns.getComparatorFor(metadata, column_parent.super_column); try { comparator.validate(range.start); comparator.validate(range.finish); } catch (MarshalException e) { throw new org.apache.cassandra.exceptions.InvalidRequestException(e.getMessage()); } Comparator<ByteBuffer> orderedComparator = range.isReversed() ? comparator.reverseComparator : comparator; if (range.start.remaining() > 0 && range.finish.remaining() > 0 && orderedComparator.compare(range.start, range.finish) > 0) { throw new org.apache.cassandra.exceptions.InvalidRequestException("range finish must come after start in the order of traversal"); } }
Example 9
Source File: SSTableImport.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Convert a string to bytes (ByteBuffer) according to type * @param content string to convert * @param type type to use for conversion * @return byte buffer representation of the given string */ private static ByteBuffer stringAsType(String content, AbstractType<?> type) { try { return type.fromString(content); } catch (MarshalException e) { throw new RuntimeException(e.getMessage()); } }
Example 10
Source File: ThriftValidation.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** * Validates the column names but not the parent path or data */ private static void validateColumnNames(CFMetaData metadata, ByteBuffer superColumnName, Iterable<ByteBuffer> column_names) throws org.apache.cassandra.exceptions.InvalidRequestException { int maxNameLength = Cell.MAX_NAME_LENGTH; if (superColumnName != null) { if (superColumnName.remaining() > maxNameLength) throw new org.apache.cassandra.exceptions.InvalidRequestException("supercolumn name length must not be greater than " + maxNameLength); if (superColumnName.remaining() == 0) throw new org.apache.cassandra.exceptions.InvalidRequestException("supercolumn name must not be empty"); if (metadata.cfType == ColumnFamilyType.Standard) throw new org.apache.cassandra.exceptions.InvalidRequestException("supercolumn specified to ColumnFamily " + metadata.cfName + " containing normal columns"); } AbstractType<?> comparator = SuperColumns.getComparatorFor(metadata, superColumnName); boolean isCQL3Table = !metadata.isThriftCompatible(); for (ByteBuffer name : column_names) { if (name.remaining() > maxNameLength) throw new org.apache.cassandra.exceptions.InvalidRequestException("column name length must not be greater than " + maxNameLength); if (name.remaining() == 0) throw new org.apache.cassandra.exceptions.InvalidRequestException("column name must not be empty"); try { comparator.validate(name); } catch (MarshalException e) { throw new org.apache.cassandra.exceptions.InvalidRequestException(e.getMessage()); } if (isCQL3Table) { // CQL3 table don't support having only part of their composite column names set Composite composite = metadata.comparator.fromByteBuffer(name); int minComponents = metadata.comparator.clusteringPrefixSize() + 1; if (composite.size() < minComponents) throw new org.apache.cassandra.exceptions.InvalidRequestException(String.format("Not enough components (found %d but %d expected) for column name since %s is a CQL3 table", composite.size(), minComponents, metadata.cfName)); // Furthermore, the column name must be a declared one. int columnIndex = metadata.comparator.clusteringPrefixSize(); ByteBuffer CQL3ColumnName = composite.get(columnIndex); if (!CQL3ColumnName.hasRemaining()) continue; // Row marker, ok ColumnIdentifier columnId = new ColumnIdentifier(CQL3ColumnName, metadata.comparator.subtype(columnIndex)); if (metadata.getColumnDefinition(columnId) == null) throw new org.apache.cassandra.exceptions.InvalidRequestException(String.format("Invalid cell for CQL3 table %s. The CQL3 column component (%s) does not correspond to a defined CQL3 column", metadata.cfName, columnId)); // On top of that, if we have a collection component, he (CQL3) column must be a collection if (metadata.comparator.hasCollections() && composite.size() == metadata.comparator.size()) { ColumnToCollectionType collectionType = metadata.comparator.collectionType(); if (!collectionType.defined.containsKey(CQL3ColumnName)) throw new org.apache.cassandra.exceptions.InvalidRequestException(String.format("Invalid collection component, %s is not a collection", UTF8Type.instance.getString(CQL3ColumnName))); } } } }