You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Vibhu Sharma <vi...@projectoffguard.com> on 2009/10/08 12:24:56 UTC

Re: User Managed Transactions...

Hi
I have managed to Run MySQL and Jackrabbit(with Derby Persistence Manager)
wiht JOTM.
Following is the code snippet. This code makes the transactions atomic
across MySQL and Jackrabbit.


/******* code starts ******/
Context ctx = new InitialContext();

// JDBC stuff
DataSource ds =
    (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");

UserTransaction ut =
(UserTransaction)ctx.lookup("java:comp/UserTransaction");

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

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

//getting repository instance
 Repository repository =
(Repository)ctx.lookup("java:comp/env/jcr/repository");
 Session session = repository.login(new
SimpleCredentials("user","user".toCharArray()));

 // extract TransactionManager from DatasourceFactory.jotm
 TransactionManager tmanager =
DataSourceFactory.jotm.getTransactionManager();

 // extract the current Transaction from TransactionManager
 Transaction trans = tmanager.getTransaction();

 // attach the XAResource from Session to Transaction
 trans.enlistResource(((XASession)session).getXAResource());

 // Perform changes to repository
 Node node = session.getRootNode();
 node.addNode("node_to_be_added","base:dummy");

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

// JDBC statements
// ...
// ...

// Rollback/commit on UserTransaction Object now makes changes in Both DB
and repository
// ut.rollback() or ut.commit()

// cleanup
session.logout();
conn.close()


The complete code for the JOTM tutorial with the Jackrabbit integration is
at :
http://www.nabble.com/Re:-User-Managed-Transactions-on-Tomcat-:-Please-Validate-the--Solution-td25771662.html

This may not be completely correct, as I am also new to JTA, but the
transactions done using this method are atomic.
Still searching for the standard solution

Thanks and hope this takes us a little fwd
Vibhu
.




On Mon, Aug 24, 2009 at 7:20 PM, Gadbury <ga...@googlemail.com> wrote:

>
> Hi all,
>
> Sorry to come back to haunt you all but I am once again confusing myself
> with Transactions.
>
> There seem to be so many different variations / terms for transactions!
>
> A local transaction
> A distributed transaction
> A global transaction
> A user transaction
> A container-managed transaction ...?
>
> I'm guessing some of these are synonyms, and that they're not all
> different!
>
> Currently, we are looking into the use of the spring-modules-jcr module for
> use with transactions.  I understand that distributed transactions use JTA
> and XA Resource (which I have got running without spring-modules-jcr,
> thanks
> to the help from you all here), but I am not clear what a local transaction
> manager is within spring-modules-jcr.  What is a local transaction?  I am
> trying to work out whether I need to use the local transaction manager or
> the distributed transaction manager in Jackrabbit.  Our concern is that XA
> Transactions are only supported by MySQL for the INNO_DB engine, and we may
> later have a requirement to use Jackrabbit with a clustered database.
>
> Thanks for reading and any aadvice would be greatly appreciated.
> --
> View this message in context:
> http://www.nabble.com/User-Managed-Transactions...-tp24687924p25116400.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>

Re: User Managed Transactions...

Posted by Vibhu Sharma <vi...@projectoffguard.com>.
Thanks Mihai for the Atomikos tip. I'll look in to it.
Also its a relief to know that somebody else is also following the same
approach as you are.

cheers!!
Vibhu

On Thu, Oct 8, 2009 at 4:57 PM, Mihai Vasilache
<mi...@yahoo.com>wrote:

> I am also new to JackRabbit and i am using the same approach: manually
> attach the JCR XAResource to the global transaction. For the database i am
> using JPA/Hibernate and hibernate is joining the transaction automtically.
> After searching o the mailing list archives i found that this is the
> correct approach unless you are using a real ejb container, in that case you
> can access the JackRabbit as a JCA resource.
>
> And i found this on the net:
> https://test.kuali.org/confluence/display/KULRICE/Replacing+JOTM+and+XAPool+with+Atomikos
>
> Mihai
>
>
>
>
> ________________________________
> From: Vibhu Sharma <vi...@projectoffguard.com>
> To: users@jackrabbit.apache.org
> Sent: Thu, October 8, 2009 1:24:56 PM
> Subject: Re: User Managed Transactions...
>
> Hi
> I have managed to Run MySQL and Jackrabbit(with Derby Persistence Manager)
> wiht JOTM.
> Following is the code snippet. This code makes the transactions atomic
> across MySQL and Jackrabbit.
>
>
> /******* code starts ******/
> Context ctx = new InitialContext();
>
> // JDBC stuff
> DataSource ds =
>    (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
>
> UserTransaction ut =
> (UserTransaction)ctx.lookup("java:comp/UserTransaction");
>
> System.out.println("<<< beginning the transaction >>>");
> ut.begin();
>
> // get DB Connection
> java.sql.Connection conn = ds.getConnection();
>
> //getting repository instance
> Repository repository =
> (Repository)ctx.lookup("java:comp/env/jcr/repository");
> Session session = repository.login(new
> SimpleCredentials("user","user".toCharArray()));
>
> // extract TransactionManager from DatasourceFactory.jotm
> TransactionManager tmanager =
> DataSourceFactory.jotm.getTransactionManager();
>
> // extract the current Transaction from TransactionManager
> Transaction trans = tmanager.getTransaction();
>
> // attach the XAResource from Session to Transaction
> trans.enlistResource(((XASession)session).getXAResource());
>
> // Perform changes to repository
> Node node = session.getRootNode();
> node.addNode("node_to_be_added","base:dummy");
>
> // ---------- call save() on Node ---> this is very Important
> // without this the changes don't persist even on transaction.commit()
> node.save();
>
> // JDBC statements
> // ...
> // ...
>
> // Rollback/commit on UserTransaction Object now makes changes in Both DB
> and repository
> // ut.rollback() or ut.commit()
>
> // cleanup
> session.logout();
> conn.close()
>
>
> The complete code for the JOTM tutorial with the Jackrabbit integration is
> at :
>
> http://www.nabble.com/Re:-User-Managed-Transactions-on-Tomcat-:-Please-Validate-the--Solution-td25771662.html
>
> This may not be completely correct, as I am also new to JTA, but the
> transactions done using this method are atomic.
> Still searching for the standard solution
>
> Thanks and hope this takes us a little fwd
> Vibhu
> .
>
>
>
>
> On Mon, Aug 24, 2009 at 7:20 PM, Gadbury <ga...@googlemail.com> wrote:
>
> >
> > Hi all,
> >
> > Sorry to come back to haunt you all but I am once again confusing myself
> > with Transactions.
> >
> > There seem to be so many different variations / terms for transactions!
> >
> > A local transaction
> > A distributed transaction
> > A global transaction
> > A user transaction
> > A container-managed transaction ...?
> >
> > I'm guessing some of these are synonyms, and that they're not all
> > different!
> >
> > Currently, we are looking into the use of the spring-modules-jcr module
> for
> > use with transactions.  I understand that distributed transactions use
> JTA
> > and XA Resource (which I have got running without spring-modules-jcr,
> > thanks
> > to the help from you all here), but I am not clear what a local
> transaction
> > manager is within spring-modules-jcr.  What is a local transaction?  I am
> > trying to work out whether I need to use the local transaction manager or
> > the distributed transaction manager in Jackrabbit.  Our concern is that
> XA
> > Transactions are only supported by MySQL for the INNO_DB engine, and we
> may
> > later have a requirement to use Jackrabbit with a clustered database.
> >
> > Thanks for reading and any aadvice would be greatly appreciated.
> > --
> > View this message in context:
> >
> http://www.nabble.com/User-Managed-Transactions...-tp24687924p25116400.html
> > Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
> >
> >
>

Re: User Managed Transactions...

Posted by Mihai Vasilache <mi...@yahoo.com>.
I am also new to JackRabbit and i am using the same approach: manually attach the JCR XAResource to the global transaction. For the database i am using JPA/Hibernate and hibernate is joining the transaction automtically.
After searching o the mailing list archives i found that this is the correct approach unless you are using a real ejb container, in that case you can access the JackRabbit as a JCA resource.

And i found this on the net: https://test.kuali.org/confluence/display/KULRICE/Replacing+JOTM+and+XAPool+with+Atomikos

Mihai




________________________________
From: Vibhu Sharma <vi...@projectoffguard.com>
To: users@jackrabbit.apache.org
Sent: Thu, October 8, 2009 1:24:56 PM
Subject: Re: User Managed Transactions...

Hi
I have managed to Run MySQL and Jackrabbit(with Derby Persistence Manager)
wiht JOTM.
Following is the code snippet. This code makes the transactions atomic
across MySQL and Jackrabbit.


/******* code starts ******/
Context ctx = new InitialContext();

// JDBC stuff
DataSource ds =
    (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");

UserTransaction ut =
(UserTransaction)ctx.lookup("java:comp/UserTransaction");

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

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

//getting repository instance
Repository repository =
(Repository)ctx.lookup("java:comp/env/jcr/repository");
Session session = repository.login(new
SimpleCredentials("user","user".toCharArray()));

// extract TransactionManager from DatasourceFactory.jotm
TransactionManager tmanager =
DataSourceFactory.jotm.getTransactionManager();

// extract the current Transaction from TransactionManager
Transaction trans = tmanager.getTransaction();

// attach the XAResource from Session to Transaction
trans.enlistResource(((XASession)session).getXAResource());

// Perform changes to repository
Node node = session.getRootNode();
node.addNode("node_to_be_added","base:dummy");

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

// JDBC statements
// ...
// ...

// Rollback/commit on UserTransaction Object now makes changes in Both DB
and repository
// ut.rollback() or ut.commit()

// cleanup
session.logout();
conn.close()


The complete code for the JOTM tutorial with the Jackrabbit integration is
at :
http://www.nabble.com/Re:-User-Managed-Transactions-on-Tomcat-:-Please-Validate-the--Solution-td25771662.html

This may not be completely correct, as I am also new to JTA, but the
transactions done using this method are atomic.
Still searching for the standard solution

Thanks and hope this takes us a little fwd
Vibhu
.




On Mon, Aug 24, 2009 at 7:20 PM, Gadbury <ga...@googlemail.com> wrote:

>
> Hi all,
>
> Sorry to come back to haunt you all but I am once again confusing myself
> with Transactions.
>
> There seem to be so many different variations / terms for transactions!
>
> A local transaction
> A distributed transaction
> A global transaction
> A user transaction
> A container-managed transaction ...?
>
> I'm guessing some of these are synonyms, and that they're not all
> different!
>
> Currently, we are looking into the use of the spring-modules-jcr module for
> use with transactions.  I understand that distributed transactions use JTA
> and XA Resource (which I have got running without spring-modules-jcr,
> thanks
> to the help from you all here), but I am not clear what a local transaction
> manager is within spring-modules-jcr.  What is a local transaction?  I am
> trying to work out whether I need to use the local transaction manager or
> the distributed transaction manager in Jackrabbit.  Our concern is that XA
> Transactions are only supported by MySQL for the INNO_DB engine, and we may
> later have a requirement to use Jackrabbit with a clustered database.
>
> Thanks for reading and any aadvice would be greatly appreciated.
> --
> View this message in context:
> http://www.nabble.com/User-Managed-Transactions...-tp24687924p25116400.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>