You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Paul Eggerling-Boeck <pa...@yahoo.com> on 2007/02/28 18:14:38 UTC

XA Transaction question

I read the Jackrabbit FAQ about transactions and have implemented
something like the following:

InitialContext context = new InitialContext();
Context environment = (Context) context.lookup("java:comp/env");
Repository repository = (Repository) environment.lookup("jcr/repository");
XASession session = (XASession)repository.login(new
SimpleCredentials("username", "password".toCharArray()), null);

XAResource xares = session.getXAResource();

// XID stuff from FAQ is next

xares.start(xid, XAResource.TMNOFLAGS);
// Create some nodes and properties
session.save();
xares.end(xid, XAResource.TMSUCCESS);
xares.rollback(xid);

Note that I'm testing a rollback here so there's no xares.prepare() or
xares.commit();

My problem is that the changes get persisted and not rolled back.  I'm
not using a UserTransaction or any transaction manager, just going at
the XAResource directly.  I read in the archives that the
session.save() method is all-or-nothing in and of itself so do I
really even need to do XA transactions if I just want to make sure all
my changes to the session are persisted as a unit?

Am I doing something wrong?  Anybody else run into this?

BTW, I'm using
org.apache.jackrabbit.core.fs.local.LocalFileSystem and
org.apache.jackrabbit.core.state.db.DerbyPersistenceManager

Thanks,

Paul

Re: XA Transaction question

Posted by Paul Eggerling-Boeck <pa...@yahoo.com>.
Sure, my code was set up to run in the doPost method of a servlet.

Here's the code:

XAResource xares = sess.getXAResource();

// create dummy Xid
Xid xid = new Xid() {
	public byte[] getBranchQualifier() {
		return "BranchQ".getBytes();
	}

	public int getFormatId() {
		return 0;
	}

	public byte[] getGlobalTransactionId() {
		return "TransId".getBytes();
	}
};

xares.start(xid, XAResource.TMNOFLAGS);
Node root = sess.getRootNode();
Node client = root.addNode("client");
String name = request.getParameter("clientName");
client.setProperty("name", name);
sess.save();
xares.end(xid, XAResource.TMSUCCESS);
xares.prepare(xid);
xares.rollback(xid);

Thanks!

Paul


