A resource factory is an object that you use to create resources. You can assign a logical name to a resource factory in the deployment descriptor.
A resource-ref element defines a single resource factory reference. This code sample defines a reference to the resource factory that implements the DataSource interface:
<resource-ref> <description> Data source for the database in which the Employee enterprise bean records transactions </description> <res-ref-name>jdbc/EmployeeAppDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
A resource-ref element contains:
res-ref-name Resource reference name used in the application’s code.
res-type Resource Java datatype that the application expects.
This code sample obtains a reference to the resource factory that implements the DataSource interface, and uses that reference to get a database connection (resource):
// Obtain the initial JNDI context Context initContext = new InitialContext(); // Look up the resource factory using JNDI javax.sql.DataSource ds = (javax.sql.DataSource) initContext.lookup (“java:comp/env/jdbc/EmployeeAppDB”); // Get a database connection java.sql.Connection connection = ds.getConnection();
For information about using EAServer Manager to add and configure resource references in Web applications, EJB components, or application clients, see “Resource references” in Chapter 21, “Creating Web Applications,” in the EAServer Programmer’s Guide.
Copyright © 2005. Sybase Inc. All rights reserved. |