> What I don't under stand is in the documents talk about 
> creating domain object using Resources, but doesn't have the Finder 
> create them for you limit a developers control? 

Yes.  In trade for looser binding between a resource and the
infrastructure that manages its URI space.

I find it helpful to think of the Restlet Resource as a resource
wrapper.  It is not the actual application domain object itself, but
rather a lightweight object which adapts a domain object to the HTTP
and REST paradigm for the purpose of a single access operation.

This requires trunk ... but we have found a really useful tactic to
be putting things like caches and connection pools at the Application
level, and then in the Resource, do something like:

((MyApplication) getContext().getApplication()).getConnection();

Augment this with some error checking, to ensure that your Resource
is being called in the Context you think it is, and this works
quite well and makes for a very readable code base with minimal
surgery to Finders, minimal storage at the Resource level, and
less overstuffing of the Context.

It is less loosely bound, and makes your Resource dependent on a 
particular Application, but if you know that constraint is true
anyway ... it's pretty useful.

> Wouldn't it be better to allow a developer to manage the creation
> of their own objects? 

Well, sure, as you said, with a custom Finder or by skipping the
Finder/Resource paradigm altogether and just attaching a Restlet,
you can do this.  I don't think I've read anything where this is
considered a Bad Thing.  There have been a number of custom Finder
cases posted to the list, I don't think I have anything new to add.

But the Finder/Resource design is a pretty neat one for separation
of concerns, and we have gotten a lot of value out of it.

- R


----- Original Message ----- 
From: "Stanczak Group" <[EMAIL PROTECTED]> 
To: [email protected] 
Sent: Saturday, September 8, 2007 10:25:22 PM (GMT-0500) America/New_York 
Subject: Re: Are Resources Cached? 

If I could find an example, it looks like I could just extend Finder and 
override createResource(). That should allow me to inject a database 
connection. What I don't under stand is in the documents talk about 
creating domain object using Resources, but doesn't have the Finder 
create them for you limit a developers control? Wouldn't it be better to 
allow a developer to manage the creation of their own objects? So my 
question is does anyone have a example of using Finder? I would like to 
have control over creating Resource objects. 

Thierry Boileau wrote: 
> Hi Justin, 
> 
> you're right, a new instance of your Resource class is created each 
> time your resource is targeted. 
> Each instance is responsible to load the resource's own state, and 
> respond to only one request. 
> 
> best regards, 
> Thierry Boileau 
>> The best I could find is yes Resources get created each request, and 
>> I should extend a Restlet and override the handle method. Allowing 
>> Pico to create the Restlet with the database connection in it. I 
>> don't see a way to do that with a Resource unless I can make Restlet 
>> use a custom factory. 
>> 
>> Stanczak Group wrote: 
>>> In the following code I supply the router with a class. Restlet then 
>>> creates this class, I'm guess when a call is made. My question is 
>>> does this class get created each time or is it cached? If I use 
>>> something like PicoContainer with caching I can have it inject the 
>>> CoursesResource.class, which would allow me to use PicoContainer to 
>>> inject for example database connection entity manager into this 
>>> resource. The way I understand it is Restlet engine, in this case, 
>>> instantiates this class for me, but looking at the constructor it 
>>> appears it's created each time a new. What am I missing here? 
>>> 
>>> @Override 
>>> public Restlet getRoot() { 
>>> Router router = new Router(this.getContext()); 
>>> router.attach("/v1/users/{user}/courses", 
>>> CoursesResource.class); 
>>> return router; 
>>> } 
>>> 
>> 
> 

-- 
Justin Stanczak 
Stanczak Group 
812-735-3600 

"All that is necessary for the triumph of evil is that good men do nothing." 
Edmund Burke 

Reply via email to