jsr342-experts@javaee-spec.java.net

[jsr342-experts] Re: Platform default data source and JMS connection factory

From: Werner Keil <werner.keil_at_gmail.com>
Date: Tue, 10 Apr 2012 10:33:55 +0200

If @DefaultResource never was to be used without @Resource can't there
be just another property with @Resource ?

Kind of like @Resource(name="myDataSource", lookup="java:comp/**
defaultDataSource", *default=true*)

Not sure about others, but I would find that less cluttered. If "default"
wasn't possible (at least inside the annotation it is a reserved keyword)
then "defaultResource" might work, too.

Werner

On Tue, Apr 10, 2012 at 10:17 AM, Antonio Goncalves <
antonio.goncalves_at_gmail.com> wrote:

> Hi all,
>
> If we agree on a standard default naming convention, then why not specify
> producer methods. The container could do a bit of work for us and produce
> these resources :
>
> public class ResourceProducer {
>
> @Produces @DefaultResource @Resource(name="myDataSource",
> lookup="java:comp/**defaultDataSource")
> DataSource myDS;
>
> @Produces @DefaultResource @Resource(name="myJMSFactory",
> lookup="java:comp/**defaultJMSFactory")
> JMSFactory myFactory;
> ...
> }
>
> This way the client code could either use :
>
> @Resource(name="myDataSource")
> DataSource myDS;
>
> or
>
> @Inject @DefaultResource
> DataSource myDS;
>
>
> What do you think ? We already have some utility classes in Java EE (like
> PersistenceUtil), the spec could define such a class, no ?
>
> Antonio
>
>
> On Thu, Mar 22, 2012 at 23:23, Linda DeMichiel <linda.demichiel_at_oracle.com
> > wrote:
>
>> In view of the feedback we've received on this issue, our conclusion is
>> that we should adopt approach 3.
>>
>> To summarize, in the data source case, the following will apply:
>>
>> The Java EE Platform requires that a Java EE Product Provider
>> provide a database in the operational environment. The Java EE
>> Product Provider must also provide a preconfigured, default data
>> source for use by the application in accessing this database.
>>
>> The Java EE Product Provider must make the default data source
>> accessible to the application under the JNDI name
>> java:comp/defaultDataSource.
>>
>> The Application Component Provider or Deployer may explicitly bind a
>> DataSource resource reference to the default data source using the
>> lookup element of the Resource annotation or the lookup-name element
>> of the resource-ref deployment descriptor element. For example,
>>
>> @Resource(name="myDataSource", lookup="java:comp/**defaultDataSource")
>> DataSource myDS;
>>
>> If a DataSource resource reference is not mapped to a specific data
>> source by the Application Component Provider or Deployer, it must be
>> mapped by the Java EE Product Provider to a preconfigured data source
>> for the Java EE Product Provider's default database. For example, in
>> the absence of any action on the part of the developer or deployer,
>> the following will map to a preconfigured data source for the
>> product's default database:
>>
>> @Resource(name="myDataSource")
>> DataSource myDS;
>>
>>
>> And similarly for default JMS Connection Factory, whose JNDI name is
>> java:comp/**defaultJMSConnectionFactory.
>>
>>
>> -Linda
>>
>>
>>
>
>
> --
> Antonio Goncalves
> Software architect and Java Champion
>
> Web site <http://www.antoniogoncalves.org> | Twitter<http://twitter.com/agoncal>|
> Blog <http://feeds.feedburner.com/AntonioGoncalves> | LinkedIn<http://www.linkedin.com/in/agoncal>| Paris
> JUG <http://www.parisjug.org>
>