Question

I am working in a Spring web application using Cassandra with Astyanax client. I want to transform result data retrieved from Cassandra queries to a POJO, but I do not know which library or Astyanax API support this.
For example, I have User column family (CF) with some basic properties (username, password, email) and other related additional information can be added to this CF. Then I fetch one User row from that CF by using OperationResult> to hold the data returned, like this:

OperationResult<ColumnList<String>> columns = getKeyspace().prepareQuery(getColumnFamily()).getRow(rowKey).execute();  

What I want to do next is populating "columns" to my User object. Here, I have 2 problems and could you please help me solve this:

1/ What is the best structure of User class to hold the corresponding data retrieved from User CF? My suggestion is:

public class User {
    String userName, password, email; // Basic properties
    Map<String, Object> additionalInfo;
}  

2/ How can I transform the Cassandra data to this POJO by using a generic method (so that it can be applied to every single CF which has mapped POJO)?
I am so sorry if there are some stupid dummy things in my questions, because I have just approached NoSQL concepts and Cassandra as well as Astyanax for 2 weeks.
Thank you so much for your help.

Was it helpful?

Solution

You can try Achilles : https://github.com/doanduyhai/achilles, an JPA compliant Entity Manager for Cassandra

Right now there is a complete implementation using Thrift API via Hector.

The CQL3 implementation using Datastax Java Driver is in progress. A beta version will be available in few months (July-August 2013)

CQL3 is great but it's still too low level because you need to extract the data yourself from the ResultSet. It's like coming back to the time when only JDBC Template was available.

Achilles is there to fill the gap.

OTHER TIPS

I would suggest you to use some library like Playorm using which you can easily perform CRUD operations on your entities. See this for an example that how you can create a User object and then you can get the POJO easily by

User user1 = mgr.find(User.class, email);

Assuming that email is your NoSqlId(Primary key or row key in Cassandra).

I use com.netflix.astyanax.mapping.Mapping and com.netflix.astyanax.mapping.MappingCache for exactly this purpose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top