jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vibhu Sharma <vi...@projectoffguard.com>
Subject Re: User Managed Transactions on Tomcat : Please Validate the Solution
Date Tue, 06 Oct 2009 16:03:17 GMT
Hi All,
I have been trying to configure JOTM with Jackrabbit (with
DerbyPersistenceManager) and MySQL 5.0 on Tomcat 6.0.14. I have managed to
achive this and now the Transactions across Jackrabbit and MySQL are atomic.

But the solution (pasted below) is (I feel) a little round about and I donot
know the correctness as I am a newbie to JTA. Please validate if the
approach is correct.

The JOTM configuration is done according to the example at:

The repository is configured according to Deployment Model 2

/****** imports ********/
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.Node;
import javax.jcr.SimpleCredentials;

import org.apache.jackrabbit.api.XASession;
import org.objectweb.jotm.datasource.DataSourceFactory;

/******** code starts ******/

Context ctx = new InitialContext();

// JDBC stuff
DataSource ds =

UserTransaction ut =

System.out.println("<<< beginning the transaction >>>");

// get DB Connection
 java.sql.Connection conn = ds.getConnection();

//getting repository instance
 Repository repository =
 Session session = repository.login(new

 // extract TransactionManager from DatasourceFactory.jotm
 TransactionManager tmanager =
 // extract the current Transaction from TransactionManager
 Transaction trans = tmanager.getTransaction();
 // attach the XAResource from Session to Transaction

 // Perform changes to repository
 Node node = session.getRootNode();

 // ---------- call save() on Node ---> this is very Important
 // without this the changes don't persist even on transaction.commit()

 // JDBC statements
 Statement stmt = conn.createStatement();
 ResultSet rst =
     stmt.executeQuery("select id, foo from testdata");
 if(rst.next()) {
 System.out.println("foo = "+ foo +" (before completion)");

 PreparedStatement pstmt = conn.prepareStatement("update testdata set foo=?
where id=1");

  if (completion != null && completion.equals("commit")) {
      System.out.println("<<< committing the transaction >>>");
  } else {
      System.out.println("<<< rolling back the transaction >>>");

 // we set foo to the value stored in the DB
 rst =
     stmt.executeQuery("select id, foo from testdata");
 if(rst.next()) {
 System.out.println("foo = "+ foo +" (after completion)");



 System.out.println("<<< done >>>");

/******** code ends ******/


On Fri, Sep 25, 2009 at 3:41 PM, Vibhu Sharma <vibhu@projectoffguard.com>wrote:

> Hi all,
> My application uses MySQL and Jackrabbit to store data. It uses Tomcat as
> the container and the business logic is wired together with Struts.
> I am looking at using JTA to manage the transactions.
> I have looked into Tyrex (last updated in 2005) and JOTM, out of which I
> think JOTM is the better option(Please guide me if there is something
> better).
> I have tried to configure JOTM with Jackrabbit on Tomcat but with no
> success.
> Please can any body point me in the right direction or provide a link.
> So far I have been consulting this link -
> http://jotm.objectweb.org/current/jotm/doc/howto-tomcat-jotm.html
> regards
> Vibhu

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message