javacassandraspring-data-cassandra

How to enable optimistic locking (versioning) in Cassandra using Spring-Data?


The answer Cassandra Optimistic Locking but the question describes that Optimistic Locking (versioning) exists in Cassandra.

My question is how to do it in Spring Boot?


Solution

  • The lightweight transactions in Cassandra Spring Data are supported via InsertOptions class or UpdateOptions - you create an instance of it via corresponding builder, for example, InsertOptions.InsertOptionsBuilder, and then pass instance of it to the corresponding operation insert or update.

    Result of operation is obtained from instance of WriteResult class that is returned by insert/update by calling the .wasApplied function.

    More detailed information could be found in the documentation.