Access data using Java EE Connector Architecture connectors


 

+

Search Tips   |   Advanced Search

 

Configure resource adapters and connection factories to access data from a Java EE Connector Architecture (JCA) compliant application.

Connection factories access a connection instance for connecting to an enterprise information system (EIS), such as...

To access data...

  1. Declare a connection factory resource reference in the deployment descriptor.

    <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. During the deployment process, configure each resource adapter and associated connection factory through the console. See the topics on installing a resource adapter and configuring a connection factory for more information.

  3. Locate the corresponding connection factory for the EIS resource adapter using JNDI lookup in the 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 */}

}


Relational resource adapters and JCA

 

Related tasks


Install a resource adapter archive
Set Java EE Connector connection factories in the admin console