List of usage examples for javax.transaction.xa XAResource prepare
int prepare(Xid xid) throws XAException;
From source file:org.seasar.karrta.jcr.intercepter.JcrTransactionInterceptor.java
public Object invoke(MethodInvocation invocation) throws Throwable { Thread currentThread = Thread.currentThread(); if (this.sessionManager_.isExist(currentThread)) { return invocation.proceed(); }//from ww w.ja v a 2s .c o m logger_.debug("::: [Begin Transaction] ::: [" + currentThread + "] :::"); // check in jcr-session. XASession session = (XASession) sessionManager_.borrowObject(currentThread); Xid xid = new Xid() { public byte[] getBranchQualifier() { return new byte[0]; } public int getFormatId() { return 0; } public byte[] getGlobalTransactionId() { return new byte[0]; } }; XAResource xares = session.getXAResource(); xares.start(xid, XAResource.TMNOFLAGS); Object result = null; try { for (Method m : invocation.getThis().getClass().getMethods()) { if ("setOcmQueryManager".equals(m.getName())) { m.invoke(invocation.getThis(), this.ocmFactory.getQueryManager()); } if ("setQueryManager".equals(m.getName())) { m.invoke(invocation.getThis(), session.getWorkspace().getQueryManager()); } } result = invocation.proceed(); xares.end(xid, XAResource.TMSUCCESS); xares.prepare(xid); xares.commit(xid, false); } catch (Exception e) { e.printStackTrace(); xares.rollback(xid); } finally { // check out jcr-session. this.sessionManager_.returnSession(currentThread, session); logger_.debug("::: [End Transaction] ::: [" + currentThread + "] :::"); } return result; }