Search in sources :

Example 1 with UnexpectedConditionException

use of com.arjuna.ats.jta.exceptions.UnexpectedConditionException in project narayana by jbosstm.

the class XATerminatorUnitTest method testUnknownTransaction.

@Test
public void testUnknownTransaction() throws Exception {
    XATerminatorImple term = new XATerminatorImple();
    XidImple xid = new XidImple(new Uid());
    try {
        term.beforeCompletion(xid);
        fail();
    } catch (final UnexpectedConditionException ex) {
    }
    try {
        term.prepare(xid);
        fail();
    } catch (final XAException ex) {
    }
    try {
        term.commit(xid, false);
        fail();
    } catch (final XAException ex) {
    }
    try {
        term.rollback(xid);
        fail();
    } catch (final XAException ex) {
    }
    try {
        term.forget(xid);
        fail();
    } catch (final XAException ex) {
    }
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAException(javax.transaction.xa.XAException) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple) Test(org.junit.Test)

Example 2 with UnexpectedConditionException

use of com.arjuna.ats.jta.exceptions.UnexpectedConditionException in project narayana by jbosstm.

the class TransactionImple method doCommit.

public boolean doCommit() throws IllegalStateException, HeuristicMixedException, HeuristicRollbackException, javax.transaction.SystemException {
    try {
        SubordinateAtomicAction subAct = (SubordinateAtomicAction) super._theTransaction;
        int res = subAct.doCommit();
        switch(res) {
            case ActionStatus.COMMITTED:
            case ActionStatus.H_COMMIT:
                TransactionImple.removeTransaction(this);
                break;
            case ActionStatus.COMMITTING:
                TransactionImple.removeTransaction(this);
                return false;
            case ActionStatus.ABORTED:
            case ActionStatus.ABORTING:
                throw new HeuristicRollbackException();
            case ActionStatus.H_ROLLBACK:
                throw new HeuristicRollbackException();
            case ActionStatus.H_HAZARD:
            case ActionStatus.H_MIXED:
                throw new HeuristicMixedException();
            case ActionStatus.INVALID:
                TransactionImple.removeTransaction(this);
                throw new IllegalStateException();
            default:
                // not sure what
                throw new HeuristicMixedException();
        }
    } catch (ClassCastException ex) {
        ex.printStackTrace();
        UnexpectedConditionException unexpectedConditionException = new UnexpectedConditionException(ex.toString());
        unexpectedConditionException.initCause(ex);
        throw unexpectedConditionException;
    }
    return true;
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 3 with UnexpectedConditionException

use of com.arjuna.ats.jta.exceptions.UnexpectedConditionException in project narayana by jbosstm.

the class ExceptionsUnitTest method test.

@Test
public void test() throws Exception {
    InactiveTransactionException ex = new InactiveTransactionException();
    ex = new InactiveTransactionException("foobar");
    NotImplementedException exp = new NotImplementedException();
    exp = new NotImplementedException("foobar");
    exp = new NotImplementedException("foobar", new NullPointerException());
    exp = new NotImplementedException(new NullPointerException());
    RollbackException exp2 = new RollbackException();
    exp2 = new RollbackException("foobar");
    exp2 = new RollbackException("foobar", new NullPointerException());
    exp2 = new RollbackException(new NullPointerException());
    UnexpectedConditionException ex2 = new UnexpectedConditionException();
    ex2 = new UnexpectedConditionException("foobar");
}
Also used : NotImplementedException(com.arjuna.ats.jta.exceptions.NotImplementedException) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(com.arjuna.ats.jta.exceptions.RollbackException) InactiveTransactionException(com.arjuna.ats.jta.exceptions.InactiveTransactionException) Test(org.junit.Test)

Example 4 with UnexpectedConditionException

use of com.arjuna.ats.jta.exceptions.UnexpectedConditionException 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 5 with UnexpectedConditionException

use of com.arjuna.ats.jta.exceptions.UnexpectedConditionException 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)

Aggregations

UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)5 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)5 HeuristicCommitException (javax.transaction.HeuristicCommitException)3 Test (org.junit.Test)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple)1 InactiveTransactionException (com.arjuna.ats.jta.exceptions.InactiveTransactionException)1 InvalidTerminationStateException (com.arjuna.ats.jta.exceptions.InvalidTerminationStateException)1 NotImplementedException (com.arjuna.ats.jta.exceptions.NotImplementedException)1 RollbackException (com.arjuna.ats.jta.exceptions.RollbackException)1 XidImple (com.arjuna.ats.jta.xa.XidImple)1 RollbackException (javax.transaction.RollbackException)1 XAException (javax.transaction.xa.XAException)1