On 30 September 2011 15:08, Thomas Broyer <[email protected]> wrote:
> 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).

:-) I apologise for "comment", that's being done by a separate event.
The JSON you see contains two proxies going to the server. I didn't
want to change the JSON as I was not clear on the exact dependencies.

I've wondered about the missing "level":1 as well. I know I've seen it
once but that may have been when I was persisting BasicUser directly.

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

I mean persisting it in the database.

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

Yeah, I had assumed it would call BasicUserService#persist(BasicUser) as well.

> 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

All right, I guess I was expecting too much.

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

I have User cached and User contains BasicUser. I want BasicUser
updated on the server and I want that change reflected in User (so
User.getBasicUser().getLevel() should yield the new level). This seems
impossible without rerequesting the entire User object graph from the
server. That's very expensive and totally unnecessary (in the sense
that all information is already available on the client). But I don't
see how I can "update" the cached User with the "new" BasicUser. I
can't call setBasicUser on User because it's frozen.

So given what you've told me above, my question becomes: how do I
update User after persisting BasicUser? Without rerequesting the whole
User object graph from the server, of course. This must be easy but I
don't see how to do it. :-(

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
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