Configuring CCI - Java-Springs

Connector configuration

The base resource to use JCA CCI is the Connection Factory interface.The connector used must provide an implementation of this interface.

To use your connector, you can deploy it on your application server and fetch the ConnectionFactory from the server's JNDI environment (managed mode).The connector must be packaged as a RAR file (resource adapter archive) and contain a ra.xml file to describe its deployment characteristics.The actual name of the resource is specified when you deploy it. To access it within Spring, simply use Spring's JndiObjectFactoryBean / <jee:jndi-lookup> fetch the factory by its JNDI name.

Another way to use a connector is to embed it in your application (non-managed mode), not using an application server to deploy and configure it.Spring offers the possibility to configure a connector as a bean, through a provided FactoryBean (Local Connection Factory Bean). In this manner, you only need the connector library in the classpath (no RAR file and no ra.xml descriptor needed).The library must be extracted from the connector's RAR file, if necessary.

Once you have got access to your Connection Factory instance, you can inject it into your components. These components can either be coded against the plain CCI API or leverage Spring's support classes for CCI access (e.g. CciTemplate).

ConnectionFactory configuration in Spring

In order to make connections to the EIS, you need to obtain a Connection Factory from the application server if you are in a managed mode, or directly from Spring if you are in a non-managed mode.

In a managed mode, you access a ConnectionFactory from JNDI; its properties will be configured in the application server.

<jee:jndi-lookup id="eciConnectionFactory" jndi-name="eis/cicseci"/>

In non-managed mode, you must configure the Connection Factory you want to use in the configuration of Spring as a Java Bean.The Local Connection Factory Bean class offers this setup style, passing in the Managed Connection Factory implementation of your connector, exposing the application-level CCI Connection Factory.

<bean id="eciManagedConnectionFactory" class="">
<property name="serverName" value="TXSERIES"/>
<property name="connectionURL" value="tcp://localhost/"/>
<property name="portNumber" value="2006"/>
<bean id="eciConnectionFactory" class="">
<property name="managedConnectionFactory" ref="eciManagedConnectionFactory"/>

Configuring CCI connections

JCA CCI allow the developer to configure the connections to the EIS using the Connection Spec implementation of your connector.In order to configure its properties, you need to wrap the target connection factory with a dedicated adapter, Connection Spec Connection Factory Adapter.

So, the dedicated ConnectionSpec can be configured with the property connection Spec(as an inner bean).

This property is not mandatory because the CCI Connection Factory interface defines two different methods to obtain a CCI connection. Some of the ConnectionSpec properties can often be configured in the application server (in managed mode) or on the corresponding local ManagedConnectionFactory implementation.

public interface ConnectionFactory implements Serializable, Referenceable {
Connection getConnection() throws ResourceException;
Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException;

Spring provides a Connection Spec Connection Factory Adapter that allows for specifying a Connection Spec instance to use for all operations on a given factory. If the adapter's connectionSpec property is specified, the adapter uses the getConnection variant without argument, else the one with the ConnectionSpec argument.

<bean id="managedConnectionFactory"
<property name="connectionURL" value="jdbc:hsqldb:hsql://localhost:9001"/>
<property name="driverName" value="org.hsqldb.jdbcDriver"/>
<bean id="targetConnectionFactory"
<property name="managedConnectionFactory" ref="managedConnectionFactory"/>
<bean id="connectionFactory"
<property name="targetConnectionFactory" ref="targetConnectionFactory"/>
<property name="connectionSpec">
<bean class="com.sun.connector.cciblackbox.CciConnectionSpec">
<property name="user" value="sa"/>
<property name="password" value=""/>

Using a single CCI connection

If you want to use a single CCI connection, Spring provides a further Connection Factory adapter to manage this. The Single Connection Factory adapter class will open a single connection lazily and close it when this bean is destroyed at application shutdown. This class will expose special Connection proxies that behave accordingly, all sharing the same underlying physical connection.

<bean id="eciManagedConnectionFactory"
<property name="serverName" value="TEST"/>
<property name="connectionURL" value="tcp://localhost/"/>
<property name="portNumber" value="2006"/>
<bean id="targetEciConnectionFactory"
<property name="managedConnectionFactory" ref="eciManagedConnectionFactory"/>
<bean id="eciConnectionFactory"
<property name="targetConnectionFactory" ref="targetEciConnectionFactory"/>

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Java-Springs Topics