What’s new in Spring Data Lovelace for Redis and Apache Cassandra? | Java

Map and Tuple data types are specific types in that allow storing multiple values within a single column. Previously, we supported both types in their raw form in mapped entities, which means that you could use only maps with primitive keys and values. For tuples, you could only use TupleValue, the raw Cassandra driver type, without further mapping or even schema support.

With this release, we added mapping and conversion support for Map- and Tuple-typed properties. Maps can now contain non-primitive keys and values, and the conversion layer applies potentially registered converters.

Consider the following types:

Manufacturer is a mapped user-defined type that is used by the map as a key. Values are represented as List of strings. We can now refactor the code to use a proper Currency type (such as .util.Currency) within the list. To do so, we provide converters between String and Currency and register these through CassandraCustomConversions. The following example shows how to do so:

After registering the converters, we can go forward and use Currency within the Supplier type to work with value objects instead of primitives, as the following example shows:

Tuples were not really usable with previous versions of for Cassandra. Using tuples required direct Row interaction and TupleType retrieval to create appropriate tuple values. Therefore, we decided to provide mapped tuple types, as the following example shows:

Mapped tuples are annotated with @Tuple, and the individual components of a tuple refer (by using @Element(…)) to their ordinal index within the tuple. The converter inspects loaded tuples and maps these onto regular Java classes that are part of your domain model. You no longer need to interact with TupleType and TupleValue directly – although you still can – but you can represent tuple values in a type-safe approach. Mapped tuples benefit from the various mapping-features of the converter and can refer to types that have a custom converter registered.

Support for maps and tuples also includes schema generation to rapidly set up a schema by deriving the type from your domain model.

See our examples for mapped tuples for further details.

serverpoint hosting banner

You might also like More from author

Leave A Reply

Your email address will not be published.