InfoCenter Home >
4: Developing applications >
4.9: Programming model for the Connector Architecture (J2C) >
4.9.1: Mapping the current implementation to the Connector Architecture (J2C) Specification >
4.9.1.1: Implementing connector architecture
4.9.1.1: Implementing connector architecture
As indicated in the Connector Architecture (J2C) specification, each EIS (Enterprise Information
System) needs a Resource Adapter and a Connection Factory.
This Connection Factory is then accessed via the following programming model.
If you are using the Enterprise Access Builder (EAB) feature of Visual Age for Java (VAJ),
most of the following deployment descriptors and code are already generated for you.
This example shows the "manual" method of accessing and EIS resource
For each EIS
connection, do the following:
-
Declare a connection factory resource references in
your application component's 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>
-
Configure, during deployment, each Resouce Adapter and
associated connection factory through the console. See article,
Configuring J2C, for a description of the parameters required to configure
a resource adapter.
-
Locate in your application component,
during runtime, the corresponding connection factory for the EIS resource
adapter using JNDI lookup.
-
Get the connection to the EIS from the connection
factory.
-
Create an Interaction from the Connection
object.
-
Create an InteractionSpec object.
Set the function to be executed in the InteractionSpec object.
-
Create a Record instance for the input and/or
output data used by function.
-
Execute the function via the Interaction object.
-
Process the Record data from the function.
-
Close the connection.
Coding example for creating and executing an Interaction
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...
// close the interaction and connection
interaction.close();
connection.close();
} catch (Exception e) {
// Exception Handling
}
|
Related topics |
|
| Home (Getting started page) |
|
InfoCenter |
|
To launch the full documentation set in a separate browser window, click: |
| Display InfoCenter |
| |
PDF library |
|
To browse the PDF library for this product, containing this article and others, click: |
| PDF versions |
| |
Using this documentation |
|
Become an InfoCenter super user! To find out more about navigation, numbering, search, downloads, and more, click: |
| Using this documentation |
| |
|