users@javaee-spec.java.net

[javaee-spec users] [jsr342-experts] Clarification on Default resources

From: Kevin Sutter <sutter_at_us.ibm.com>
Date: Tue, 4 Jun 2013 16:07:43 -0500

Hi,
The discussion about the Default resources in the Java EE 7 spec pre-dates
my involvement, so I'm looking for some clarification. I've reviewed the
discussion in the archives and an associated JIRA, but I still have
questions...

https://java.net/projects/javaee-spec/lists/jsr342-experts/archive/2012-03/message/56

https://java.net/projects/javaee-spec/lists/jsr342-experts/archive/2012-03/message/70
https://java.net/jira/browse/JAVAEE_SPEC-4

I was especially interested in David Blevin's replies as they relate to
OpenEJB and TomEE since it sounds like they already provide default
resource bindings similar to WebSphere.

My basic question centers around this example. From the spec, are these
two @Resource injections supposed to resolve to the same datasource?

    @Resource(lookup="java:comp/DefaultDataSource")
    DataSource myDS;
    @Resource
    DataSource myDS;

My reading of the spec would indicate that the latter example (plain
@Resource) would default to the product's default datasource. The use of
the word "product" is key in my understanding. If the product already
provides a default mapping, then the plain @Resource could continue to
default to the behavior as prescribed by the product. But, if the product
does not currently provide a default mapping, then the plain @Resource
could default to the newly defined resource located at
java:comp/DefaultDataSource. And, Werner's final comment seems to support
that interpretation:

"Thanks, that sounds like the most flexible approach. While not confusing
those who are fine with the default
lookup, others who may require alternatives there can overwrite it."

Is my interpretation accurate? Thanks for the input.

----------------------------------------------------------------------------------------------------------------------------------------------------------------
Kevin Sutter, Java EE and Java Persistence API (JPA) architect
mail: sutter_at_us.ibm.com, Kevin Sutter/Rochester/IBM
http://webspherepersistence.blogspot.com/
phone: tl-553-3620 (office), 507-253-3620 (office)
http://openjpa.apache.org/