本文介绍了使用DAO与复合对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 只是简单的JDBC(没有JPA,ORM)
我试图重写一组DAO是这样的设置: / li>
- 没有使用任何界面
- 在插入对象之前进行大量检查
- >
我的主要问题是:
如何保持/检索由多个其他对象组成的业务对象?
例如
解决方案
不知道为什么你不想使用JPA while你想要你的业务对象被链接,但至少你应该使用Spring JDBC模板,这将缓解你从一些样板代码。
关于其他约束,我会做它如下:
- 我仍然会使用接口来定义
DAO
方法在支持DAOImpl
的Spring JDBC模板中实现它们。使用DAO无处不在和注入DAOImpl。 - 我的DAO将是简单的一对一映射到基础表,每个DAO不知道其他DAO的存在。 / li>
- 我的管理器图层将具有运行验证检查和准备需要持久化的对象集的所有业务逻辑,调用相应的DAO和适当的方法(CREATE / UPDATE / DELETE)
- 同样,Manager层将遵循基于接口的实现,而视图层将使用ManagerImpls注入管理器类型。
- only plain JDBC (no JPA, ORM whatsoever)
- no interfaces used
- lots of checks before inserting an object
- Business objects are strongly linked
- I would still employ interfaces to define the
DAO
methods and implement them in a Spring JDBC template backedDAOImpl
. Use the DAO everywhere and inject the DAOImpl. - My DAOs will be simply one-to-one mapping to the underlying tables and each DAO wouldn't know about the existence of other DAOs.
- My Manager layer will have all the business logic that runs validation checks and prepares the set of objects that need to be persisted, calls the appropriate DAO and appropriate method (CREATE/UPDATE/DELETE) to persist the objects.
- Again, the Manager layer will follow the interface-based implementation and the view layer would have manager types injected with the ManagerImpls.
我的两分钱!
I am trying to rewrite a bunch of DAOs here is the setting:
My main question is:How do I persist/retrieve a business object that is composed of multiple other objects?e.g. does my CustomerDAO know the AddressDAO and retrieve the csutomers adresses from there?
解决方案
Not sure why you don't want to use JPA while you want your business objects to be linked, but at least you should use Spring JDBC template that would relieve you from some boilerplate code.
Regarding the other constraints, I would do it as follows:
My two cents!
这篇关于使用DAO与复合对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!