Class TypeCodec.AbstractCollectionCodec<E,C extends java.util.Collection<E>>
- java.lang.Object
-
- org.apache.cassandra.cql3.functions.types.TypeCodec<C>
-
- org.apache.cassandra.cql3.functions.types.TypeCodec.AbstractCollectionCodec<E,C>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.cassandra.cql3.functions.types.TypeCodec
TypeCodec.AbstractCollectionCodec<E,C extends java.util.Collection<E>>, TypeCodec.AbstractMapCodec<K,V>, TypeCodec.AbstractTupleCodec<T>, TypeCodec.AbstractUDTCodec<T>, TypeCodec.PrimitiveBooleanCodec, TypeCodec.PrimitiveByteCodec, TypeCodec.PrimitiveDoubleCodec, TypeCodec.PrimitiveFloatCodec, TypeCodec.PrimitiveIntCodec, TypeCodec.PrimitiveLongCodec, TypeCodec.PrimitiveShortCodec
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanaccepts(java.lang.Object value)Returntrueif this codec is capable of serializing the given object.Cdeserialize(java.nio.ByteBuffer bytes, ProtocolVersion protocolVersion)Deserialize the givenByteBufferinstance according to the CQL type handled by this codec.java.lang.Stringformat(C value)Format the given value as a valid CQL literal according to the CQL type handled by this codec.protected abstract CnewInstance(int size)Return a new instance ofCwith the given estimated size.Cparse(java.lang.String value)Parse the given CQL literal into an instance of the Java type handled by this codec.java.nio.ByteBufferserialize(C value, ProtocolVersion protocolVersion)Serialize the given value according to the CQL type handled by this codec.-
Methods inherited from class org.apache.cassandra.cql3.functions.types.TypeCodec
accepts, accepts, accepts, ascii, bigint, blob, cboolean, cdouble, cfloat, cint, counter, custom, date, decimal, duration, getCqlType, getJavaType, inet, list, map, set, smallInt, time, timestamp, timeUUID, tinyInt, toString, tuple, userType, uuid, varchar, varint
-
-
-
-
Method Detail
-
serialize
public java.nio.ByteBuffer serialize(C value, ProtocolVersion protocolVersion)
Description copied from class:TypeCodecSerialize the given value according to the CQL type handled by this codec.Implementation notes:
- Null values should be gracefully handled and no exception should be raised; these should be considered as the equivalent of a NULL CQL value;
- Codecs for CQL collection types should not permit null elements;
- Codecs for CQL collection types should treat a
nullinput as the equivalent of an empty collection.
- Specified by:
serializein classTypeCodec<C extends java.util.Collection<E>>- Parameters:
value- An instance of T; may benull.protocolVersion- the protocol version to use when serializingbytes. In most cases, the proper value to provide for this argument is the value returned byProtocolOptions#getProtocolVersion(which is the protocol version in use by the driver).- Returns:
- A
ByteBufferinstance containing the serialized form of T
-
deserialize
public C deserialize(java.nio.ByteBuffer bytes, ProtocolVersion protocolVersion)
Description copied from class:TypeCodecDeserialize the givenByteBufferinstance according to the CQL type handled by this codec.Implementation notes:
- Null or empty buffers should be gracefully handled and no exception should be raised;
these should be considered as the equivalent of a NULL CQL value and, in most cases,
should map to
nullor a default value for the corresponding Java type, if applicable; - Codecs for CQL collection types should clearly document whether they return immutable collections or not (note that the driver's default collection codecs return mutable collections);
- Codecs for CQL collection types should avoid returning
null; they should return empty collections instead (the driver's default collection codecs all comply with this rule). - The provided
ByteBuffershould never be consumed by read operations that modify its current position; if necessary,ByteBuffer.duplicate()duplicate} it before consuming.
- Specified by:
deserializein classTypeCodec<C extends java.util.Collection<E>>- Parameters:
bytes- AByteBufferinstance containing the serialized form of T; may benullor empty.protocolVersion- the protocol version to use when serializingbytes. In most cases, the proper value to provide for this argument is the value returned byProtocolOptions#getProtocolVersion(which is the protocol version in use by the driver).- Returns:
- An instance of T
- Null or empty buffers should be gracefully handled and no exception should be raised;
these should be considered as the equivalent of a NULL CQL value and, in most cases,
should map to
-
format
public java.lang.String format(C value)
Description copied from class:TypeCodecFormat the given value as a valid CQL literal according to the CQL type handled by this codec.Implementors should take care of quoting and escaping the resulting CQL literal where applicable. Null values should be accepted; in most cases, implementations should return the CQL keyword
"NULL"fornullinputs.Implementing this method is not strictly mandatory. It is used:
- in the query builder, when values are inlined in the query string (see
querybuilder.BuiltStatementfor a detailed explanation of when this happens); - in the
QueryLogger, if parameter logging is enabled; - to format the INITCOND in
AggregateMetadata#asCQLQuery(boolean); - in the
toString()implementation of some objects (UDTValue,TupleValue, and the internal representation of aROWSresponse), which may appear in driver logs.
If you choose not to implement this method, you should not throw an exception but instead return a constant string (for example "XxxCodec.format not implemented").
- in the query builder, when values are inlined in the query string (see
-
parse
public C parse(java.lang.String value)
Description copied from class:TypeCodecParse the given CQL literal into an instance of the Java type handled by this codec.Implementors should take care of unquoting and unescaping the given CQL string where applicable. Null values and empty Strings should be accepted, as well as the string
"NULL"; in most cases, implementations should interpret these inputs has equivalent to anullreference.Implementing this method is not strictly mandatory: internally, the driver only uses it to parse the INITCOND when building the metadata of an aggregate function (and in most cases it will use a built-in codec, unless the INITCOND has a custom type).
-
accepts
public boolean accepts(java.lang.Object value)
Description copied from class:TypeCodecReturntrueif this codec is capable of serializing the given object. Note that the object's Java type is inferred from the object' runtime (raw) type, contrary toTypeCodec.accepts(TypeToken)which is capable of handling generic types.This method is intended mostly to be used by the QueryBuilder when no type information is available when the codec is used.
Implementation notes:
- The default implementation is covariant with respect to the passed argument
(through the usage of
TypeToken#isAssignableFrom(TypeToken)orTypeToken.isSupertypeOf(Type)) and it's strongly recommended not to modify this behavior. This means that, by default, a codec will accept any subtype of the Java type that it has been created for. - The base implementation provided here can only handle non-parameterized types; codecs handling parameterized types, such as collection types, must override this method and perform some sort of "manual" inspection of the actual type parameters.
- Similarly, codecs that only accept a partial subset of all possible values must override this method and manually inspect the object to check if it complies or not with the codec's limitations.
- The default implementation is covariant with respect to the passed argument
(through the usage of
-
newInstance
protected abstract C newInstance(int size)
Return a new instance ofCwith the given estimated size.- Parameters:
size- The estimated size of the collection to create.- Returns:
- new instance of
Cwith the given estimated size.
-
-