Java Code Examples for javax.transaction.RollbackException#initCause()
The following examples show how to use
javax.transaction.RollbackException#initCause() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiThreadedTx.java From reladomo with Apache License 2.0 | 5 votes |
@Override public void postCommitCheck(MultiThreadedTx tx) throws RollbackException { String msg = "commit did not succeed. Rolled back instead. "; if (tx.timedout) { msg += " rollback was due to timeout"; } RollbackException ex = new RollbackException(msg); if (tx.rollbackCause != null) { ex.initCause(tx.rollbackCause); } throw ex; }
Example 2
Source File: JackRabbitUserTransaction.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
/** * @see javax.transaction.UserTransaction#commit */ @Override public void commit() throws IllegalStateException, RollbackException, SecurityException, SystemException { if (status != Status.STATUS_ACTIVE) { throw new IllegalStateException("Transaction not active"); } try { xares.end(xid, XAResource.TMSUCCESS); status = Status.STATUS_PREPARING; xares.prepare(xid); status = Status.STATUS_PREPARED; status = Status.STATUS_COMMITTING; xares.commit(xid, false); status = Status.STATUS_COMMITTED; } catch (XAException e) { if (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND) { RollbackException rollbackException = new RollbackException(e.toString()); rollbackException.initCause(e); throw rollbackException; } final SystemException systemException = new SystemException("Unable to commit transaction: " + "XA_ERR=" + e.errorCode); systemException.initCause(e); throw systemException; } }
Example 3
Source File: SpringAwareUserTransaction.java From alfresco-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * @throws IllegalStateException if a transaction was not started */ public synchronized void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { // perform checks TransactionInfo txnInfo = getTransactionInfo(); int status = getStatus(); // check the status if (status == Status.STATUS_NO_TRANSACTION) { throw new IllegalStateException("The transaction has not yet begun"); } else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK) { throw new RollbackException("The transaction has already been rolled back"); } else if (status == Status.STATUS_MARKED_ROLLBACK) { throw new RollbackException("The transaction has already been marked for rollback"); } else if (status == Status.STATUS_COMMITTING || status == Status.STATUS_COMMITTED) { throw new IllegalStateException("The transaction has already been committed"); } else if (status != Status.STATUS_ACTIVE || txnInfo == null) { throw new IllegalStateException("No user transaction is active"); } if (!finalized) { try { // the status seems correct - we can try a commit commitTransactionAfterReturning(txnInfo); } catch (Throwable e) { if (logger.isDebugEnabled()) { logger.debug("Transaction didn't commit", e); } // commit failed internalStatus = Status.STATUS_ROLLEDBACK; RollbackException re = new RollbackException("Transaction didn't commit: " + e.getMessage()); // Stick the originating reason for failure into the exception. re.initCause(e); throw re; } finally { // make sure that we clean up the stack cleanupTransactionInfo(txnInfo); finalized = true; // clean up leaked transaction logging isBeginMatched = true; beginCallStack = null; } } // regardless of whether the transaction was finally committed or not, the status // as far as UserTransaction is concerned should be 'committed' // keep track that this UserTransaction was explicitly committed internalStatus = Status.STATUS_COMMITTED; // done if (logger.isDebugEnabled()) { logger.debug("Committed user transaction: " + this); } }