On 3/5/07, Dominique Pfister <do...@day.com> wrote:
> Hi Paul,
>
> I set up the tomcat/jackrabbit environment as described and was not
> able to reproduce your error with the following additions to your
> sample code (inside a jsp) and jackrabbit 1.2.2:
>
>   // Create some nodes and properties
>   session.getRootNode().addNode("a");
>   ...
>
>   ...
>   xares.rollback(xid);
>   %><%= session.getRootNode().hasNode("a") %>
>
> This always gives me "false" on the output, as expected. Can you tell
> me, what operations you invoked and what was your call context (e.g.
> servlet) ?
>
> Kind regards
> Dominique
>
> On 3/1/07, Paul Eggerling-Boeck <pa...@yahoo.com> wrote:
> > Thanks Dominique,
> >
> > I followed the instructions for Tomcat 5.5 on the Model 2 deployment
> > instructions page.  I copied and pasted the XML elements verbatim and
> > changed the configFilePath and repHomeDir appropriately.
> >
> > I also copied the .jars listed below into [tomcat home]/common/lib:
> > jcr-1.0.jar
> > jackrabbit-api-1.2.1.jar
> > jackrabbit-core-1.2.1.jar
> > jackrabbit-index-filters-1.2.1.jar
> > concurrent-1.3.4.jar
> > derby-10.2.1.6.jar
> > jackrabbit-webdav-1.2.1.jar
> > jackrabbit-jcr-commons-1.2.1.jar
> > log4j-1.2.8.jar
> > jackrabbit-jcr-server-1.2.1.jar
> > commons-httpclient-3.0.jar
> > xmlParserAPIs-2.0.2.jar
> > commons-collections-3.1.jar
> > geronimo-jta_1.0.1B_spec-1.0.1.jar
> > lucene-core-2.0.0.jar
> > commons-codec-1.2.jar
> > xercesImpl-2.6.2.jar
> > jackrabbit-jcr-rmi-1.2.1.jar
> > jcl104-over-slf4j-1.0.jar
> > slf4j-log4j12-1.0.jar
> >
> > On 3/1/07, Dominique Pfister <do...@day.com> wrote:
> > > Hi Paul,
> > >
> > > you're right, session.save() will either save all or nothing, so you
> > > don't really need transactions here. But just out of curiosity - and
> > > because and I don't think anything is wrong with your sample code -
> > > can you tell me how you set up your repository in the JNDI context?
> > >
> > > Kind regards
> > > Dominique
> > >
> > >
> > > On 2/28/07, Paul Eggerling-Boeck <pa...@yahoo.com> wrote:
> > > > I read the Jackrabbit FAQ about transactions and have implemented
> > > > something like the following:
> > > >
> > > > InitialContext context = new InitialContext();
> > > > Context environment = (Context) context.lookup("java:comp/env");
> > > > Repository repository = (Repository) environment.lookup("jcr/repository");
> > > > XASession session = (XASession)repository.login(new
> > > > SimpleCredentials("username", "password".toCharArray()), null);
> > > >
> > > > XAResource xares = session.getXAResource();
> > > >
> > > > // XID stuff from FAQ is next
> > > >
> > > > xares.start(xid, XAResource.TMNOFLAGS);
> > > > // Create some nodes and properties
> > > > session.save();
> > > > xares.end(xid, XAResource.TMSUCCESS);
> > > > xares.rollback(xid);
> > > >
> > > > Note that I'm testing a rollback here so there's no xares.prepare() or
> > > > xares.commit();
> > > >
> > > > My problem is that the changes get persisted and not rolled back.  I'm
> > > > not using a UserTransaction or any transaction manager, just going at
> > > > the XAResource directly.  I read in the archives that the
> > > > session.save() method is all-or-nothing in and of itself so do I
> > > > really even need to do XA transactions if I just want to make sure all
> > > > my changes to the session are persisted as a unit?
> > > >
> > > > Am I doing something wrong?  Anybody else run into this?
> > > >
> > > > BTW, I'm using
> > > > org.apache.jackrabbit.core.fs.local.LocalFileSystem and
> > > > org.apache.jackrabbit.core.state.db.DerbyPersistenceManager
> > > >
> > > > Thanks,
> > > >
> > > > Paul
> > > >
> > >
> >
>

Re: XA Transaction question

Posted by Dominique Pfister <do...@day.com>.
Hi Paul,

I set up the tomcat/jackrabbit environment as described and was not
able to reproduce your error with the following additions to your
sample code (inside a jsp) and jackrabbit 1.2.2:

  // Create some nodes and properties
  session.getRootNode().addNode("a");
  ...

  ...
  xares.rollback(xid);
  %><%= session.getRootNode().hasNode("a") %>

This always gives me "false" on the output, as expected. Can you tell
me, what operations you invoked and what was your call context (e.g.
servlet) ?

Kind regards
Dominique

