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.
6
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.
This is really dependant, for instance if you take managed entities in JPA, you will almost never used the update method directly, since updating the model will be automatically transefered to the database on commit.
On the other hand, having JPA while not using managed entities through converting DTO to business model is very inefficient.
Furthermore, there are document NoSQL database, key-value, ….
In my opinion, just design a proper service interface and one implementation that use properly ORM objects and a proper JUnit Suite tests. Then if you have to switch, rewrite the same service with it’s own DAO layer for NoSQL when it will be time against the same suite of JUnit test.