Search in sources :

Example 1 with HeuristicCommitException

use of javax.transaction.HeuristicCommitException in project narayana by jbosstm.

the class XATerminatorImple method prepare.

/**
 * Prepare the imported transaction.
 *
 * @param xid
 *            the transaction to prepare.
 * @throws XAException
 *             thrown if any error occurs, including if the transaction has
 *             rolled back.
 * @return either XAResource.XA_OK if the transaction prepared, or
 *         XAResource.XA_RDONLY if it was a read-only transaction (and in
 *         which case, a second phase message is not expected/required.)
 */
public int prepare(Xid xid) throws XAException {
    // JBTM-927 this can happen if the transaction has been rolled back by the TransactionReaper
    SubordinateTransaction tx = null;
    try {
        tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    } catch (XAException xae) {
        if (xae.errorCode == XAException.XA_RBROLLBACK) {
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        }
        throw xae;
    }
    try {
        if (tx == null)
            throw new XAException(XAException.XAER_INVAL);
        switch(tx.doPrepare()) {
            case TwoPhaseOutcome.PREPARE_ONE_PHASE_COMMITTED:
                // Should never happen Would be great if there was heuristic commit :(
                SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
                jtaLogger.i18NLogger.fatalSubordinate1PCDuringPrepare(xid);
                throw new XAException(XAException.XAER_RMERR);
            case TwoPhaseOutcome.PREPARE_READONLY:
                SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
                return XAResource.XA_RDONLY;
            case TwoPhaseOutcome.PREPARE_NOTOK:
                // the JCA API spec limits what we can do in terms of reporting
                // problems.
                // try to use the exception code and cause to provide info
                // whilst
                // remaining API compliant. JBTM-427.
                Exception initCause = null;
                int xaExceptionCode = XAException.XA_RBROLLBACK;
                try {
                    tx.doRollback();
                } catch (HeuristicCommitException e) {
                    initCause = e;
                    xaExceptionCode = XAException.XAER_RMERR;
                } catch (HeuristicMixedException e) {
                    initCause = e;
                    xaExceptionCode = XAException.XAER_RMERR;
                } catch (SystemException e) {
                    initCause = e;
                    xaExceptionCode = XAException.XAER_RMERR;
                } catch (final HeuristicRollbackException e) {
                    initCause = e;
                    xaExceptionCode = XAException.XAER_RMERR;
                }
                SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
                XAException xaException = new XAException(xaExceptionCode);
                if (initCause != null) {
                    xaException.initCause(initCause);
                }
                throw xaException;
            case TwoPhaseOutcome.PREPARE_OK:
                return XAResource.XA_OK;
            case TwoPhaseOutcome.INVALID_TRANSACTION:
                throw new XAException(XAException.XAER_NOTA);
            default:
                throw new XAException(XAException.XA_RBOTHER);
        }
    } catch (XAException ex) {
        throw ex;
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) IOException(java.io.IOException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException)

Example 2 with HeuristicCommitException

use of javax.transaction.HeuristicCommitException in project narayana by jbosstm.

the class XATerminatorImple method rollback.

public void rollback(Xid xid) throws XAException {
    // JBTM-927 this can happen if the transaction has been rolled back by
    // the TransactionReaper
    SubordinateTransaction tx = null;
    try {
        tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    } catch (XAException xae) {
        if (xae.errorCode == XAException.XA_RBROLLBACK) {
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
            return;
        }
        throw xae;
    }
    try {
        if (tx == null)
            throw new XAException(XAException.XAER_INVAL);
        if (tx.baseXid() != null) {
            tx.doRollback();
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        } else
            throw new XAException(XAException.XA_RETRY);
    } catch (XAException ex) {
        if (ex.errorCode != XAException.XA_RETRY) {
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        }
        throw ex;
    } catch (HeuristicCommitException ex) {
        XAException xaException = new XAException(XAException.XA_HEURCOM);
        xaException.initCause(ex);
        throw xaException;
    } catch (final HeuristicRollbackException ex) {
        XAException xaException = new XAException(XAException.XA_HEURRB);
        xaException.initCause(ex);
        throw xaException;
    } catch (HeuristicMixedException ex) {
        XAException xaException = new XAException(XAException.XA_HEURMIX);
        xaException.initCause(ex);
        throw xaException;
    } catch (final IllegalStateException ex) {
        SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        XAException xaException = new XAException(XAException.XAER_NOTA);
        xaException.initCause(ex);
        throw xaException;
    } catch (SystemException ex) {
        SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        XAException xaException = new XAException(XAException.XAER_RMERR);
        xaException.initCause(ex);
        throw xaException;
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) HeuristicCommitException(javax.transaction.HeuristicCommitException)

Example 3 with HeuristicCommitException

use of javax.transaction.HeuristicCommitException in project narayana by jbosstm.

the class TransactionImple method doCommit.

/**
 * Drive the subordinate transaction to commit. It must have previously
 * been prepared.
 *
 *@return true if the transaction was committed
 *
 * @throws IllegalStateException thrown if the transaction has not been prepared
 * or is unknown.
 * @throws HeuristicMixedException thrown if a heuristic mixed outcome occurs
 * (where some participants committed whilst others rolled back).
 * @throws HeuristicRollbackException thrown if the transaction rolled back.
 * @throws SystemException thrown if some other error occurs.
 */
public boolean doCommit() throws IllegalStateException, HeuristicMixedException, HeuristicRollbackException, HeuristicCommitException, SystemException {
    try {
        SubordinateAtomicTransaction subAct = (SubordinateAtomicTransaction) super._theTransaction;
        int res = subAct.doCommit();
        switch(res) {
            case ActionStatus.H_COMMIT:
                throw new HeuristicCommitException();
            case ActionStatus.COMMITTED:
                break;
            case ActionStatus.COMMITTING:
                return false;
            case ActionStatus.ABORTED:
            case ActionStatus.ABORTING:
            case ActionStatus.H_ROLLBACK:
                throw new HeuristicRollbackException();
            case ActionStatus.H_HAZARD:
            case ActionStatus.H_MIXED:
                throw new HeuristicMixedException();
            case ActionStatus.INVALID:
                throw new IllegalStateException();
            default:
                // not sure what happened,
                throw new HeuristicMixedException();
        }
    } catch (ClassCastException ex) {
        ex.printStackTrace();
        UnexpectedConditionException unexpectedConditionException = new UnexpectedConditionException(ex.toString());
        unexpectedConditionException.initCause(ex);
        throw unexpectedConditionException;
    } finally {
        TransactionImple.removeTransaction(this);
    }
    return true;
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException)

Example 4 with HeuristicCommitException

use of javax.transaction.HeuristicCommitException in project narayana by jbosstm.

the class TransactionImple method doRollback.

/**
 * Drive the subordinate transaction to roll back. It need not have been previously
 * prepared.
 *
 * @throws IllegalStateException thrown if the transaction is not known by the
 * system or has been previously terminated.
 * @throws HeuristicMixedException thrown if a heuristic mixed outcome occurs
 * (can only happen if the transaction was previously prepared and then only if
 * some participants commit whilst others roll back).
 * @throws HeuristicCommitException thrown if the transaction commits (can only
 * happen if it was previously prepared).
 * @throws SystemException thrown if any other error occurs.
 */
public void doRollback() throws IllegalStateException, HeuristicMixedException, HeuristicCommitException, HeuristicRollbackException, SystemException {
    try {
        SubordinateAtomicTransaction subAct = (SubordinateAtomicTransaction) super._theTransaction;
        if (!endSuspendedRMs()) {
            jtaxLogger.i18NLogger.warn_jtax_transaction_jts_endsuspendfailed1();
        }
        int res = subAct.doRollback();
        switch(res) {
            case ActionStatus.ABORTED:
            case ActionStatus.ABORTING:
                break;
            case ActionStatus.H_ROLLBACK:
                throw new HeuristicRollbackException();
            case ActionStatus.COMMITTED:
            case ActionStatus.COMMITTING:
            case ActionStatus.H_COMMIT:
                throw new HeuristicCommitException();
            case ActionStatus.H_HAZARD:
            case ActionStatus.H_MIXED:
                throw new HeuristicMixedException();
            default:
                throw new HeuristicMixedException();
        }
    } catch (ClassCastException ex) {
        ex.printStackTrace();
        UnexpectedConditionException unexpectedConditionException = new UnexpectedConditionException(ex.toString());
        unexpectedConditionException.initCause(ex);
        throw unexpectedConditionException;
    } finally {
        TransactionImple.removeTransaction(this);
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException)

Example 5 with HeuristicCommitException

use of javax.transaction.HeuristicCommitException in project narayana by jbosstm.

the class XATerminatorImple method rollback.

/**
 * Rollback the imported transaction subordinate.
 *
 * @param xid
 *            the transaction to roll back.
 * @throws XAException
 *             thrown if there are any errors.
 */
public void rollback(Xid xid) throws XAException {
    // JBTM-927 this can happen if the transaction has been rolled back by
    // the TransactionReaper
    SubordinateTransaction tx = null;
    try {
        tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    } catch (XAException xae) {
        if (xae.errorCode == XAException.XA_RBROLLBACK) {
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
            return;
        }
        throw xae;
    }
    try {
        if (tx == null)
            throw new XAException(XAException.XAER_INVAL);
        if (tx.activated()) {
            tx.doRollback();
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        } else
            throw new XAException(XAException.XA_RETRY);
    } catch (XAException ex) {
        if (ex.errorCode != XAException.XA_RETRY) {
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        }
        throw ex;
    } catch (final HeuristicRollbackException ex) {
        XAException xaException = new XAException(XAException.XA_HEURRB);
        xaException.initCause(ex);
        throw xaException;
    } catch (HeuristicCommitException ex) {
        XAException xaException = new XAException(XAException.XA_HEURCOM);
        xaException.initCause(ex);
        throw xaException;
    } catch (HeuristicMixedException ex) {
        XAException xaException = new XAException(XAException.XA_HEURMIX);
        xaException.initCause(ex);
        throw xaException;
    } catch (final IllegalStateException ex) {
        SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        XAException xaException = new XAException(XAException.XAER_NOTA);
        xaException.initCause(ex);
        throw xaException;
    } catch (SystemException ex) {
        SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        throw new XAException(XAException.XAER_RMERR);
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicCommitException(javax.transaction.HeuristicCommitException)

Aggregations

HeuristicCommitException (javax.transaction.HeuristicCommitException)6 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)6 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)4 SystemException (javax.transaction.SystemException)3 XAException (javax.transaction.xa.XAException)3 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)1 IOException (java.io.IOException)1 RollbackException (javax.transaction.RollbackException)1