MongoDB / Cassandra JPA Service using Kundera


           Earlier, i have discussed many NoSQL datastores in my previous blog. Schema less datastores are really required to make the application scale at any point of time. MySQL can fits only up to small set of data. When the data grows up, its very hard to scale the MySQL DB by using shards/clusters. I opted to chose, MongoDB is one of the best key-value and schema-less store for the immediate migration strategy from SQL. Because, MongoDB is very ease to install. For querying the complex data, in other NoSQL DBs, you need to write a separate Map/Reduce program to segregate  your data. But in MongoDB, simply we can write the queries to analyze it.
Java Objects mapping with NoSQL data store similar to SQL ORM (Object Relational Mapping) using JPA. I am sure the developer will be more happier to use JPA in NoSQL. I found a NoSQL JPA library named Kundera. The beauty of this library that it supports, many NoSQL and relational DBs  which we can switch over by simply changing the configuration.  The below table is the list that Kundera supporting DBs.
 
I wrote a core API by using this Kundera library for manipulating any set of operations irrespective of the data store.  Its using JPA to persists the data and all the CRUD (Create, Read, Update & Delete) operations can perform via Restful webservice. Kundera’s Persistence manager, is a configurable one which we can map any datastore details. To setting up the Entity Manager connection object in below from persistence unit.

 JPA’s Persistence Manager will keeps the connection of the MongoDB datastore. We can easily switch over to Cassandra, HBase or any RDBMS databases, by simply modifying the connection URL and DB parameters in the “persistence.xml“.  In my API, i have a class called “AbstractJPA” which does all the CRUD operations.
   
 The Database mapping object class which contains the table name, column fields and id column mapping to Java objects in Class name and all property fields respectively. The mappings all are annotation based in the java class.
Entity name is the actual DB name mapped in annotation header of the data object class. Annotation “@id” which prescribes the primary key column of the table and “@column” represents the column details. In this API, the generic DAO & Spring MVC patterns are used to do the data store operations and Web Service as  exposed as Spring controller & service are used here. The abstract flow are in below.,

Finally the Spring controller, which expose all the operations as a service.
You can find this code available in github.
About these ads
This entry was posted in NoSQL. Bookmark the permalink.

2 Responses to MongoDB / Cassandra JPA Service using Kundera

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s