spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
379 stars 311 forks source link

Investigate on using Cassandra CodecRegistry for type mapping [DATACASS-283] #454

Open spring-projects-issues opened 8 years ago

spring-projects-issues commented 8 years ago

Mark Paluch opened DATACASS-283 and commented

The Cassandra 3 Java driver provides a CodecRegistry which allows the usage of custom codecs for object and UDT value mapping. The mapper is an additional artifact which could be added optionally to the classpath.

@UDT(name = "address")
public class Address { ... }

codec = AnnotationParser.parseUDT(mappedClass, ReflectionMapper.factory(), this);
session.getCluster().getConfiguration().getCodecRegistry().register(codec);

Row row = session.execute("select address from user where id = 1").one();
Address address = row.get("address", Address.class);

See also https://github.com/datastax/java-driver/tree/3.0/driver-mapping


Reference URL: https://datastax.github.io/java-driver/manual/object_mapper/custom_codecs/

Issue Links:

mp911de commented 3 years ago

Calling codecFor(…) responds with an exception if the type isn't found. So a plain approach to ask the codec registry whether a particular codec can be resolved/handled by the driver would impose a lot of CPU drag.