Peristence Web Service for Rich Client Java (Swing) Applications

I am rewriting my client server client application (Swing) into a three-tier application with rich NetBeans RCP client.

By default, Hibernate and other JPA providers can only be used in a very cumbersome way from rich clients (own database connection that does not cut through firewalls, loss of lazy load, conceptual problems with Session / EntityManager lifecycle management ... etc. others Problems). So you need some kind of extension to conveniently use them with wealthy customers.

Wealthy clients usually call webservices at the level of business logic (on the server). Typically, dedicated web service methods handle the CRUD operations of each type of object. Now I would not want to write my own web service for CRUD operations of each constant class of my application, so I thought that there could be a generic persistence web service for operations that can handle at least all CRUD operations of the application.

Is there such a save service?

Below are the details of my ideas / requirements:

The service should work with JPA-annotated POJOs , so the server must have some support for JPA-resilience. I am currently using Hibernate, so if it actively supports Hibernate, this is a plus. Of course, POJO classes should be included in the server-side JPA configuration, I do not expect ANY kind of unknown POJOs to be processed.

I would not like to create separate Value Objects or data transfer objects for sending data between client and server parts of the service. I would like to use only JPA-annotated POJOs even for transmission . I think this is standard practice these days.

The client should receive data and send data with HTTP requests to the server service in order to reduce communication problems with the firewall. Using an HTTP proxy must be customizable.

The client part of the save service can receive POJO list results for completed JPA QL requests (sent as a simple string , optional ** named parameters ** also sent in the request). These requests are sent by the client in the form of a webservice call or a simple HTTP request to a servlet . It would be nice if several JPA requests could be sent on one request, the Client receives the result of the requests in the form of POJO lists, which can have lazy loaded collections and links to objects (they are not sent from the server during the request).

Customer service data storage services should perform lazy load requests automatically / transparently when the client application accesses the lazy-load attribute in the POJO (later, and not in the original request). Thus, transparent lazy loading should remain operational after the POJO has been passed to the client .

New, updated / dirty or to be deleted POJOs can be sent by the client by the save service side to the server, where the changes are saved and the success / failure status is sent back (for example, the identifier that was assigned by the newly saved POJO). Multiple POJOs to be stored can be sent on one request.

It should have a mechanism for marking the boundaries of the transaction , so several independent calls to the HTTP service can be made in a single database transaction (saving something like Session / EntityManager. BeginTransaction () , commit () and rollback ()).

It would be nice if validation and access control checks can be connected to the server component.

Is there such a conservation service project? Perhaps as an extension shipped with the JPA continuity provider?

+4
source share
3 answers

When I developed a similar application back in 2002, we searched around the world for a framework to use, but finally had to launch our own. Subgraphs of permanent objects were transported to the swing client by translating these objects into DTO objects (DataTransferObjects), which preserved attribute mapping and information if the client was contaminated with an attribute. On the way back to the server, only dirty attributes were updated in trx.

You might want to use JDO 2.0 as your save layer. It supports detaching objects or subtrees from the graph of permanent objects, sending these individual objects through wiring, and reattaching them to a subsequent transaction.

However, you lose the ability to minimize the data that you send via cable.

Best bet: start your own mechanism and add the createDTO and updateFromDTO method to your permanent objects, but I would be very happy to be wrong.

+1
source

Transactions, server request processing, verification and access control are all that, as you said, go beyond the level of storage. You will not find a conservation service that implements these things.

Thus, there are many web frameworks that quickly provide you with a basic implementation of CRUD operations. In particular, the term you are looking for is forests .

Grails is a popular Java web environment that provides scaffolding . I am sure there are many others. I would suggest looking at Grail.

0
source

I will use Spring with JPA. Spring provides reasonable defaults for most of the storage management issues you talked about. (Transaction management, lazy loading)

0
source

Source: https://habr.com/ru/post/1332744/


All Articles