GWT Request Factory - Multiple queries for collection from the "ServiceLayerDecorator.isLive()" - method

StackOverflow https://stackoverflow.com/questions/16886949

  •  30-05-2022
  •  | 
  •  

質問

I had the problem, that every time i retrieved a collection from the gwt request factory, there was the "findEntity()"-method called for every entity in that collection. And this "findEntity()"-method calls the SQL-Database.

I found out that this happens because request factory checks the "liveness" of every entity in the "ServiceLayerDecorator.isLive()"-method (also described here: requestfactory and findEntity method in GWT)

So i provided my own RequestFactoryServlet:

public class MyCustomRequestFactoryServlet extends RequestFactoryServlet {


    public MyCustomRequestFactoryServlet() {
        super(new DefaultExceptionHandler(), new MyCustomServiceLayerDecorator());

    }

}

And my own ServiceLayerDecorator:

public class MyCustomServiceLayerDecorator extends ServiceLayerDecorator {

    /**
     * This check does normally a lookup against the db for every element in a collection
     * -> Therefore overridden
     */
    @Override
    public boolean isLive(Object domainObject) {
        return true;
    }
}

This works so far and I don't get this massive amount of queries against the database.

Now I am wondering if I will get some other issues with that? Or is there a better way to solve this?

役に立ちましたか?

解決

RequestFactory expects a session-per-request pattern with the session guaranteeing a single instance per entity (i.e. using a cache).

The proper fix is to have isLive hit that cache, not the database. If you use JPA or JDO, they should do that for you for free. What matters is what "the request" thinks about it (if you issued a delete request, isLive should return false), not really what's exactly stored in the DB, taking into account what other users could have done concurrently.

That being said, isLive is only used for driving EntityProxyChange events on the client side, so if you don't use them, it shouldn't cause any problem unconditionally returning true like you do.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top