Monday, May 16, 2011

JNDI locations jms database

In the source code it's good practice to use Enterprise Information Systems (EIS) connection factories. In the Enterprise Manager this eis JNDI (Java Naming and Directory Interface) location points to the datasource JNDI location. Therefor the physical endpoint information can be kept outside the sourcecode, either in the connection factory (quick and dirty) or in a connection pool (multi-layered) to which the connection factory points to, via a datasource.

Here two examples using connection pools, one for a database connection and one JMS connection with the database as datastore.

Database connection, the source JNDI location is eis/db/XREF with the following connection factory $SOA_HOME/j2ee/oc4j_soa/application-deployments/default/DbAdapter/oc4j-ra.xml:
<connector-factory location="eis/db/XREF" connector-name="DbAdapter">
  <config-property name="xADataSourceName" value="jdbc/XREFDataSource"/>
  <config-property name="dataSourceName" value=""/>
  <config-property name="platformClassName" value="oracle.toplink.platform.database.Oracle9Platform"/>
  <config-property name="usesNativeSequencing" value="true"/>
  <config-property name="sequencePreallocationSize" value="50"/>
  <config-property name="defaultNChar" value="false"/>
  <config-property name="usesBatchWriting" value="true"/>
  <config-property name="usesSkipLocking" value="false"/>
  <connection-pooling use="none">
  </connection-pooling>
  <security-config use="none">
  </security-config>
  <connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
</connector-factory>

There is also a GUI available in the Enterprise Manager, goto instance [oc4j_soa], tab Applications and click on Default application. Then click module DbAdapter and tab Connection Factories.

The connection factory points to the JNDI location jdbc/XREFDataSource in $SOA_HOME/j2ee/oc4j_soa/config/data-sources.xml:
<managed-data-source connection-pool-name="XREFConnectionPool" jndi-name="jdbc/XREFDataSource" name="XREFDataSource"/>
<connection-pool name="XREFConnectionPool">
  <connection-factory factory-class="oracle.jdbc.xa.client.OracleXADataSource" user="aia" password="[password]" url="jdbc:oracle:thin:@[DB-HOST]:[DB-PORT]:[DB-SID]" commit-record-table-name=""/>
</connection-pool>

There is also a GUI available in the Enterprise Manager, goto instance [oc4j_soa], tab Administration and under Services go to task JDBC Resources.

That's it. Now the jms connection, the source JNDI location is eis/jms/JMSProducer with the following connection factory $SOA_HOME/j2ee/oc4j_soa/application-deployments/default/JmsAdapter/oc4j-ra.xml:
<connector-factory location="eis/jms/JMSProducer" connector-name="JmsAdapter">
  <config-property name="connectionFactoryLocation" value="java:comp/resource/JMSProducer/QueueConnectionFactories/QCF"/>
  <config-property name="factoryProperties" value=""/>
  <config-property name="acknowledgeMode" value="AUTO_ACKNOWLEDGE"/>
  <config-property name="isTopic" value="false"/>
  <config-property name="isTransacted" value="false"/>
  <config-property name="username" value="jmsuser"/>
  <config-property name="password" value="[password]"/>
  <connection-pooling use="none">
  </connection-pooling>
  <security-config use="none">
  </security-config>
  <connectionfactory-interface>oracle.tip.adapter.jms.IJmsConnectionFactory</connectionfactory-interface>
</connector-factory>

There is also a GUI available in the Enterprise Manager, goto instance [oc4j_soa], tab Applications and click on Default application. Then click module JmsAdapter and tab Connection Factories.

As you can see there is no JNDI location the connection factory refers to. This is done in the resource provider (you can see the name inside the config property connectionFactoryLocation, between the slashes after resource), the resource provider offers no Enterprise Manager GUI, only the xml file $SOA_HOME/j2ee/oc4j_soa/config/application.xml:
<resource-provider name="JMSProducer" class="oracle.jms.OjmsContext">
  <description>oc4j-jms AIASystem Queue Producer resource provider</description>
  <property name="datasource" value="jdbc/JMSDataSource" />
</resource-provider>


This resource provider points to the JNDI location jdbc/JMSDataSource in $SOA_HOME/j2ee/oc4j_soa/config/data-sources.xml:
<managed-data-source connection-pool-name="JMSConnectionPool" jndi-name="jdbc/JMSDataSource" name="JMSDataSource"/>
<connection-pool name="JMSConnectionPool">
  <connection-factory factory-class="oracle.jdbc.xa.client.OracleXADataSource" user="jmsuser" password="[password]" url="jdbc:oracle:thin:@[DB-HOST]:[DB-PORT]:[DB-SID]" commit-record-table-name=""/>
</connection-pool>

There is also a GUI available in the Enterprise Manager, goto instance [oc4j_soa], tab Administration and under Services go to task JDBC Resources.

No comments:

Post a Comment