DAO 模式多表
我知道这个问题之前已经讨论过,但我找不到答案。我的问题是我想在非关系数据库中实现 DAO 模式...
对于简单的 CRUD 操作,这似乎简单明了...
只需获取 DAO 工厂提供的数据库句柄或在 Dao 对象构造期间...
问题是,当我需要从多个表获取数据时
,如果返回的对象属于 2 个或更多表的联接,我应该把它放在哪里?
例如,如果我想获取某些订单的客户地址?我应该返回仅填充地址字段的完整客户列表吗?我应该把它放在哪里?在 customerDao ?看起来 DAO 会增长得太多而无法涵盖所有内容。
它似乎变得太复杂了。另外,对于父子关系,我应该创建一个 ParentChildDao 吗?返回一个ParentDao对象?
I know that this 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 tables
If 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为 CRUD 操作保留具体的 DAO,并根据其业务功能(用户故事、用例)或其他标准为特定操作创建自定义查询对象。
但实际上,如果您的数据访问变得越来越复杂,也许最好切换到某些 ORM。
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.