Wednesday, June 29, 2011

RequestFactory - persist method that returns the saved Entity.

So, still trying to fully understand the RequestFactory, I made myself
a small app to test having my persistence code in the entity itself.
(I have been previously working off the TurboManage
objectify+requestfactory sample, thanks David, its been very useful!)

I have an Entity called Parent, which has this method:

public Parent persistAndReturn() {
ObjectifyDao dao = new ObjectifyDao();
this.aBool = true;
Key<Parent> key = dao.ofy().put(this);
return dao.ofy().get(key);
}

In my App's RequestFactory interface, I have this:

@Service(Parent.class)
interface ParentRequestContext extends RequestContext {
InstanceRequest<ParentProxy, Void> persist();
InstanceRequest<ParentProxy, ParentProxy> persistAndReturn();
}
ParentRequestContext getParentRC();


Then when I want to create and persist a new Parent object, I do this...

ParentRequestContext rc = rf.getParentRC();
ParentProxy proxyObj = rc.create(ParentProxy.class);
(.. set some properties.. )

Request<ParentProxy> fetchRequest = rc.persistAndReturn().using(proxyObj);
fetchRequest.to(new Receiver<ParentProxy>(){
(... onSuccess Handler.. )
});

fetchRequest.fire();

However I get the 'autobean has been frozen' error (stack trace:
http://pastebin.com/NZ7280B9 )
Its clear from the stacktrace and other debug messages that the object
is persisted, but returning it fails.

So...

Is this possible? Is it desirable?

Also, if we look at the last line, fetchRequest.fire(), we could also
do rc.fire() instead of it, and get the same result.. Are we doing
the exact same operation when we call either 'fire' method?

Thanks,
Aidan.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment