Sunday, 20 March 2016

How to use JDBC and transactions in Tomcat with JOTM ?


Setup the JOTM library JARs

Put these JARs in the lib/ directory of Tomcat :
  • jotm.jar 
  • jotm_jrmp_stubs.jar 
  • ow_carol.jar 
  • jta-spec1_0_1.jar 
  • jts1_0.jar 
  • objectweb-datasource.jar 
  • xapool.jar 
  • howl.jar 
  • commons-cli-1.0.jar 
  • connector-1_5.jar

All these jar files need to be placed on $TOMCAT_HOME / common / lib /  so that both Tomcat and your web application will see them.


Configuring JOTM

Create a file named carol.properties with the following properties, put this file in classpath.
# JNDI (Protocol Invocation)
carol.protocols=jrmp
# Local RMI Invocation
carol.jvm.rmi.local.call=false
# do not use CAROL JNDI wrapper
carol.start.jndi=false
# do not start a name server
carol.start.ns=false
# Naming Factory
carol.jndi.java.naming.factory.url.pkgs=org.apache.naming


Configuring DataSource

In META-INF / context.xml, configure the <Resource> and <Transaction> elements as follows :
<Context reloadable="true">
  <Resource name="jdbc/myDB" auth="Container
    type="javax.sql.DataSource"    
    factory="org.objectweb.jndi.DataSourceFactory"
    driverClassName="org.postgresql.Driver" username="mojo
    password="jojo" url="jdbc:postgresql://localhost/javatest" />

  <Transaction factory="org.objectweb.jotm.UserTransactionFactory
    jotm.timeout="60" />
</Context>

Example for Oracle
<Resource name="jdbc/myDB1" auth="Container
  type="javax.sql.DataSource
  factory="org.objectweb.jndi.DataSourceFactory"
  driverClassName="oracle.jdbc.driver.OracleDriver"
  username="vod" password="vox"  
  url="jdbc:oracle:thin:@172.16.1.216:1521:nbo" maxActive="5" 
  maxIdle="5" maxWait="10000" removeAbandoned="true"
  removeAbandonedTimeout="300"  logAbandoned="true" />

No comments:

Post a Comment

Note: only a member of this blog may post a comment.