开发者

GWT Request Factory - Several entity locators for the same entity type

I want to be able to use different entity locators for the same domain object. I use Twig and it has an option to load an object fully or partially. When I run the lite request fetchRangeLite, the locator TwigLocator is used instead of TwigLiteLocator. My current implementation is:

Proxies

@ProxyFor(value = MyDomain.class, locator = TwigLocator.class)
public interface MyDomainProxy extends EntityProxy {}

@ProxyFor(value = MyDomain.class, locator = TwigLiteLocator.class)
public interface MyDomainLiteProxy extends EntityProxy {}

Request

@Service(value = MyDao.class, locator = DaoServiceLocator.class)
public interface MyRequest extends RequestContext {
    Request<List<MyDomainProxy>> fetchRange(Integer start, Integer length);
    Request<Integer> getCount();
    Request<List<MyDomainLiteProxy>> fetchRangeLite(Integer start, Integer length);
}

DAO

public List<MyDomain> fetchRange(Integer start, Integer length) {
  ...   
}

public List<MyDomain> fetchRangeLite(Integer start, Integer length) {
  ...   
}

I was expecting the lite locator to be used but it's not the case. So how does RF choose which locator it should use for a specific domain type?

UPDATE

My domain object is composed by list of lists.

public class MyDomain extends DatastoreObject {
  private List<A> a;
}

public class A {
  private List<B> b;
}

When a proxy of my MyDomain object is sent from the server to the client, Twig also loads all the A's and all the B's which takes time. I am only interested by a property in the MyDomain object, that's why I want to use a "lite" locator.

TwigLocator

@Override
public DatastoreObject find(Class< ? extends DatastoreObject> clazz, Long id) {
    ObjectDatastore myDatastore = datastoreProvider.get();
    DatastoreObject object = myDatastore.load(clazz, id);
    return object;
}

TwigLiteLocator

@Override
public DatastoreObject find(Class< ? extends DatastoreObject> clazz, Long id) {
    ObjectDatastore myDatastore = datastoreProvider.get();
    myDatastore.setActivationDepth(0);
    DatastoreObject object = myDatastore.load(clazz, id);
    return object;
}

myDatastore.setActivationDepth(0); tells the datastore to load only the properties in MyDomain and not the sublevel (List) properties.

The DAO imple开发者_运维知识库mentation is the same, so the ID and version are the same for both proxies.


I'm not sure why RF isn't using the "lite" locator, but I'm not sure why it could be an issue either: shouldn't the ID and version be the same for MyDomain whichever the proxy being used?

Actually, I don't understand why you do need two different locators in this case: the "complete" or "lite" fetches are done in your DAO, not in the locators. The only reason for having two distinct locators would be to implement find differently, when a proxy is sent from the client to the server (find is also used by the default implementation of isLive but it's generally a good idea to override it with your own implementation, unless the default one is already the "best optimized" one: find(obj.getClass(), getId(obj)) != null)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