T
- The Java type that the UDT will be mapped to.public abstract static class TypeCodec.AbstractUDTCodec<T> extends TypeCodec<T>
user-defined types
(UDTs) to Java objects.
It can serve as a base class for codecs dealing with direct UDT-to-Pojo mappings.TypeCodec.AbstractCollectionCodec<E,C extends 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
Modifier and Type | Field and Description |
---|---|
protected UserType |
definition |
Modifier | Constructor and Description |
---|---|
protected |
AbstractUDTCodec(UserType definition,
Class<T> javaClass) |
protected |
AbstractUDTCodec(UserType definition,
TypeToken<T> javaType) |
Modifier and Type | Method and Description |
---|---|
T |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion)
Deserialize the given
ByteBuffer instance according to the CQL type
handled by this codec. |
protected abstract T |
deserializeAndSetField(ByteBuffer input,
T target,
String fieldName,
ProtocolVersion protocolVersion)
Deserialize an individual field and set it on an object, as part of deserializing the whole
object from a CQL UDT (see
deserialize(ByteBuffer, ProtocolVersion) ). |
String |
format(T value)
Format the given value as a valid CQL literal according
to the CQL type handled by this codec.
|
protected abstract String |
formatField(T source,
String fieldName)
Format an individual field in an object as a CQL literal, as part of formatting the whole object
(see
format(Object) ). |
protected abstract T |
newInstance()
Return a new instance of
T . |
T |
parse(String value)
Parse the given CQL literal into an instance of the Java type
handled by this codec.
|
protected abstract T |
parseAndSetField(String input,
T target,
String fieldName)
Parse an individual field and set it on an object, as part of parsing the whole object
(see
parse(String) ). |
ByteBuffer |
serialize(T value,
ProtocolVersion protocolVersion)
Serialize the given value according to the CQL type
handled by this codec.
|
protected abstract ByteBuffer |
serializeField(T source,
String fieldName,
ProtocolVersion protocolVersion)
Serialize an individual field in an object, as part of serializing the whole object to a CQL
UDT (see
serialize(Object, ProtocolVersion) ). |
accepts, 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
protected final UserType definition
public ByteBuffer serialize(T value, ProtocolVersion protocolVersion)
TypeCodec
null
input as
the equivalent of an empty collection.serialize
in class TypeCodec<T>
value
- An instance of T; may be null
.protocolVersion
- the protocol version to use when serializing
bytes
. In most cases, the proper value to provide for this argument
is the value returned by ProtocolOptions.getProtocolVersion()
(which
is the protocol version in use by the driver).ByteBuffer
instance containing the serialized form of Tpublic T deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
TypeCodec
ByteBuffer
instance according to the CQL type
handled by this codec.
Implementation notes:
null
or a default value for the corresponding Java type, if applicable;null
;
they should return empty collections instead (the driver's default collection codecs all comply with this rule).ByteBuffer
should never be consumed by read operations that
modify its current position; if necessary,
ByteBuffer.duplicate()
duplicate} it before consuming.deserialize
in class TypeCodec<T>
bytes
- A ByteBuffer
instance containing the serialized form of T;
may be null
or empty.protocolVersion
- the protocol version to use when serializing
bytes
. In most cases, the proper value to provide for this argument
is the value returned by ProtocolOptions.getProtocolVersion()
(which
is the protocol version in use by the driver).public String format(T value)
TypeCodec
"NULL"
for null
inputs.
Implementing this method is not strictly mandatory. It is used:
BuiltStatement
for a detailed
explanation of when this happens);QueryLogger
, if parameter logging is enabled;AggregateMetadata.asCQLQuery(boolean)
;toString()
implementation of some objects (UDTValue
,
TupleValue
, and the internal representation of a ROWS
response),
which may appear in driver logs.public T parse(String value)
TypeCodec
"NULL"
;
in most cases, implementations should interpret these inputs has equivalent to a null
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).protected abstract T newInstance()
T
.T
.protected abstract ByteBuffer serializeField(T source, String fieldName, ProtocolVersion protocolVersion)
serialize(Object, ProtocolVersion)
).source
- The object to read the field from.fieldName
- The name of the field. Note that if it is case-sensitive or contains special
characters, it will be double-quoted (i.e. the string will contain actual
quote characters, as in "\"foobar\""
).protocolVersion
- The protocol version to use.null
if that field should be ignored.protected abstract T deserializeAndSetField(ByteBuffer input, T target, String fieldName, ProtocolVersion protocolVersion)
deserialize(ByteBuffer, ProtocolVersion)
).input
- The serialized form of the field.target
- The object to set the field on.fieldName
- The name of the field. Note that if it is case-sensitive or contains special
characters, it will be double-quoted (i.e. the string will contain actual
quote characters, as in "\"foobar\""
).protocolVersion
- The protocol version to use.target
, but if you're dealing
with immutable types you'll need to return a different instance.protected abstract String formatField(T source, String fieldName)
format(Object)
).source
- The object to read the field from.fieldName
- The name of the field. Note that if it is case-sensitive or contains special
characters, it will be double-quoted (i.e. the string will contain actual
quote characters, as in "\"foobar\""
).protected abstract T parseAndSetField(String input, T target, String fieldName)
parse(String)
).input
- The String to parse the field from.target
- The value to write to.fieldName
- The name of the field. Note that if it is case-sensitive or contains special
characters, it will be double-quoted (i.e. the string will contain actual
quote characters, as in "\"foobar\""
).target
, but if you're dealing
with immutable types you'll need to return a different instance.Copyright © 2012–2017. All rights reserved.