The Common Client Interface (CCI) defines a standard client API
so that applications can access multiple resource adapters.
One goal of the CCI is to complement, rather than replace, the JDBC API.
Therefore, the JDBC API should be used to access relational databases while
the CCI API should be used to access EIS hosts that are not relational databases.
For this reason, the CCI programming model matches the JDBC programming model.
Because it is independent of specific EIS implementations, an enterprise
application development tool can use the CCI to produce code for any J2EE
compliant resource adapter implementing the CCI interface. While the CCI is
primarily for application development and enterprise integration tools,Java
developers can also use the CCI directly.
The CCI provides two distinct types of classes:
- Framework classes - These define the communication with the resource adapter.
The Framework classes enable you to connect to and disconnect from a resource
adapter, specify the interaction to occur in the EIS, and execute that interaction
by passing input and retrieving output. The following example code shows how
to interact with an EIS using the CCI API (in this case from the javax.resource.cci
package).
ConnectionFactory cf = <lookup from JNDI namespace> [1]
Connection connection = cf.getConnection();
Interaction interaction = connection.createInteraction(); [2]
interaction.execute(<input and output data>); [3]
interaction.close(); [4]
connection.close();
The logic of the code is as follows:
- Create a Connection object to connect to the EIS - The ConnectionFactory
object generates a Connection object. The ConnectionFactory retrieves information
on how to connect to the EIS by performing a JNDI lookup. This information
might include the location of the resource adapter to use and the name of
the EIS that is the target of the connection.
- Create an Interaction object - The Connection object creates an
Interaction object to perform specific actions on the EIS.
- Execute the interaction with the EIS - The Interaction object
makes a call to the resource adapter over the specified connection. The resource
adapter, in turn, calls a specific function on the EIS. The resource adapter
implements specific objects to create getter and setter methods for the specific
EIS.
- Close the Interaction and Connection
- Input and output classes - These classes pass specific information to
the framework classes or EIS, or retrieve specific information from the framework
classes or EIS. There are three types of input and output classes:
- ConnectionSpec objects - Pass information such as a user ID and
password that a resource adapter needs to connect to an EIS.
- InteractionSpec objects - Pass information such as an application
name that a resource adapter needs run during an interaction with an EIS.
- Record objects - Store the input and output data used during the
interaction with an EIS. The input Record contains data to pass to the EIS
and the output Record contains data generated by the EIS.
The following example expands the previous code example to include
input and output classes for the fictional xyz resource adapter:
ConnectionFactory cf = <lookup from JNDI namespace>
xyzConnectionSpec cs = new xyzConnectionSpec
cs.setXXX();
Connection connection = cf.getConnection();
Interaction interaction = connection.createInteraction();
xyzInteractionSpec is = new xyzInteractionSpec();
is.setYYY();
RecordImpl in = new RecordImpl();
RecordImpl out = new RecordImpl();
interaction.execute(is, in, out);
interaction.close();
connection.close();