WAS v8.5 > Develop applications > Develop data access resources > Develop data access applications > Develop data access applicationsResource reference benefits
WebSphere Application Server requires your code to reference application server resources (such as data sources or J2C connection factories) through logical names, rather than access the resources directly in the JNDI name space. These logical names are called resource references.
Application Server requires use of resource references for the following reasons:
- If application code looks up a data source directly in the JNDI naming space, every connection that is maintained by that data source inherits the properties that are defined in the application. Consequently, you create the potential for numerous exceptions if you configure the data source to maintain shared connections among multiple applications. For example, an application that requires a different connection configuration might attempt to access that particular data source, resulting in application failure.
- It relieves the programmer from having to know the name of the actual data source or connection factory at the target application server.
- We can set the default isolation level for a data source through resource references. With no resource reference you get the default for the JDBC driver we use.
The following example of using a resource reference invokes a data source by creating a place holder for it through the lookup method. Using the logical name jdbc/Section, the code stores the place holder in the JNDI subcontext java:comp/env/; hence jdbc/Section becomes a resource reference. (The subcontext java:comp/env/ is the name space that WAS provides exclusively for object references within application code.)
javax.sql.DataSource specificDataSource = (javax.sql.DataSource) (new InitialContext()).lookup("java:comp/env/jdbc/Section"); //The method InitialContext()).lookup creates the logical name, or resource reference, jdbc/Section.Generally, an actual data source is configured later as an administrative task.The logical name jdbc/Section is officially declared as a resource reference in the application deployment descriptor. We can then associate the resource reference with the JNDI name of the actual data source in several ways:
- If you know the data source JNDI name at the point of application assembly, specify the name on the resource references Bindings page.
- Specify the data source JNDI name during application deployment.
- Map the resource reference to the data source JNDI name when we configure the application after deployment.
This act of association is called binding the resource reference to the data source.
See the article, Application bindings, for information on all types of required resource bindings.
Subtopics
- Requirements for setting data access isolation levels
This article discusses the criteria and effects of setting isolation levels for data access components that comprise EJB 2.x and later modules.- Requirements for setting data access isolation levels
This article discusses the criteria and effects of setting isolation levels for data access components that comprise EJB 2.x and later modules.
Related concepts:
Data sources
Application bindings
Related
Access data from application clients
Configure data access for the Application Client
Create or changing a resource reference
Assemble data access applications
Access data using Java EE Connector Architecture connectors
Migrating applications to use data sources of the current JCA
Configure a JDBC provider and data source
Reference:
Lookup names support in deployment descriptors and thin clients