public class InstantCodec extends TypeCodec<Instant>
TypeCodec
that maps Instant
to CQL timestamp
allowing the setting and retrieval of timestamp
columns as Instant
instances.
Since C* timestamp
columns do not preserve timezones
any attached timezone information will be lost.
IMPORTANT: this codec's format
method formats
timestamps using an ISO-8601 format that includes milliseconds.
This format is incompatible with Cassandra versions < 2.0.9.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 |
---|---|
static InstantCodec |
instance |
Modifier and Type | Method and Description |
---|---|
Instant |
deserialize(ByteBuffer bytes,
ProtocolVersion protocolVersion)
Deserialize the given
ByteBuffer instance according to the CQL type
handled by this codec. |
String |
format(Instant value)
Format the given value as a valid CQL literal according
to the CQL type handled by this codec.
|
Instant |
parse(String value)
Parse the given CQL literal into an instance of the Java type
handled by this codec.
|
ByteBuffer |
serialize(Instant value,
ProtocolVersion protocolVersion)
Serialize the given value according to the CQL type
handled by this codec.
|
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
public static final InstantCodec instance
public ByteBuffer serialize(Instant value, ProtocolVersion protocolVersion)
TypeCodec
null
input as
the equivalent of an empty collection.serialize
in class TypeCodec<Instant>
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 Instant 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<Instant>
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(Instant 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 Instant 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).Copyright © 2012–2018. All rights reserved.