Reputation: 1914
Suppose I have a users table in cassandra called 'UserPrincipal', the repository will look something like the following
public interface UserRepository extends CassandraRepository<UserPrincipal>
{
@Query("SELECT * FROM UserPrincipal WHERE email = ?0")
UserPrincipal findByEmailAddress(String emailAddress);
}
If I need to query the table with username for example, I have to denormalize the table and create a duplicate and let's call it UserPrincipalByUsername which is identical to the first one and only different with the primary key, now, can I use the following Interface as a repository? and what about saving/removing a user to/from both tables simultaneously to maintain data consistency?
public interface UserRepository extends CassandraRepository<UserPrincipal>
{
@Query("SELECT * FROM UserPrincipal WHERE email = ?0")
UserPrincipal findByEmailAddress(String emailAddress);
@Query("SELECT * FROM UserPrincipalByUsername WHERE username= ?0")
UserPrincipal findByUsername(String username);
}
It can be noted that two separate interfaces can be used to deal with each table alone, but still, I need to have some logic to maintain the consistency at some point.
I am using Cassandra 2.0.11, CQL spec 3.1.1, Spring data Cassandra 1.3.2 and Spring boot 1.3.1
Upvotes: 2
Views: 1994
Reputation: 1914
The only procedure I found to solve this is, as mentioned in the question, to use two separate interfaces to deal with each table alone, I have added a wrapper class to use both of them to save
using one call, but this dosen't guarantee consistency all the time (in a case of server/system failure for example), but this is ok in my specific application.
Upvotes: 0