WebSphere Application Server Network Deployment, Version 6.0.x   Operating Systems: AIX, HP-UX, Linux, Solaris, Windows
             [TIP: Focusing the table of contents and search results]

Accessing data using J2EE Connector Architecture connectors

To access data from a J2EE Connector Architecture (JCA) compliant application in WebSphere Application Server, you configure and use resource adapters and connection factories.

About this task

An application component uses a connection factory to access a connection instance, which the component then uses to connect to the underlying enterprise information system (EIS). Examples of connections include database connections, Java Message Service connections, and SAP R/3 connections.

As indicated in the J2EE Connector Architecture (JCA) Specification, each enterprise information system (EIS) needs a resource adapter and a connection factory. This connection factory is then accessed through the following programming model. If you use Rational Application Development (RAD) tools, most of the following deployment descriptors and code are generated for you. This example shows the manual method of accessing an EIS resource.

Procedure

  1. Declare a connection factory resource reference in your application component deployment descriptors, as described in this example:
    <resource-ref>
       <description>description</description>
       <res-ref-name>eis/myConnection</res-ref-name>
       <res-type>javax.resource.cci.ConnectionFactory</res-type>
       <res-auth>Application</res-auth>
    </resource-ref>
    
  2. Configure, during deployment, each resource adapter and associated connection factory through the console. See Configuring J2C resource adapters and Configuring J2C connection factories for more information.
  3. Locate the corresponding connection factory for the EIS resource adapter using Java Naming and Directory Interface (JNDI) lookup in your application component, during run time.
  4. Get the connection to the EIS from the connection factory.
  5. Create an interaction from the connection object.
  6. Create an InteractionSpec object. Set the function to execute in the InteractionSpec object.
  7. Create a record instance for the input and output data used by function.
  8. Execute the function through the Interaction object.
  9. Process the record data from the function.
  10. Close the connection.

Example

The following code segment shows how an application component might create an interaction and execute it on the EIS:

javax.resource.cci.ConnectionFactory connectionFactory = null;
javax.resource.cci.Connection connection = null;
javax.resource.cci.Interaction interaction = null;
javax.resource.cci.InteractionSpec interactionSpec = null;
javax.resource.cci.Record inRec = null;
javax.resource.cci.Record outRec = null;

try {
// Locate the application component and perform a JNDI lookup
   javax.naming.InitialContext ctx = new javax.naming.InitialContext();
   connectionFactory = (javax.resource.cci.ConnectionFactory)
ctx.lookup("java:comp/env/eis/myConnection");

// create a connection
   connection = connectionFactory.getConnection();

// Create Interaction and an InteractionSpec
   interaction = connection.createInteraction();
   interactionSpec = new InteractionSpec();
   interactionSpec.setFunctionName("GET");

// Create input record
   inRec = new javax.resource.cci.Record();

// Execute an interaction
   interaction.execute(interactionSpec, inRec, outRec);

// Process the output...

} catch (Exception e) {
   // Exception Handling
}
finally {
    if (interaction != null) {
         try {
              interaction.close();
         }
         catch (Exception e) {/* ignore the exception*/}
   }
   if (connection != null) {
        try {
             connection.close();
        }
        catch (Exception e) {/* ignore the exception */}
   }
}




Related concepts
Resource adapters
Task topic    

Terms of Use | Feedback

Last updated: Mar 8, 2007 8:14:28 PM CST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/tdat_impjcaapi.html

© Copyright IBM Corporation 2002, 2006. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)