What is a good strategy for separating layers for an application that can be used online and offline?

谁都会走 提交于 2019-12-04 11:31:20

What is a good strategy for separating layers for an application that can be used online and offline?

Well, your plan looks decent from a high-level point of view and will definitely simplify the maintenance of your applications. I don't have much to add: create JPA entities, a service layer, and if you feel the need, a DAO layer1. Then use these parts in both of your applications, with different JPA settings.

Here are a few additional notes:

  • I would go for a full Java database on the desktop (derby), it will be easier to manage its lifecycle.
  • Spring would provide good overall support (for layering, for declarative transaction management).
  • JPA doesn't provide any facility for the merge or databases, you'll have to implement that yourself and handle painful things like conflicting changes, etc.

1 I would actually even consider skipping the DAOs and accessing JPA's EntityManager directly from the service layer. Some people might not agree with this but the fact is that the EntityManager already implements the Domain Store pattern which does pretty much what the DAO pattern does and and there is not much value at shielding it behind a DAO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!