Class TypeCodec.AbstractTupleCodec<T>
- java.lang.Object
-
- org.apache.cassandra.cql3.functions.types.TypeCodec<T>
-
- org.apache.cassandra.cql3.functions.types.TypeCodec.AbstractTupleCodec<T>
-
-
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
-
-
Field Summary
Fields Modifier and Type Field Description protected TupleType
definition
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
accepts(DataType cqlType)
Returntrue
if this codec is capable of deserializing the givencqlType
.T
deserialize(java.nio.ByteBuffer bytes, ProtocolVersion protocolVersion)
Deserialize the givenByteBuffer
instance according to the CQL type handled by this codec.protected abstract T
deserializeAndSetField(java.nio.ByteBuffer input, T target, int index, ProtocolVersion protocolVersion)
Deserialize an individual field and set it on an object, as part of deserializing the whole object from a CQL tuple (seedeserialize(ByteBuffer, ProtocolVersion)
).java.lang.String
format(T value)
Format the given value as a valid CQL literal according to the CQL type handled by this codec.protected abstract java.lang.String
formatField(T source, int index)
Format an individual field in an object as a CQL literal, as part of formatting the whole object (seeformat(Object)
).protected abstract T
newInstance()
Return a new instance ofT
.T
parse(java.lang.String value)
Parse the given CQL literal into an instance of the Java type handled by this codec.protected abstract T
parseAndSetField(java.lang.String input, T target, int index)
Parse an individual field and set it on an object, as part of parsing the whole object (seeparse(String)
).java.nio.ByteBuffer
serialize(T value, ProtocolVersion protocolVersion)
Serialize the given value according to the CQL type handled by this codec.protected abstract java.nio.ByteBuffer
serializeField(T source, int index, ProtocolVersion protocolVersion)
Serialize an individual field in an object, as part of serializing the whole object to a CQL tuple (seeserialize(Object, ProtocolVersion)
).-
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
-
-
-
-
Field Detail
-
definition
protected final TupleType definition
-
-
Method Detail
-
accepts
public boolean accepts(DataType cqlType)
Description copied from class:TypeCodec
Returntrue
if this codec is capable of deserializing the givencqlType
.
-
serialize
public java.nio.ByteBuffer serialize(T value, ProtocolVersion protocolVersion)
Description copied from class:TypeCodec
Serialize 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
null
input as the equivalent of an empty collection.
- Specified by:
serialize
in classTypeCodec<T>
- 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
ByteBuffer
instance containing the serialized form of T
-
deserialize
public T deserialize(java.nio.ByteBuffer bytes, ProtocolVersion protocolVersion)
Description copied from class:TypeCodec
Deserialize the givenByteBuffer
instance 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
null
or 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
ByteBuffer
should never be consumed by read operations that modify its current position; if necessary,ByteBuffer.duplicate()
duplicate} it before consuming.
- Specified by:
deserialize
in classTypeCodec<T>
- Parameters:
bytes
- AByteBuffer
instance containing the serialized form of T; may benull
or 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(T value)
Description copied from class:TypeCodec
Format 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"
fornull
inputs.Implementing this method is not strictly mandatory. It is used:
- in the query builder, when values are inlined in the query string (see
querybuilder.BuiltStatement
for 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 aROWS
response), 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 T parse(java.lang.String value)
Description copied from class:TypeCodec
Parse 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 anull
reference.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).
-
newInstance
protected abstract T newInstance()
Return a new instance ofT
.- Returns:
- A new instance of
T
.
-
serializeField
protected abstract java.nio.ByteBuffer serializeField(T source, int index, ProtocolVersion protocolVersion)
Serialize an individual field in an object, as part of serializing the whole object to a CQL tuple (seeserialize(Object, ProtocolVersion)
).- Parameters:
source
- The object to read the field from.index
- The index of the field.protocolVersion
- The protocol version to use.- Returns:
- The serialized field, or
null
if that field should be ignored.
-
deserializeAndSetField
protected abstract T deserializeAndSetField(java.nio.ByteBuffer input, T target, int index, ProtocolVersion protocolVersion)
Deserialize an individual field and set it on an object, as part of deserializing the whole object from a CQL tuple (seedeserialize(ByteBuffer, ProtocolVersion)
).- Parameters:
input
- The serialized form of the field.target
- The object to set the field on.index
- The index of the field.protocolVersion
- The protocol version to use.- Returns:
- The target object with the field set. In most cases this should be the same as
target
, but if you're dealing with immutable types you'll need to return a different instance.
-
formatField
protected abstract java.lang.String formatField(T source, int index)
Format an individual field in an object as a CQL literal, as part of formatting the whole object (seeformat(Object)
).- Parameters:
source
- The object to read the field from.index
- The index of the field.- Returns:
- The formatted value.
-
parseAndSetField
protected abstract T parseAndSetField(java.lang.String input, T target, int index)
Parse an individual field and set it on an object, as part of parsing the whole object (seeparse(String)
).- Parameters:
input
- The String to parse the field from.target
- The value to write to.index
- The index of the field.- Returns:
- The target object with the field set. In most cases this should be the same as
target
, but if you're dealing with immutable types you'll need to return a different instance.
-
-