Thursday, September 1, 2011

Re: Requestfactory : best practice for persisting updates with Locator

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

--
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