0

I'm doing a simple asynchronous put operation with Objectify:

ofy().async().put(object);

This returns Result< Key< ObjectEntity>>, and I can call

Result<Key<ObjectEntity>> result = ofy().async().put(object);

And then I can call .get() on that to block until I get the result:

Key<ObjectEntity> objectKey = result.get();

But what can I do with this objectKey in order to get my object entity back? I basically want to be able to send this as an object back to GWT.


This should get your object back:

Result<Foo> fooResult = ofy.async().get(Foo.class, "foo1-id");
Foo foo = fooResult.get();

I tried my hands with Objectify a little so I'm definitely not an expert but you might want to make sure that if you're putting an object into the datastore with an async put call, that you block until it has been inserted into the datastore before calling. If you're going to end up needing to retrieve an entity immediately after inserting it, you're defeating the purpose of using async.put().

Also you probably know this but the Objectify folks have done a decent job of putting together their API Javadoc for reference.

4

1 回答 1

0

这应该让你的对象回来:

Result<Foo> fooResult = ofy.async().get(Foo.class, "foo1-id");
Foo foo = fooResult.get();

我尝试过使用 Objectify,所以我绝对不是专家,但您可能需要确保如果您使用异步 put 调用将对象放入数据存储区,您会一直阻塞直到它被插入调用前的数据存储。如果您最终需要在插入实体后立即检索它,那么您就违背了使用 async.put() 的目的。

您也可能知道这一点,但 Objectify 的人在整理他们的API Javadoc以供参考方面做得不错。

于 2011-11-25T04:41:29.867 回答