RequestFactory: Get entity ID on success of persist

32 views
Skip to first unread message

Tapomay Dey

unread,
Jan 12, 2012, 9:24:38 AM1/12/12
to Google Web Toolkit
Hi,
I am using following code.

Note:
request is of type ? extends RequestContext
entity is of type ? extends EntityProxy

(request).persist().using(entity).fire(
new Receiver<Void>() {
@Override
public void onSuccess(Void unUsed) {
I need the entity ID generated in the DB here.
If I do entity.getId(); it returns null obviously.
As I don't know the ID here, I can't even refetch the persisted
entity.
The Receiver should have received the updated entity as arg to its
onSuccess.
}

});

How do I do it?

Thanks,
Tapomay.

Patrick Julien

unread,
Jan 12, 2012, 12:20:31 PM1/12/12
to google-we...@googlegroups.com
in 

request is of type ? extends RequestContext  

add your own persist method that returns the newly created entity instead of void.  The you receive it using Receiver<XEntity> instead of Receiver<Void>

Thomas Broyer

unread,
Jan 13, 2012, 4:21:46 AM1/13/12
to google-we...@googlegroups.com


On Thursday, January 12, 2012 3:24:38 PM UTC+1, Tapomay Dey wrote:
Hi,
I am using following code.

Note:
request is of type ? extends RequestContext
entity is of type ? extends EntityProxy

(request).persist().using(entity).fire(
new Receiver<Void>() {
  @Override
  public void onSuccess(Void unUsed) {
    I need the entity ID generated in the DB here.
    If I do entity.getId(); it returns null obviously.
    As I don't know the ID here, I can't even refetch the persisted
entity.

You should be able to pass the entity.stableId() to RequestContext#find().
 
    The Receiver should have received the updated entity as arg to its
onSuccess.

As Patrick said, make your persist() method return the entity, if that's what you want. Or you can make it return the entity ID if you prefer (smaller payload, but you have to make an additional request if you want to retrieve it; apply the 80/20 rule to choose between a smaller response payload or less requests).
 
Reply all
Reply to author
Forward
0 new messages