Pregunta

I noticed that when I invoke

    SomeProxy proxyNew = someRequestContext.edit(proxyOld);
    proxyNew.setSomething(somethingNew);
    someRequestContext.mySaveMethod(proxyNew).fire();

The entity returned from

    @Override //from Locator<SomeEntity ,IdClass>
    public SomeEntity find(Class<? extends SomeProxy > clazz, IdClass id) {
    ...
    }

is used in server when saving method is invoked and only those property/istance variable values of proxyNew are transfered to server implementation mySaveMethod(SomeEntity entity)which are new in comparison with the returned entity.

Now. I understand that there is some comparison in order to provide server side only with deltas so there is efficiency in communication but I think it is somehow offset by additional processing/transfer time needed by implementation of public SomeEntity find(Class<? extends SomeProxy > clazz, IdClass id) which retrieves the entity objects from database.

My question now is, how should this be correctly implemented in system with persistence services exposed via stateless session bean which provide services to GWT server side servlets/DAO objects. Correctly implemented in a way that the highest efficiency and lowest waiting time is achieved. Also could someone explain to me this RequestFactory aspect/process in greater detail?

My example: I retrieve OrganizerEntry entities from persistence layer for a certain day span - a week.

So the method like retrieveOrganizerEntries(Date from, Date to) is invoked in persistence layer.

Then I see that for each OrganizerEntry entity object obtained which is to be sent to the client layer, another query is made, like retrieveOrganizerEntry(int id).

So not only are the same objects queried twice, but the second time they are queried one by one in a very inefficient manner.

How can this be improved? Should I cache in DAO/servlet objects somehow the results from first query and let public SomeEntity find(Class<? extends SomeProxy > clazz, IdClass id) search the cache? Is it way to go to implement this method returning null or newly created empty entity (new OrganizerEntity()) and before invoking the persist/save method from the client just setting every single property/instance variable value?

Where can I find more examples and explanation about this stuff? Because http://www.gwtproject.org/doc/latest/DevGuideRequestFactory.html seems to me not very exhausting .

¿Fue útil?

Solución

1.) Regarding the rf internals, you can refer to this document. But I guess Thomas Broyer is going to respond to this in more detail.

The basic flow is following:

  • properties that are modifed through the setter are transmitted to the server.
  • server uses find() to retrieve the entity and calls the corresponding setters (whatever you also called on the client).
  • Validation rules are processed
  • The entity is passed to your service method.

2.) With RF you need one session per http request aka OpenSessioninview pattern. . The first level cache of your persistence layer (i.e. Hibernate) should make multiple redundant calls to find() really efficient so you usually will only hit the database once during the session`s lifetime.

3.) If you don't care about EntityProxyChange events on the client you could override the isLive() method of your Locator and just return true (see here for more details). That's also probably the reason why the find() method is called when you retrieve a list of OrganizerEntry instances because for each OrganizerEntry RF checks if it's still alive by calling 'isLive()' which itself calls find().

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top