views:

624

answers:

3

Hello,

As I had written in title, I am trying to learn Spring 3.0 (I already know Django, Pylons and few simpler MVC frameworks) and try to use Cassandra as a backend for my web application.

Are there any real world examples of doing this? Or maybe some tutorials? I know about the existence of documentation of both technologies, yet I am looking for something "faster" to read and get me rolling.

+2  A: 

AFAIK there is no "public" tutorial or example covering Spring (3.0) in conjunction with Cassandra. So maybe you could look into it :)

I would recommend to start looking at the "template" terminology in Spring (e.g JDBCTemplate and HibernateTemplate) and create something like a "CassandraTemplate".

Schildmeijer
+1  A: 

If you are already familiar with MVC frameworks then you should be aware that which database/datastore you use in the backend shouldn't impact your MVC application as a whole, or how you structure things - it should only affect your data layer and how it retrieves data.

With Spring MVC, the accepted practice is that you represent your data model as a series of "domain model / classes", which are typically just POJOs to hold your data. "Domain" here means that it is related to your problem domain; so if you have an application which deals with customers ordering things you'd want to have a Customer class, an Order class, etc.

Each of the three layers of your MVC application - the controllers, the service/business logic layer, and the DAO layer interacts with these domain model classes. Since the DAO layer is responsible for retrieving or updating this data in the backend, this means it is the DAO layer which needs to know how to fetch your Customer or Order class from Cassandra, how to update certain Customer fields, etc.

So there is nothing special about how you would build your Spring MVC application itself when using Cassandra or any other "NoSQL" database. You'll just need to provide different implementations of your DAO classes which can communicate with Cassandra.

If you are asking if there are any pre-built Spring utilities that can access Cassandra (or Thrift) then the answer is no, at least as far as what's in Spring 3.0. But this should be pretty simple to write once you have the DAO interface set and all other layers of your application in place.

matt b
matt b, thank You for such a great explanation of things. I will try to look more information and I hope that You are right about the fact, that things will get clear as soon as I will have all layers in place.
zeroDivisible
+1  A: 

I don't think there is any cassandra-spring library available. However, you could use Spring to instantiate and configure the bean that talks to Cassandra, and inject that into any other bean you have that requires persistence. That way you can let it benefit from Inversion Of Control and all the facilities the Spring ApplicationContext offers. That way you can separate the code that is aware of the cassandra datastore from your business logic and use spring.

So, your component that talks to Cassandra will be of the [@Repository][1] stereotype, e.g. it is a Repository, just like a repository that talks, for instance to a JDBC datasource.

Hans Westerbeek