How to get hold of the instance in an InstanceRequest

63 views
Skip to first unread message

Gregor Frey

unread,
Dec 22, 2011, 3:00:14 AM12/22/11
to google-we...@googlegroups.com
Hi,
I'm implementing an InstanceRequest on the server side in a dedicated service class, which is annotated as Service in the RequestContext. This works fine, but how can I get a reference to the instance of the entity, on which I need to operate?
The background of my question is, that the entity returns enum types that must be adapted for the client. My idea is to implement these adapter methods as instance methods in a service class.

Thomas Broyer

unread,
Dec 22, 2011, 8:16:47 AM12/22/11
to google-we...@googlegroups.com
I think you don't understand what InstanceRequest means vs. Request.

InstanceRequest means the method will be called on the domain object corresponding to the proxy passed as argument (referenced by its @ProxyFor annotation), so the "instance of the entity" is "this".

Request, on the other hand, means the method will be called on the class referenced by the @Service annotation. Whether there's an instance of the service class or the method is static depends on whether there is a ServiceLocator for the service (similarly to entities that must have a findXxx static method, a no-arg constructor, and a getId and getVersion instance methods, unless there is a Locator for the entity class).


Gregor Frey

unread,
Dec 22, 2011, 3:04:27 PM12/22/11
to google-we...@googlegroups.com
Thank you. So there is no way to implement an instance method outside the domain class? But why woulnt I include all instance methods in the proxy definition then? I hoped I could add methods, that are originally not in the domain object, but are needed just for doing data transformations for the UI, in a separate class.

Thomas Broyer

unread,
Dec 29, 2011, 6:51:07 AM12/29/11
to google-we...@googlegroups.com


On Thursday, December 22, 2011 9:04:27 PM UTC+1, Gregor Frey wrote:
Thank you. So there is no way to implement an instance method outside the domain class?

Yes you can: you simply need a ServiceLocator.
 
But why woulnt I include all instance methods in the proxy definition then? I hoped I could add methods, that are originally not in the domain object, but are needed just for doing data transformations for the UI, in a separate class.

Declare your method as "Request<Result> doSomething(Instance object)" instead of "InstanceRequest<Instance, Result> doSomething()". The former says the method is declared on the class pointed to by the @Service annotation, while the latter bypasses that annotation and tells the method is declared on the class pointed to by the @ProxyFor annotation of the Instance proxy. Obviously, on the server-side, you'd need a "DomainResult doSomething(DomainInstance object)" method in the former case, and a "DomainResult doSomething()" (declared on the DomainInstance class, so "this" will be the instance you passed to using() on the client-side) in the latter case.
Reply all
Reply to author
Forward
0 new messages