On 3/1/07, Paul Eggerling-Boeck <pa...@yahoo.com> wrote:
> Thanks Dominique,
>
> I followed the instructions for Tomcat 5.5 on the Model 2 deployment
> instructions page.  I copied and pasted the XML elements verbatim and
> changed the configFilePath and repHomeDir appropriately.
>
> I also copied the .jars listed below into [tomcat home]/common/lib:
> jcr-1.0.jar
> jackrabbit-api-1.2.1.jar
> jackrabbit-core-1.2.1.jar
> jackrabbit-index-filters-1.2.1.jar
> concurrent-1.3.4.jar
> derby-10.2.1.6.jar
> jackrabbit-webdav-1.2.1.jar
> jackrabbit-jcr-commons-1.2.1.jar
> log4j-1.2.8.jar
> jackrabbit-jcr-server-1.2.1.jar
> commons-httpclient-3.0.jar
> xmlParserAPIs-2.0.2.jar
> commons-collections-3.1.jar
> geronimo-jta_1.0.1B_spec-1.0.1.jar
> lucene-core-2.0.0.jar
> commons-codec-1.2.jar
> xercesImpl-2.6.2.jar
> jackrabbit-jcr-rmi-1.2.1.jar
> jcl104-over-slf4j-1.0.jar
> slf4j-log4j12-1.0.jar
>
> On 3/1/07, Dominique Pfister <do...@day.com> wrote:
> > Hi Paul,
> >
> > you're right, session.save() will either save all or nothing, so you
> > don't really need transactions here. But just out of curiosity - and
> > because and I don't think anything is wrong with your sample code -
> > can you tell me how you set up your repository in the JNDI context?
> >
> > Kind regards
> > Dominique
> >
> >
> > On 2/28/07, Paul Eggerling-Boeck <pa...@yahoo.com> wrote:
> > > I read the Jackrabbit FAQ about transactions and have implemented
> > > something like the following:
> > >
> > > InitialContext context = new InitialContext();
> > > Context environment = (Context) context.lookup("java:comp/env");
> > > Repository repository = (Repository) environment.lookup("jcr/repository");
> > > XASession session = (XASession)repository.login(new
> > > SimpleCredentials("username", "password".toCharArray()), null);
> > >
> > > XAResource xares = session.getXAResource();
> > >
> > > // XID stuff from FAQ is next
> > >
> > > xares.start(xid, XAResource.TMNOFLAGS);
> > > // Create some nodes and properties
> > > session.save();
> > > xares.end(xid, XAResource.TMSUCCESS);
> > > xares.rollback(xid);
> > >
> > > Note that I'm testing a rollback here so there's no xares.prepare() or
> > > xares.commit();
> > >
> > > My problem is that the changes get persisted and not rolled back.  I'm
> > > not using a UserTransaction or any transaction manager, just going at
> > > the XAResource directly.  I read in the archives that the
> > > session.save() method is all-or-nothing in and of itself so do I
> > > really even need to do XA transactions if I just want to make sure all
> > > my changes to the session are persisted as a unit?
> > >
> > > Am I doing something wrong?  Anybody else run into this?
> > >
> > > BTW, I'm using
> > > org.apache.jackrabbit.core.fs.local.LocalFileSystem and
> > > org.apache.jackrabbit.core.state.db.DerbyPersistenceManager
> > >
> > > Thanks,
> > >
> > > Paul
> > >
> >
>

Re: XA Transaction question

Posted by Paul Eggerling-Boeck <pa...@yahoo.com>.
Thanks Dominique,

I followed the instructions for Tomcat 5.5 on the Model 2 deployment
instructions page.  I copied and pasted the XML elements verbatim and
changed the configFilePath and repHomeDir appropriately.

I also copied the .jars listed below into [tomcat home]/common/lib:
jcr-1.0.jar
jackrabbit-api-1.2.1.jar
jackrabbit-core-1.2.1.jar
jackrabbit-index-filters-1.2.1.jar
concurrent-1.3.4.jar
derby-10.2.1.6.jar
jackrabbit-webdav-1.2.1.jar
jackrabbit-jcr-commons-1.2.1.jar
log4j-1.2.8.jar
jackrabbit-jcr-server-1.2.1.jar
commons-httpclient-3.0.jar
xmlParserAPIs-2.0.2.jar
commons-collections-3.1.jar
geronimo-jta_1.0.1B_spec-1.0.1.jar
lucene-core-2.0.0.jar
commons-codec-1.2.jar
xercesImpl-2.6.2.jar
jackrabbit-jcr-rmi-1.2.1.jar
jcl104-over-slf4j-1.0.jar
slf4j-log4j12-1.0.jar

