Configure JCA connection factories

We can configure connection factories that comply with Java EE Connector Architecture (JCA) specification. We can configure one or more connection factory instances for connection factory types provided by an installed resource adapter. To configure JCA support for Liberty, edit server.xml and configure a resource adapter with a unique identifier of MyAdapter. in the Design view of WebSphere Development Tools (WDT) is not supported.

  1. Update server.xml to add the jca-1.6 feature under the featureManager tag.

      <featureManager>  
      	<feature>jca-1.6</feature> 
      	<feature>jndi-1.0</feature>  <!-- jndi-1.0 enables look up of connection factories -->   
      		... 
      </featureManager>

  2. Install a resource adapter. For example:

  3. Configure one or more connection factory instances.

    When configuring the connection factory instances, supply a properties subelement, even if we do not want to override any configuration properties, in order to associate the connectionFactory element with a connection factory interface provided by a particular resource adapter. In the following example, the MyAdapter resource adapter provides only one type of connection factory:

      <connectionFactory jndiName="eis/cf1">
       <properties.MyAdapter portNumber="1234" someVendorProperty="100"/>
      </connectionFactory>
      
      <connectionFactory jndiName="eis/cf2" containerAuthDataRef="auth2">
       <connectionManager maxPoolSize="20" connectionTimeout="0"/>
       <properties.MyAdapter portNumber="1234" someVendorProperty="200"/>
      </connectionFactory>
      <authData id="auth2" user="user2" password="{xor}Lz4sLCgwLTtt"/>

  4. (Optional) If required, identify the available connection factory property subelement names.

    • If a resource adapter provides exactly one connection factory interface, excluding any JMS connection factories, the subelement is: properties.<rar_identifier>
    • If the interface name is unique without the package name, the subelement name is: properties.<rar_identifier>.<InterfaceName>
    • If the implementation name is unique without the package name, the subelement name is: properties.<rar_identifier>.<ImplementationName>
    • In other cases, the subelement name is: properties.<rar_identifier>.<fully.qualified.InterfaceName>


Example

The following configures resource adapters with two connection factories with unique interface class names.

In the following snippet from ra.xml, the MyAdapter resource adapter provides two connection factories with unique interface class names:

    <connection-definition>
      <config-property>
      <config-property-name>ServerName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
     </config-property>
     <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
     <connectionfactory-impl-class>com.vendor.adapter.ConnectionFactoryImpl</connectionfactory-impl-class>
    </connection-defintion>

    <connection-definition>
     <config-property>
      <config-property-name>ServerName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
     </config-property> 
     <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
     <connectionfactory-impl-class>com.vendor.adapter.DataSourceImpl</connectionfactory-impl-class>
    </connection-defintion> 

The following is an example of a server configuration for this scenario:

    <connectionFactory jndiName="eis/cf">
     <properties.MyAdapter.ConnectionFactory serverName="localhost"/>
    </connectionFactory>
    
    <connectionFactory jndiName="jdbc/ds">
     <properties.MyAdapter.DataSource serverName="localhost"/>
    </connectionFactory>

The following configures resource adapters with two connection factories with unique implementation class names.

In the following snippet from ra.xml, the MyAdapter resource adapter provides two connection factories with unique implementation class names:

    <connection-definition>
      <config-property>
      <config-property-name>ServerName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
     </config-property>
     <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
     <connectionfactory-impl-class>com.vendor.adapter.ConnectionFactoryImpl</connectionfactory-impl-class>
    </connection-defintion>
    
    <connection-definition>
      <config-property>
      <config-property-name>ServerName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
     </config-property>
     <connectionfactory-interface>com.vendor.adapter.ConnectionFactory</connectionfactory-interface>
     <connectionfactory-impl-class>com.vendor.adapter.MyConnectionFactoryImpl</connectionfactory-impl-class>
    </connection-defintion>

The following is an example of a server configuration for this scenario:

    <connectionFactory jndiName="eis/cf1">
     <properties.MyAdapter.ConnectionFactoryImpl serverName="localhost"/>
    </connectionFactory> 
    
    <connectionFactory jndiName="eis/cf2">
     <properties.MyAdapter.MyConnectionFactoryImpl serverName="localhost"/>
    </connectionFactory>

Use the following example to learn how to configure resource adapters with two connection factories where neither the simple interface nor implementation class names are unique.

In the following snippet from ra.xml, the MyAdapter resource adapter provides two connection factories where neither the simple interface nor the implementation class names are unique:

    <connection-definition>
     <config-property>
      <config-property-name>ServerName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
     </config-property> 
     <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
     <connectionfactory-impl-class>com.vendor.adapter.ConnectionFactoryImpl</connectionfactory-impl-class>
    </connection-defintion>
    
    <connection-definition>
      <config-property>
      <config-property-name>HostName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
     </config-property> 
     <connectionfactory-interface>com.vendor.adapter.custom.ConnectionFactory</connectionfactory-interface>
     <connectionfactory-impl-class>com.vendor.adapter.custom.ConnectionFactoryImpl</connectionfactory-impl-class>
    </connection-defintion>

The following is an example of a server configuration for this scenario:

    <connectionFactory jndiName="eis/cci-cf">
     <properties.MyAdapter.javax.resource.cci.ConnectionFactory serverName="localhost"/>
    </connectionFactory>
    
    <connectionFactory jndiName="eis/custom-cf">
     <properties.MyAdapter.com.vendor.adapter.custom.ConnectionFactory hostName="localhost"/>
    </connectionFactory>

It is possible to override the suffixes of configuration element names. See customizing JCA configuration elements.


Parent topic: Overview of JCA configuration elements