On Friday, September 30, 2011 9:26:22 PM UTC+2, Hilco Wijbenga wrote:
>
> On 30 September 2011 00:54, Thomas Broyer <[email protected]> wrote:
> > Why would BasicUserService ( = GizmoService?) be called if you invoke
> > UserRequest#persist(UserProxy) ( = ThingRequest#persist(ThingProxy) ?)
>
> Because BasicUserProxy is part of UserProxy.
>
If you call a method on UserRequest, the equivalent method will be called on 
its @Service (i.e. UserService), and no other service method will be called.
If you call setters on proxies (UserProxy, BasicUserProxy), the equivalent 
setters are called on their @ProxyFor (User, BasicUser).

The only "special namings" RequestFactory uses are the static findXxx(), and 
the getId() and getVersion() methods; and only if you do not use a Locator. 
A method called "persist" is in no way a special method.

What I mean is that calling UserRequest#persist(UserProxy) cannot imply a 
call to, say, BasicUserService#persist(BasicUser) on the server; only 
UserService#persist(User) will be called.
 

> > It's hard to follow what you're expecting given that you switched from
> > thing/gizmo/setSomething to [something-else]/user/basicUser/set[what?]
>
> I wanted to keep it generic but see below.
>
> > Could you post the actual code that led to the request whose payload you
> > posted already?
>
> Here you go:
>
> final UserRequest userRequest =
> domainRequestApi.getRequestBuilder().newUserRequest();
> final UserProxy mutableUser =
> userRequest.edit(domainRequestApi.getCache().getCurrentUser());
> final BasicUserProxy mutableBasicUser = mutableUser.getBasicUser();
> final int level = mutableBasicUser.getLevel();
> final int basicCurrencyDelta = ...;
> final int premiumCurrencyDelta = ...;
> final int newLevel = level + 1;
> final String comment = "Level Up to Level " + newLevel + ".";
> mutableBasicUser.setLevel(newLevel);
> final Receiver<Integer> levelUpReceiver = new LevelUpReceiver(...,
> mutableUser, comment, basicCurrencyDelta, premiumCurrencyDelta);
> userRequest.persist(mutableUser).fire(levelUpReceiver);
>

What's strange is that there's a "comment": "Level Up to Level 1." in the 
JSON payload of the request, while I don't see a setComment() above; and 
there's no "level":1 while there is a setLevel(newLevel).

 

> Given that BasicUserProxy is part of UserProxy, I would expect its
>
> changes to be stored, i.e. I expect the entire object graph that is
> UserProxy to be stored (as necessary).
>

What do you mean exactly by "stored"? What RequestFactory will do on the 
server side is:

   1. get User and BasicUser (and others, as needed) by their ID
   2. "apply the diff" from the request to these objects, by calling the 
   appropriate setters.
   3. call the service methods; here, call UserService#persist(User) with 
   the User instance modified above

So actually persisting the "entire object graph" is up to the 
UserService#persist(User) method; as the doc says:
“RequestFactory automatically sends the whole object graph in a single 
request. In this case, the implementation of Person.persist() on the server 
is responsible for persisting the related Address also, which may or may not 
happen automatically, depending on the ORM framework and how the 
relationship is defined.” (the part about @Embedded objects not being 
supported is no longer true since GWT 2.1.1 and the introduction of 
ValueProxy; but that doesn't apply here)
— 
http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html#relationships

So, is your problem that BasicUser is not persisted? or that the 
User#getBasicUser() passed to the persist() method doesn't have its level 
modified?

Or is your issue that domainRequestApi.getCache().getCurrentUser() doesn't 
reflect the change? In that case, then unless you, somewhere, setCurrentUser 
with the "mutableUser", that's normal: immutable proxies are never updated, 
they're immutable snapshots.

>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/IeWUYjioA48J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to