Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading calls to Datastax Java APIs that are gone in 3

There are a number of APIs that are gone now in Datastax 3.x driver. They were used to do 'framework' level driver wrapper classes I have.

https://github.com/datastax/java-driver/tree/3.0/upgrade_guide

The upgrade guide offers no examples of how to replace calls to the removed APIs (that I care about anyway). Here are several that are missing and I'm trying to upgrade my code. Any ideas what has 'replaced' them?

DataType.serialize(Object value, ProtocolVersion protocolVersion) 
DataType.deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) 
DataType.asJavaClass()
DataType.Name.asJavaClass()

Any help on which APIs calls to these methods should now be invoking would be appreciated.

like image 378
Jason Avatar asked Oct 19 '22 20:10

Jason


1 Answers

Item #2 references the changes to DataTypes via custom codecs. A TypeCodec is no longer attached to a DataType since in the 3.0 version of the driver you can define your own codecs for data types. Therefore these methods are no longer provided directly via DataType.

Custom codecs (JAVA-721) introduce several breaking changes and also modify a few runtime behaviors.

Here is a detailed list of breaking API changes:

...

DataType has no more references to TypeCodec, so most methods that dealt with serialization and deserialization of data types have been removed:

  • ByteBuffer serialize(Object value, ProtocolVersion protocolVersion)

  • Object deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)

  • Class asJavaClass()

The Custom Codecs should provide the details you need to accomplish everything needed if you have the DataType by resolving the TypeCodec for it using CodecRegistry.codecFor or the TypeCodec static methods for resolving the default codecs. TypeCodec provides the methods you need, i.e.:

TypeCodec<Long> bigIntCodec = TypeCodec.bigint();
bigIntCodec.serialize(10L, protocolVersion);
bigIntCodec.deserialize(bytes, protocolVersion);
Class<?> clazz = bigIntCodec.getJavaType().getRawType();
like image 87
Andy Tolbert Avatar answered Oct 21 '22 22:10

Andy Tolbert