The REST service I mentioned previously uses
Cassandra for data storage and talks to it using
Spring Data Cassandra (1.2.2). Integrating with it was easy peasy, all it took is a couple of beans in configuration, and a couple of Repository interfaces (which caused some problems with Spring Boot as I described in
this post). But then a new requirement came in, columns in Cassandra had to be inserted with TTL (time to live).
CrudRepository methods don't support TTL. In order to support TTL during insertion,
save method has to be able to take
ttl as a parameter. I wanted to implement this functionality once for all repositories in the application. As described in the
documentation, 2 classes needed to be created:
Interface MyRepository, where I added another save method:
Class MyRepositoryImpl, where the method was implemented:
Notice that the documentation is for JPA repositories. For Cassandra repository one more step was needed (I did not find the way around it).
Reporsitory Factory Bean needed to be created:
and it had to be defined in Configuration:
Now we can define a
Repository, e.g :
Then we just autowire it and call it: