T
- the generic typepublic abstract static class CassandraExecutor.UDTCodec<T>
extends com.datastax.driver.core.TypeCodec<T>
static final CassandraExecutor cassandraExecutor;
static {
final CodecRegistry codecRegistry = new CodecRegistry();
final Cluster cluster = Cluster.builder().withCodecRegistry(codecRegistry).addContactPoint("127.0.0.1").build();
codecRegistry.register(new UDTCodec<Address>(cluster, "simplex", "address", Address.class) {
protected Address deserialize(UDTValue value) {
if (value == null) {
return null;
}
Address address = new Address();
address.setStreet(value.getString("street"));
address.setCity(value.getString("city"));
address.setZipCode(value.getInt("zipCode"));
return address;
}
protected UDTValue serialize(Address value) {
return value == null ? null
: newUDTValue().setString("street", value.getStreet()).setInt("zipcode", value.getZipCode());
}
});
cassandraExecutor = new CassandraExecutor(cluster);
}
com.datastax.driver.core.TypeCodec.AbstractCollectionCodec<E,C extends Collection<E>>, com.datastax.driver.core.TypeCodec.AbstractMapCodec<K,V>, com.datastax.driver.core.TypeCodec.AbstractTupleCodec<T>, com.datastax.driver.core.TypeCodec.AbstractUDTCodec<T>, com.datastax.driver.core.TypeCodec.PrimitiveBooleanCodec, com.datastax.driver.core.TypeCodec.PrimitiveByteCodec, com.datastax.driver.core.TypeCodec.PrimitiveDoubleCodec, com.datastax.driver.core.TypeCodec.PrimitiveFloatCodec, com.datastax.driver.core.TypeCodec.PrimitiveIntCodec, com.datastax.driver.core.TypeCodec.PrimitiveLongCodec, com.datastax.driver.core.TypeCodec.PrimitiveShortCodec
Constructor and Description |
---|
UDTCodec(com.datastax.driver.core.Cluster cluster,
String keySpace,
String userType,
Class<T> javaType)
Instantiates a new UDT codec.
|
UDTCodec(com.datastax.driver.core.TypeCodec<com.datastax.driver.core.UDTValue> innerCodec,
Class<T> javaType)
Instantiates a new UDT codec.
|
Modifier and Type | Method and Description |
---|---|
T |
deserialize(ByteBuffer bytes,
com.datastax.driver.core.ProtocolVersion protocolVersion)
Deserialize.
|
protected abstract T |
deserialize(com.datastax.driver.core.UDTValue value)
Deserialize.
|
String |
format(T value)
Format.
|
protected com.datastax.driver.core.UDTValue |
newUDTValue()
New UDT value.
|
T |
parse(String value)
Parses the.
|
protected abstract com.datastax.driver.core.UDTValue |
serialize(T value)
Serialize.
|
ByteBuffer |
serialize(T value,
com.datastax.driver.core.ProtocolVersion protocolVersion)
Serialize.
|
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 UDTCodec(com.datastax.driver.core.TypeCodec<com.datastax.driver.core.UDTValue> innerCodec, Class<T> javaType)
innerCodec
- the inner codecjavaType
- the java typepublic ByteBuffer serialize(T value, com.datastax.driver.core.ProtocolVersion protocolVersion) throws com.datastax.driver.core.exceptions.InvalidTypeException
serialize
in class com.datastax.driver.core.TypeCodec<T>
value
- the valueprotocolVersion
- the protocol versioncom.datastax.driver.core.exceptions.InvalidTypeException
- the invalid type exceptionpublic T deserialize(ByteBuffer bytes, com.datastax.driver.core.ProtocolVersion protocolVersion) throws com.datastax.driver.core.exceptions.InvalidTypeException
deserialize
in class com.datastax.driver.core.TypeCodec<T>
bytes
- the bytesprotocolVersion
- the protocol versioncom.datastax.driver.core.exceptions.InvalidTypeException
- the invalid type exceptionpublic T parse(String value) throws com.datastax.driver.core.exceptions.InvalidTypeException
parse
in class com.datastax.driver.core.TypeCodec<T>
value
- the valuecom.datastax.driver.core.exceptions.InvalidTypeException
- the invalid type exceptionpublic String format(T value) throws com.datastax.driver.core.exceptions.InvalidTypeException
format
in class com.datastax.driver.core.TypeCodec<T>
value
- the valuecom.datastax.driver.core.exceptions.InvalidTypeException
- the invalid type exceptionprotected com.datastax.driver.core.UDTValue newUDTValue()
protected abstract com.datastax.driver.core.UDTValue serialize(T value)
value
- the valueprotected abstract T deserialize(com.datastax.driver.core.UDTValue value)
value
- the valueCopyright © 2019. All rights reserved.