Last weekend I started working on my own in a small library for persisting java objects in different datasources and with different formats so that I was going to be able to leverage that library at work.
I intended to support different datasources. I started with MongoDB, Redis, File System, Cassandra, Riak and CouchDB.
The idea of the solution is to work as a kind of logger, so I took the main architecture characteristics from the Apache Log4j project. So for example I had the idea to easily plug the different datasources in what I called Appenders, following the Log4j concept.
Another thing I wanted is to be able to easily configure it with Spring, so I also created a small namespace for it.
The simple architecture I ended up with was something like this:
The idea is that any object will get “normalized” into a library internal object by using an implementation of a Normalizer. Then this normalized message goes to any of the Appenders where it gets converted into a provider specific message (e.g. DBObject in Mongo) then the appender takes care of storing it.
All the appenders and datastore libraries I currently use are very simple, and none of the datasources have been optimized anyhow, I work with them with their default installation behaviour.
If not for anything else, the library can at least serve to see the basic of how to interact with the different data sources. So next I show how all the appenders I have for the different Datasources.
This is the abstract appender they all derive from:
As an example of how the library would be used there are a couple of Tests. Like the following:
If using from Spring, I’m developing a simple namespace so things like the following can be done:
The Maven dependencies for all the drivers are:
The source code is in Github
Great books on NoSQL