DAO Pattern multiple tables
I know that thi开发者_运维技巧s has been discused before but i cant find an answer.. My problem is that i want to implement DAO pattern in a non relational database...
For simple CRUD actions this seems straightforward and easy... Just get a database handle provided by the DAO factory or during Dao object construction... The problem is that when i need to get data from multiple tablesIf the returned object belongs to a join of 2 or more tables where should i put it?
For example if i want to get the addresses of customers for some orders? Should i return a whole list of Customers having only the address field populated?? And where should i put that ? At customerDao ? It seems that DAO would grow too much to cover everything..
It seems that it is becoming too complex. Also for Parent Child relationship should i create a ParentChildDao ? to return a ParentDao object?
You can leave concrete DAO for CRUD operations and create custom query objects for specific operations based on their business function (user stories, use cases) or another criteria. But really, if your Data Access is getting complicated maybe it's better to switch to some ORM.
精彩评论