Java – Implementing a NoSQL and RDBMS compatible DAO

daodata modelingdesign-patternsjavaorm

What would be the correct way to design a DAO which implementation is first going to be targeting a MS SQL database with a STAR model, but yet, business requirements specify the application must be flexible enough that it would be able to be migrated to a NoSQL database in the future if required. Which type of NoSQL, no idea…

My confusion is that i cannot seem to figure out how could I build independent DAOs for the STAR Dimensions and Facts tables which could then be swapped for a completely different model that might not even be table oriented (riak/mongo/whatever).

Therefore,

Should I create DAOs which rather than abstracting the table, it abstracts the CRUD operations – for example create IDaoInsert which can then be implemented as SQLInsertDaoImpl and MongoInsertDaoImpl, each with a completely different model logic etc.

or

Should I just create the typical DAO design whose interface would be something like IDaoCustomerDimension, and the implementation SqlDaoCustomerDimesionImpl and MongoDaoCustomerDimentionImpl respectively?

Hibernate/Etc are out of the scope of this question for the time being.

Best Answer

Your architecture should look something like this:

Data source <--> Data source driver <--> CRUD interface <--> Application

You'll need one data source driver implementation for each type of data source. The CRUD interface will be the same regardless of data source.

Note that you can have more than just CRUD methods. You might want to return collections, for example. Just make sure that whatever you do on the Data Source side is translatable to your API on the CRUD side for all possible data sources.