Requestfactory : best practice for persisting updates with Locator

63 views
Skip to first unread message

Dominik Steiner

unread,
Aug 31, 2011, 8:46:18 AM8/31/11
to Google Web Toolkit
Hi,

I finally did a first try at RF and am wondering what is the best way
to implement the persist method on a Locator class in order to deal
with only the deltas send from the client?

As right now my persist(T objectToPersist) method on the Locator is
doing a create if the object has no id associated to it. This use case
is pretty similar to what i would have done with RPC as the whole
object is being sent evidently. But when i then reload the object from
the server, change some properties on it and call persist again a
pretty 'light' objectToPersist appears in that method which seems to
even have lost the PK on the associations in that object.

So am i missing something or is there a good way to implement those
updates especially when dealing with associations in that object?

Thanks

Dominik Steiner

unread,
Sep 1, 2011, 12:36:41 PM9/1/11
to Google Web Toolkit
Perhaps a small test case might better explain what problem i'm facing
with the delta's send from request factory to the locator class (the
fire() method is in order to do synchronous testing of the requests
sent)

@Test
public void testPersistAndUpdate() throws Exception {
SomeRequestContext addRequest = requestFactory.someRequest();
FooProxy fooProxyCreated = addRequest.create(FooProxy.class);
fooProxyCreated.setName("fooname");
BarProxy barProxy = addRequest.create(BarProxy.class);
barProxy.setName("barname");
fooProxyCreated.setBars(Arrays.asList(barProxy));

IntegerResponseProxy addResponse =
fire(addRequest.persist(fooProxyCreated));
assertEquals(null, addResponse.getErrormessage());
assertNotNull(addResponse.getValue());
Integer id = addResponse.getValue();

SomeRequestContext findRequest = requestFactory.someRequest();
FooProxy fooProxyFound = fire(findRequest.find(id).with("bars"));

SomeRequestContext updateRequest = requestFactory.someRequest();
fooProxyFound = updateRequest.edit(fooProxyFound);
BarProxy bar = fooProxyFound.getBars().get(0);
bar.setName("newname");
IntegerResponseProxy updateResponse =
fire(updateRequest.persist(fooProxyFound));
assertEquals(null, updateResponse.getErrormessage());
assertEquals(id, updateResponse.getValue());
}


So on the server the service method just looks like this

public IntegerResponse persist(Foo foo)

and the
public class Foo{
Integer id;
String name;
List<Bar> bars;
|

and Bar might have a composite id

public class Bar {
BarPK barPK;
}

public class BarPK{
Integer fooId;
String name;
}

When it is created all properties gets sent to the persist() method
and the full object can easily be persisted using hibernate. The
second time an update is occuring on that object the fooId will be
null as no changes have been made to that on the client evidently.
This makes working with the Foo foo object in the persist method quite
manual. And how would i differentiate if some null property is just
not sent because no update has occured or because it has been reset to
null? Is such a use case not supported by RF and i have to stick with
RPC?

Thanks for any hints

Dominik
Reply all
Reply to author
Forward
0 new messages