users@jersey.java.net

Re: [Jersey] Business object for jersey

From: cepam <emmanuel.lallemand_at_cpam-dijon.cnamts.fr>
Date: Tue, 6 Oct 2009 09:12:10 -0700 (PDT)

Hi,

Thanks a lot for your answer.

Yes, I need that you describe your first proposition. For example, I want to
create only one business object who is charge to communicate whis a Database
and manage the differents concurrent requests from a lot of resource
methods.
 
Can you give me more details regarding your small example:

For class MySingletonResource, if the constructor is for example :
MySingletonRessource(File config), how (where) to instanciate it (new ...)
for my whole web appli ?

I suppose that MySingleton resource must be thread safe ?

The annotation @Pathname in some resource method will not be 'disturbed' by
the @Context annotation ?

If necessary, I can post a piece of code.
Thanks.




Paul Sandoz wrote:
>
> Hi,
>
> Do you want some kind of singleton object to be injected into the
> resource classes (the classes that contain the resource methods
> annotated with @GET etc) ?
>
> If, this is going to get a lot easier when we release EE 6 with
> support for 299 and managed beans. In the mean time you can do the
> following:
>
> @Singleton // see [1]
> public class MySingletonResource {
> ...
> }
>
>
> @Path("/blah")
> public class MyResourceClass {
>
> @GET
> public ... get(@Context ResourceContext rc) { // see [2]
> MySingletonResource msr =
> rc.getResource(MySingletonResource.class);
> }
> }
>
>
> If you want the MyResourceClass to be a singleton you can do:
>
> @Singleton
> @Path("/blah")
> public class MyResourceClass {
> }
>
>
> You do not have to use EJBs, but that is one option, but i recommend
> only using it with EJB 3.1 and Java EE 6 which significantly improves
> the ease of use of EJBs.
>
> Otherwise, if this is not what you require a simple example of what
> you want to do will help me understand better your needs,
> Paul.
>
> [1]
> https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/spi/resource/Singleton.html
> [2]
> https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api/core/ResourceContext.html
>
> On Oct 5, 2009, at 2:28 PM, cepam wrote:
>
>

-- 
View this message in context: http://n2.nabble.com/Business-object-for-jersey-tp3768500p3776023.html
Sent from the Jersey mailing list archive at Nabble.com.