On 3/1/07, Dominique Pfister <do...@day.com> wrote:
> Hi Paul,
>
> you're right, session.save() will either save all or nothing, so you
> don't really need transactions here. But just out of curiosity - and
> because and I don't think anything is wrong with your sample code -
> can you tell me how you set up your repository in the JNDI context?
>
> Kind regards
> Dominique
>
>
> On 2/28/07, Paul Eggerling-Boeck <pa...@yahoo.com> wrote:
> > I read the Jackrabbit FAQ about transactions and have implemented
> > something like the following:
> >
> > InitialContext context = new InitialContext();
> > Context environment = (Context) context.lookup("java:comp/env");
> > Repository repository = (Repository) environment.lookup("jcr/repository");
> > XASession session = (XASession)repository.login(new
> > SimpleCredentials("username", "password".toCharArray()), null);
> >
> > XAResource xares = session.getXAResource();
> >
> > // XID stuff from FAQ is next
> >
> > xares.start(xid, XAResource.TMNOFLAGS);
> > // Create some nodes and properties
> > session.save();
> > xares.end(xid, XAResource.TMSUCCESS);
> > xares.rollback(xid);
> >
> > Note that I'm testing a rollback here so there's no xares.prepare() or
> > xares.commit();
> >
> > My problem is that the changes get persisted and not rolled back.  I'm
> > not using a UserTransaction or any transaction manager, just going at
> > the XAResource directly.  I read in the archives that the
> > session.save() method is all-or-nothing in and of itself so do I
> > really even need to do XA transactions if I just want to make sure all
> > my changes to the session are persisted as a unit?
> >
> > Am I doing something wrong?  Anybody else run into this?
> >
> > BTW, I'm using
> > org.apache.jackrabbit.core.fs.local.LocalFileSystem and
> > org.apache.jackrabbit.core.state.db.DerbyPersistenceManager
> >
> > Thanks,
> >
> > Paul
> >
>

Re: XA Transaction question

Posted by Dominique Pfister <do...@day.com>.
Hi Paul,

you're right, session.save() will either save all or nothing, so you
don't really need transactions here. But just out of curiosity - and
because and I don't think anything is wrong with your sample code -
can you tell me how you set up your repository in the JNDI context?

Kind regards
Dominique


On 2/28/07, Paul Eggerling-Boeck <pa...@yahoo.com> wrote:
> I read the Jackrabbit FAQ about transactions and have implemented
> something like the following:
>
> InitialContext context = new InitialContext();
> Context environment = (Context) context.lookup("java:comp/env");
> Repository repository = (Repository) environment.lookup("jcr/repository");
> XASession session = (XASession)repository.login(new
> SimpleCredentials("username", "password".toCharArray()), null);
>
> XAResource xares = session.getXAResource();
>
> // XID stuff from FAQ is next
>
> xares.start(xid, XAResource.TMNOFLAGS);
> // Create some nodes and properties
> session.save();
> xares.end(xid, XAResource.TMSUCCESS);
> xares.rollback(xid);
>
> Note that I'm testing a rollback here so there's no xares.prepare() or
> xares.commit();
>
> My problem is that the changes get persisted and not rolled back.  I'm
> not using a UserTransaction or any transaction manager, just going at
> the XAResource directly.  I read in the archives that the
> session.save() method is all-or-nothing in and of itself so do I
> really even need to do XA transactions if I just want to make sure all
> my changes to the session are persisted as a unit?
>
> Am I doing something wrong?  Anybody else run into this?
>
> BTW, I'm using
> org.apache.jackrabbit.core.fs.local.LocalFileSystem and
> org.apache.jackrabbit.core.state.db.DerbyPersistenceManager
>
> Thanks,
>
> Paul
>