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

I have a Java web application that has a โ€œdisabledโ€ desktop Java Swing application. Using desktop application users connects to the Internet and downloads the data they need from the server. They can disconnect and use the application offline. When they reconnect to the Internet, they can synchronize their data with the server.

The server itself is a Java EE web application, and the desktop application is a limited functional version of the web application. Until now, all business logic and data access codes have been encoded separately for each application. The data stores were different for each application (SQL Server web server and Desktop are serialized objects). Some new requirements require a lot of development for both applications. Since the functionality is the same, I want to add data access code and business logic so that I can easily use it for both applications.

My plan is as follows.

1) Create a DAO library (JPA)

Switch my DAOs (currently JDBC) to use the Java Persistence API. That way, I can start using RDBMS in a desktop application like derby, sql express or something like that, and reuse entites and DAO code to do all the db operations. I can link this to the class library and use the same library for the web and desktop.

2) Create a library for business logic

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

I assume that the JPA will take care of duplicating the data access code and put the business logic (which is mostly dao calls) in a separate library to take care of the duplication of business logic.

So my question is: what is a good layer separation strategy for an application that can be used online and offline?

If you have any recommendations for achieving this in a different way, any warning for me when I start this project or any framework that can help me, let me know.

+4
java web-applications swing jpa code-reuse
Aug 11 2018-10-18T00:
source share
1 answer

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

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

Here are some additional notes:

  • I would like to get a full Java database on the desktop (derby), it will be easier to manage its life cycle.
  • Spring will provide good general support (for layers, declarative transaction management ).
  • JPA does not provide any merge or database options, you will have to implement it yourself and handle painful things like conflicting changes, etc.

1 I would even consider skipping the DAO and accessing the JPA EntityManager directly from the service level. Some people may not agree with this, but the fact is that the EntityManager already implements the Domain Store template, which does pretty much what the DAO template does and doesn't really matter when protecting it from the DAO.

+2
Aug 11 '10 at 21:19
source share



All Articles