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

安稳与你 提交于 2019-12-14 03:58:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16886949/gwt-request-factory-multiple-queries-for-collection-from-the-servicelayerdeco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!