List of usage examples for javax.transaction.xa XAException XAException
public XAException(int errcode)
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XAFileResourceManager.java
/** * Set the current transaction <code>timeout</code> value for this * <code>XAFileResourceManager</code> instance. Once set, this timeout value is * effective until <code>setTransactionTimeout</code> is invoked again with * a different value./*from w w w . j a v a2s . c o m*/ * The method acts like the * {@link org.apache.commons.transaction.file.FileResourceManager#setTransactionTimeout(Object, long)} * does. * * @param seconds transaction timeout value in seconds * @return true if transaction timeout value is set successfully; * otherwise false */ public boolean setTransactionTimeout(int seconds) throws XAException { System.out.println("XAFileResourceManager.setTransactionTimeout(timeout=" + seconds + ")"); try { freMngr.setTransactionTimeout(curTxId, seconds * 1000); } catch (ResourceManagerException rme) { throw new XAException(rme.getMessage()); } return false; }
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XAFileResourceManager.java
/** * Start work on behalf of a transaction branch specified in <code>xid</code>. * The method act like the//ww w. j av a 2 s.c o m * {@link org.apache.commons.transaction.file.FileResourceManager#startTransaction(Object)} * does. * @param xid a global Transaction id to be associated with this * Resource Manager instance * @param flags (can be anything) * @throws XAException if there is already a Transaction */ public void start(Xid xid, int flags) throws XAException { System.out.println("XAFileResourceManager.start(Xid=" + xid + ", flags=" + flags + ")"); if (currentXid != null) { System.out.println("XAFileResourceManager.start - wrong Xid!"); throw new XAException( "Current Transaction is: <" + currentXid + ">\nCannot start the new Transaction."); } try { freMngr.startTransaction(curTxId); } catch (ResourceManagerException rme) { throw new XAException(rme.getMessage()); } currentXid = xid; }
From source file:org.mule.util.xa.DefaultXASession.java
public void start(Xid xid, int flags) throws XAException { if (logger.isDebugEnabled()) { logger.debug(new StringBuffer(128).append("Thread ").append(Thread.currentThread()) .append(flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins" : " resumes") .append(" work on behalf of transaction branch ").append(xid).toString()); }/* w w w .java2s .co m*/ // A local transaction is already begun if (this.localContext != null) { throw new XAException(XAException.XAER_PROTO); } // This session has already been associated with an xid if (this.localXid != null) { throw new XAException(XAException.XAER_PROTO); } switch (flags) { // a new transaction case TMNOFLAGS: case TMJOIN: default: try { localContext = resourceManager.createTransactionContext(this); resourceManager.beginTransaction(localContext); } catch (Exception e) { // TODO MULE-863: Is logging necessary? logger.error("Could not create new transactional resource", e); throw (XAException) new XAException(e.getMessage()).initCause(e); } break; case TMRESUME: localContext = resourceManager.getSuspendedTransactionalResource(xid); if (localContext == null) { throw new XAException(XAException.XAER_NOTA); } // TODO: resume context resourceManager.removeSuspendedTransactionalResource(xid); break; } localXid = xid; resourceManager.addActiveTransactionalResource(localXid, localContext); }
From source file:org.mule.util.xa.DefaultXASession.java
public void end(Xid xid, int flags) throws XAException { if (logger.isDebugEnabled()) { logger.debug(new StringBuffer(128).append("Thread ").append(Thread.currentThread()) .append(flags == TMSUSPEND ? " suspends" : flags == TMFAIL ? " fails" : " ends") .append(" work on behalf of transaction branch ").append(xid).toString()); }/* ww w.j ava 2 s . co m*/ // No transaction is already begun if (localContext == null) { throw new XAException(XAException.XAER_NOTA); } // This session has already been associated with an xid if (localXid == null || !localXid.equals(xid)) { throw new XAException(XAException.XAER_PROTO); } try { switch (flags) { case TMSUSPEND: // TODO: suspend context resourceManager.addSuspendedTransactionalResource(localXid, localContext); resourceManager.removeActiveTransactionalResource(localXid); break; case TMFAIL: resourceManager.setTransactionRollbackOnly(localContext); break; case TMSUCCESS: // no-op default: // no-op break; } } catch (ResourceManagerException e) { throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } localXid = null; localContext = null; }
From source file:org.mule.util.xa.DefaultXASession.java
public void commit(Xid xid, boolean onePhase) throws XAException { if (xid == null) { throw new XAException(XAException.XAER_PROTO); }//from w ww.j av a 2 s . c om AbstractTransactionContext context = resourceManager.getActiveTransactionalResource(xid); if (context == null) { throw new XAException(XAException.XAER_NOTA); } if (logger.isDebugEnabled()) { logger.debug("Committing transaction branch " + xid); } if (context.status == Status.STATUS_MARKED_ROLLBACK) { throw new XAException(XAException.XA_RBROLLBACK); } try { if (context.status != Status.STATUS_PREPARED) { if (onePhase) { resourceManager.prepareTransaction(context); } else { throw new XAException(XAException.XAER_PROTO); } } resourceManager.commitTransaction(context); } catch (ResourceManagerException e) { throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } resourceManager.removeActiveTransactionalResource(xid); resourceManager.removeSuspendedTransactionalResource(xid); }
From source file:org.mule.util.xa.DefaultXASession.java
public void rollback(Xid xid) throws XAException { if (xid == null) { throw new XAException(XAException.XAER_PROTO); }//from ww w . ja va 2s . c o m AbstractTransactionContext context = resourceManager.getActiveTransactionalResource(xid); if (context == null) { throw new XAException(XAException.XAER_NOTA); } if (logger.isDebugEnabled()) { logger.debug("Rolling back transaction branch " + xid); } try { resourceManager.rollbackTransaction(context); } catch (ResourceManagerException e) { throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } resourceManager.removeActiveTransactionalResource(xid); resourceManager.removeSuspendedTransactionalResource(xid); }
From source file:org.mule.util.xa.DefaultXASession.java
public int prepare(Xid xid) throws XAException { if (xid == null) { throw new XAException(XAException.XAER_PROTO); }// ww w . j a v a2 s. c om AbstractTransactionContext context = resourceManager.getTransactionalResource(xid); if (context == null) { throw new XAException(XAException.XAER_NOTA); } if (logger.isDebugEnabled()) { logger.debug("Preparing transaction branch " + xid); } if (context.status == Status.STATUS_MARKED_ROLLBACK) { throw new XAException(XAException.XA_RBROLLBACK); } try { return resourceManager.prepareTransaction(context); } catch (ResourceManagerException e) { throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } }
From source file:org.mule.util.xa.DefaultXASession.java
public void forget(Xid xid) throws XAException { if (logger.isDebugEnabled()) { logger.debug("Forgetting transaction branch " + xid); }//from ww w. j a v a 2 s.c om AbstractTransactionContext context = resourceManager.getTransactionalResource(xid); if (context == null) { throw new XAException(XAException.XAER_NOTA); } resourceManager.removeActiveTransactionalResource(xid); resourceManager.removeSuspendedTransactionalResource(xid); }
From source file:org.mule.util.xa.XaTransactionRecoverer.java
public void rollbackDandlingTransaction(Xid xid) throws XAException { try {//from w w w . ja v a2s . c o m logger.info("Rollbacking danling tx with id " + xid); new PersistentXaTransactionContext(xaTxQueueTransactionJournal, queueProvider, xid).doRollback(); } catch (ResourceManagerException e) { logger.warn(e.getMessage()); if (logger.isDebugEnabled()) { logger.debug(e); } throw new XAException(XAException.XAER_NOTA); } }
From source file:org.mule.util.xa.XaTransactionRecoverer.java
public void commitDandlingTransaction(Xid xid, boolean onePhase) throws XAException { try {/* ww w . j a v a2 s . c o m*/ logger.info("Commiting danling tx with id " + xid); new PersistentXaTransactionContext(xaTxQueueTransactionJournal, queueProvider, xid).doCommit(); } catch (ResourceManagerException e) { logger.warn(e.getMessage()); if (logger.isDebugEnabled()) { logger.debug(e); } throw new XAException(XAException.XAER_NOTA); } }