public class TypeCodecs extends Object
See also ExtraTypeCodecs
for additional codecs that you can register with your session
to handle different type mappings.
Modifier and Type | Field and Description |
---|---|
static TypeCodec<String> |
ASCII
The default codec that maps CQL type
ascii to Java's String . |
static PrimitiveLongCodec |
BIGINT
The default codec that maps CQL type
bigint to Java's long . |
static TypeCodec<ByteBuffer> |
BLOB
The default codec that maps CQL type
blob to Java's ByteBuffer . |
static PrimitiveBooleanCodec |
BOOLEAN
The default codec that maps CQL type
boolean to Java's boolean . |
static PrimitiveLongCodec |
COUNTER
The default codec that maps CQL type
counter to Java's long . |
static TypeCodec<LocalDate> |
DATE
The default codec that maps CQL type
date to Java's LocalDate . |
static TypeCodec<BigDecimal> |
DECIMAL
The default codec that maps CQL type
decimal to Java's BigDecimal . |
static PrimitiveDoubleCodec |
DOUBLE
The default codec that maps CQL type
double to Java's double . |
static TypeCodec<CqlDuration> |
DURATION
The default codec that maps CQL type
duration to the driver's CqlDuration . |
static PrimitiveFloatCodec |
FLOAT
The default codec that maps CQL type
float to Java's float . |
static TypeCodec<InetAddress> |
INET
The default codec that maps CQL type
inet to Java's InetAddress . |
static PrimitiveIntCodec |
INT
The default codec that maps CQL type
int to Java's int . |
static PrimitiveShortCodec |
SMALLINT
The default codec that maps CQL type
smallint to Java's short . |
static TypeCodec<String> |
TEXT
The default codec that maps CQL type
text to Java's String . |
static TypeCodec<LocalTime> |
TIME
The default codec that maps CQL type
time to Java's LocalTime . |
static TypeCodec<Instant> |
TIMESTAMP
The default codec that maps CQL type
timestamp to Java's Instant , using the
system's default time zone to parse and format CQL literals. |
static TypeCodec<UUID> |
TIMEUUID
The default codec that maps CQL type
timeuuid to Java's UUID . |
static PrimitiveByteCodec |
TINYINT
The default codec that maps CQL type
tinyint to Java's byte . |
static TypeCodec<UUID> |
UUID
The default codec that maps CQL type
uuid to Java's UUID . |
static TypeCodec<BigInteger> |
VARINT
The default codec that maps CQL type
varint to Java's BigInteger . |
static TypeCodec<ZonedDateTime> |
ZONED_TIMESTAMP_SYSTEM
An alias for
ExtraTypeCodecs.ZONED_TIMESTAMP_SYSTEM . |
static TypeCodec<ZonedDateTime> |
ZONED_TIMESTAMP_UTC
An alias for
ExtraTypeCodecs.ZONED_TIMESTAMP_UTC . |
Constructor and Description |
---|
TypeCodecs() |
Modifier and Type | Method and Description |
---|---|
static TypeCodec<ByteBuffer> |
custom(DataType cqlType)
Builds a new codec that maps a CQL custom type to Java's
ByteBuffer . |
static <T> TypeCodec<List<T>> |
listOf(TypeCodec<T> elementCodec)
Builds a new codec that maps a CQL list to a Java list, using the given codec to map each
element.
|
static <K,V> TypeCodec<Map<K,V>> |
mapOf(TypeCodec<K> keyCodec,
TypeCodec<V> valueCodec)
Builds a new codec that maps a CQL map to a Java map, using the given codecs to map each key
and value.
|
static <T> TypeCodec<Set<T>> |
setOf(TypeCodec<T> elementCodec)
Builds a new codec that maps a CQL set to a Java set, using the given codec to map each
element.
|
static TypeCodec<TupleValue> |
tupleOf(TupleType cqlType)
Builds a new codec that maps a CQL tuple to the driver's
TupleValue , for the given type
definition. |
static TypeCodec<UdtValue> |
udtOf(UserDefinedType cqlType)
Builds a new codec that maps a CQL user defined type to the driver's
UdtValue , for the
given type definition. |
static TypeCodec<ZonedDateTime> |
zonedTimestampAt(ZoneId timeZone)
An alias for
ExtraTypeCodecs.zonedTimestampAt(ZoneId) . |
public static final PrimitiveBooleanCodec BOOLEAN
boolean
to Java's boolean
.public static final PrimitiveByteCodec TINYINT
tinyint
to Java's byte
.public static final PrimitiveDoubleCodec DOUBLE
double
to Java's double
.public static final PrimitiveLongCodec COUNTER
counter
to Java's long
.public static final PrimitiveFloatCodec FLOAT
float
to Java's float
.public static final PrimitiveIntCodec INT
int
to Java's int
.public static final PrimitiveLongCodec BIGINT
bigint
to Java's long
.public static final PrimitiveShortCodec SMALLINT
smallint
to Java's short
.public static final TypeCodec<Instant> TIMESTAMP
timestamp
to Java's Instant
, using the
system's default time zone to parse and format CQL literals.
This codec uses the system's default time zone as its
source of time zone information when formatting values as CQL literals, or parsing CQL literals
that do not have any time zone indication. Note that this only applies to the TypeCodec.format(Object)
and TypeCodec.parse(String)
methods; regular encoding and
decoding, like setting a value on a bound statement or reading a column from a row, are not
affected by the time zone.
If you need a different time zone, consider other codecs in ExtraTypeCodecs
, or call
ExtraTypeCodecs.timestampAt(ZoneId)
instead.
public static final TypeCodec<LocalDate> DATE
date
to Java's LocalDate
.public static final TypeCodec<LocalTime> TIME
time
to Java's LocalTime
.public static final TypeCodec<ByteBuffer> BLOB
blob
to Java's ByteBuffer
.
If you are looking for a codec mapping CQL type blob
to the Java type byte[]
, you should use ExtraTypeCodecs.BLOB_TO_ARRAY
instead.
If you are looking for a codec mapping CQL type list<tinyint>
to the Java type
byte[]
, you should use ExtraTypeCodecs.BYTE_LIST_TO_ARRAY
instead.
public static final TypeCodec<String> TEXT
text
to Java's String
.public static final TypeCodec<String> ASCII
ascii
to Java's String
.public static final TypeCodec<BigInteger> VARINT
varint
to Java's BigInteger
.public static final TypeCodec<BigDecimal> DECIMAL
decimal
to Java's BigDecimal
.public static final TypeCodec<UUID> UUID
uuid
to Java's UUID
.public static final TypeCodec<UUID> TIMEUUID
timeuuid
to Java's UUID
.public static final TypeCodec<InetAddress> INET
inet
to Java's InetAddress
.public static final TypeCodec<CqlDuration> DURATION
duration
to the driver's CqlDuration
.public static final TypeCodec<ZonedDateTime> ZONED_TIMESTAMP_SYSTEM
ExtraTypeCodecs.ZONED_TIMESTAMP_SYSTEM
.
This exists for historical reasons: the constant was originally defined in this class, but
technically it belongs to ExtraTypeCodecs
because this is not a built-in mapping.
public static final TypeCodec<ZonedDateTime> ZONED_TIMESTAMP_UTC
ExtraTypeCodecs.ZONED_TIMESTAMP_UTC
.
This exists for historical reasons: the constant was originally defined in this class, but
technically it belongs to ExtraTypeCodecs
because this is not a built-in mapping.
@NonNull public static TypeCodec<ByteBuffer> custom(@NonNull DataType cqlType)
ByteBuffer
.cqlType
- the fully-qualified name of the custom type.@NonNull public static <T> TypeCodec<List<T>> listOf(@NonNull TypeCodec<T> elementCodec)
@NonNull public static <T> TypeCodec<Set<T>> setOf(@NonNull TypeCodec<T> elementCodec)
@NonNull public static <K,V> TypeCodec<Map<K,V>> mapOf(@NonNull TypeCodec<K> keyCodec, @NonNull TypeCodec<V> valueCodec)
@NonNull public static TypeCodec<TupleValue> tupleOf(@NonNull TupleType cqlType)
TupleValue
, for the given type
definition.
Note that the components of a TupleValue
are stored in their encoded form. They are
encoded/decoded on the fly when you set or get them, using the codec registry.
@NonNull public static TypeCodec<UdtValue> udtOf(@NonNull UserDefinedType cqlType)
@NonNull public static TypeCodec<ZonedDateTime> zonedTimestampAt(@NonNull ZoneId timeZone)
ExtraTypeCodecs.zonedTimestampAt(ZoneId)
.
This exists for historical reasons: the method was originally defined in this class, but
technically it belongs to ExtraTypeCodecs
because this is not a built-in mapping.
Copyright © 2017–2024. All rights reserved.