GWT RequestFactory:我如何从stableId()获得一个持久性ID? [英] GWT RequestFactory: How can I get a persistent id from stableId()?

查看:111
本文介绍了GWT RequestFactory:我如何从stableId()获得一个持久性ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的实体中使用 Long id,不仅将它们存储在数据存储中,而且还引用其他实体。现在,我使用RequestFactory在客户端创建()对象并坚持它们,但我需要一种方法来确定服务器生成的id。

I use Long ids in my entities, not only to store them in the datastore, but to reference other entities. Now, I'm using RequestFactory to create() objects on the client and persist them, but I need a way to figure out what id the server has generated.

这里是我发现一种方法需要两次旅行:

Here's one way I've figured out that requires two trips:

final OrganizationProxy proxy = context.create(OrganizationProxy.class);
context.persist().using(proxy).fire(new Receiver<Void>(){

    public void onSuccess(Void response)
    {
        requestFactory.find(proxy.stableId()).fire(new Receiver<OrganizationProxy>()
        {
            public void onSuccess(OrganizationProxy response)
            {
                //hey, now response has the server-generated id in it, along with any other values the server populated
            }
        });
    }
});

但似乎必须是一种获取持久性ID的方法没有第二次旅行。看起来像requestFactory.find()将需要持久性ID在所有的工作。第一位。

But it seems like there must be a way to get the persistent id without the second trip. It seems like requestFactory.find() would need the persistent id to work at all in the first place.

我怎么能在没有第二次请求服务器?

How can I get at the persistent id without a second request to the server?

=======更新=======

=======Update=======

它终于发生在我身后(tbroyer Long 标识符(), )方法在RequestContext中。这不会从 EntityProxyId 中检索持久性标识,但它确实为我提供了一个请求中新对象的持久标识。

It finally occurred to me (after tbroyer told me ;)) that I could return the Long id from the persist() method in the RequestContext. This doesn't retrieve the persistent id from the EntityProxyId, but it does get me the persistent id of a new object in a single request.

我打开这个问题 - 我仍然对从EntityProxyId获取持久性id感兴趣。

I'll leave this question open - I am still interested in getting the persistent id out of an EntityProxyId.

推荐答案

实现 EntityProxyId 的类是 SimpleEntityProxyId 。这个类有一个方法 getServerId(),它将返回这个id。因此,通过检查 instanceof ,然后可以调用该方法。 (实际上 RequestFactory.getHistoryToken()甚至没有检查,只是简单地转换为这个类)。

The class implementing an EntityProxyId is SimpleEntityProxyId. This class has a method getServerId(), which will return the id. So by checking with instanceof you can then call the method. (Actually RequestFactory.getHistoryToken() doesn't even check, but simply casts to this class).

现在坏消息是:它是编码的,它的基类是 SimpleEntityProxyId ,它是 SimpleProxyId 并包含方法 getServerId(),明确指出: b
$ b

Now the bad news: it's encoded and the base class for SimpleEntityProxyId, which is SimpleProxyId and contains the method getServerId(), specifically states:


encodedAddress对客户端是完全不透明的。它可能是base64编码的字符串,但它可能是pi的数字。

The encodedAddress is totally opaque to the client. It's probably a base64-encoded string, but it could be digits of pi. Any code that does anything other than send the contents of this field back to the server is wrong.

(其中字段 encodedAddress 包含服务器ID。)

(Where the field encodedAddress contains the server id.)

这篇关于GWT RequestFactory:我如何从stableId()获得一个持久性ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