为在线和离线使用的应用程序分离层的好策略是什么? [英] What is a good strategy for separating layers for an application that can be used online and offline?

查看:141
本文介绍了为在线和离线使用的应用程序分离层的好策略是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Web应用程序,它具有断开连接的Java Swing桌面应用程序。使用桌面应用程序,用户可以连接到Internet并从服务器下载所需的数据。他们可以脱机并脱机使用应用程序。当他们重新连接到互联网时,他们可以将他们的数据同步回服务器。

I have a Java web application that has a 'disconnected' Java Swing desktop app. Using the desktop app users connect to the internet and download data they need from a server. They can disconnect and use the application offline. When they reconnect to the internet they can sync their data back to the server.

服务器本身是一个Java EE Web应用程序,桌面应用程序是一个有限的功能版本网络应用程序。到目前为止,所有业务逻辑和数据访问代码都针对每个应用程序单独编码。每个应用程序的数据存储都不同(Web是SQL Server,Desktop是Serialized对象)。一些新要求涉及对这两个应用程序的大量开发。由于功能相同,我想分层数据访问代码和业务逻辑,以便我可以轻松地将它重用于两个应用程序。

The server itself is a Java EE web application and the desktop app is a limited functionality version of the web app. Up until now all business logic and data access code was coded separately for each application. The data stores were different for each application (Web is SQL Server and Desktop is Serialized objects). Some new requirements involve a lot of development to both applications. Since the functionality is the same I want to layer the data access code and business logic so I can easily reuse it for both applications.

我的计划是执行以下操作。

My plan is to do the following.

1)创建DAO库(JPA)

1) Create a DAO library (JPA)

切换我的DAO(当前是JDBC)以使用Java持久性API。这样我就可以开始在桌面应用程序上使用RDBMS,如derby,sql express或类似的东西,并重用entites和DAO代码来完成所有的db操作。我可以将它捆绑到一个类库中,并为Web和桌面使用相同的库。

Switch my DAOs (currently JDBC) to use Java Persistence API. This way I can start using a RDBMS on the desktop app like derby, sql express or something similar and reuse the entites and DAO code to do all of the db operations. I can bundle this into a class library and use the same library for the web and the desktop.

2)为业务逻辑创建一个库

2) Create a library for business logic

Web应用程序是用struts 2编写的。我将在Action类中使用所有逻辑,但它将在POJO中使用。使用业务逻辑创建jar类库。我可以将lib添加到我的Web和桌面项目中。然后我可以从我的struts操作和桌面应用程序调用POJO。

The web app is written in struts 2. I will take all of the logic in my Action classes and but it in POJOs. Create a jar class library with the business logic. I can add the lib to my web and desktop project. Then I can call the POJOs from my struts actions and from my desktop application.

我认为JPA将负责复制数据访问代码并放置业务逻辑(在大多数情况下是dao调用)在一个单独的库中将负责复制业务逻辑。

I assume that the JPA will take care of duplicating the data access code and putting the business logic (which for the most part are dao calls) in a separate library will take care of duplicating the business logic.

所以我的问题是:什么是分离的好策略可以在线和离线使用的应用程序层?

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

如果您有任何不同的建议,我开始这个项目时的任何警告或任何框架可能会帮助我,请告诉我。

If you have any recommendations for achieving this differently, any warning for me as I begin this project or any frameworks that might help me please let me know.

推荐答案


分离图层的好策略是什么?可以在线和离线使用的应用程序?

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

嗯,从高层的角度看你的计划看起来不错,肯定会简化维护您的应用程序。我没有太多要补充:创建JPA实体,服务层,如果您觉得有需要,可以使用DAO层 1 。然后在两个应用程序中使用这些部分,使用不同的JPA设置。

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.

以下是一些附加说明:


  • 我会在桌面(derby)上找到一个完整的Java数据库,它将更容易管理它的生命周期。

  • Spring会提供良好的整体支持(用于分层,用于声明式事务管理)。

  • JPA不为合并或数据库提供任何设施,您必须自己实施并处理诸如冲突变更等痛苦的事情。

  • 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 我实际上甚至会考虑直接从跳过DAO并访问JPA的 EntityManager 服务层。有些人可能不同意这一点,但事实是 EntityManager 已经实现了 Domain Store 模式几乎完成了DAO模式所做的事情,并且在DAO后面屏蔽它没有多大价值。

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.

这篇关于为在线和离线使用的应用程序分离层的好策略是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