Search in sources :

Example 1 with InvalidTerminationStateException

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

the class SubordinateTxUnitTest method testTransactionImple.

@Test
public void testTransactionImple() throws Exception {
    TransactionImple tx = new TransactionImple(0);
    TransactionImple dummy = new TransactionImple(0);
    assertFalse(tx.equals(dummy));
    try {
        tx.commit();
        fail();
    } catch (final IllegalStateException ex) {
    }
    try {
        tx.rollback();
        fail();
    } catch (InvalidTerminationStateException ex) {
    }
    assertEquals(tx.doPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    tx.doCommit();
    dummy.doRollback();
    tx = new TransactionImple(10);
    tx.doOnePhaseCommit();
    tx.doForget();
    tx.doBeforeCompletion();
    assertTrue(tx.toString() != null);
    assertTrue(tx.activated());
}
Also used : TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.TransactionImple) InvalidTerminationStateException(com.arjuna.ats.jta.exceptions.InvalidTerminationStateException) Test(org.junit.Test)

Example 2 with InvalidTerminationStateException

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

the class TransactionImpleUnitTest method test.

@Test
public void test() throws Exception {
    OTSImpleManager.current().begin();
    TransactionImple tx = new TransactionImple(new SubordinateAtomicTransaction(new ServerControlWrapper(OTSImpleManager.current().get_control())));
    assertFalse(tx.equals(null));
    assertTrue(tx.equals(tx));
    assertFalse(tx.equals(new TransactionImple(new AtomicTransaction())));
    assertFalse(tx.equals(new Object()));
    assertTrue(tx.toString() != null);
    try {
        tx.commit();
        fail();
    } catch (final InvalidTerminationStateException ex) {
    }
    try {
        tx.rollback();
        fail();
    } catch (final InvalidTerminationStateException ex) {
    }
    tx.doBeforeCompletion();
    tx.doPrepare();
    try {
        tx.doCommit();
        fail();
    } catch (final Throwable ex) {
    }
    try {
        tx.doRollback();
        fail();
    } catch (final Throwable ex) {
    }
    try {
        tx.doOnePhaseCommit();
        fail();
    } catch (final Throwable ex) {
    }
    tx.doForget();
    OTSImpleManager.current().rollback();
    DummyTransactionImple dummy = new DummyTransactionImple(new AtomicTransaction());
    try {
        dummy.commitAndDisassociate();
    } catch (final InactiveTransactionException ex) {
    }
    try {
        dummy.rollbackAndDisassociate();
    } catch (final InactiveTransactionException ex) {
    }
}
Also used : ServerControlWrapper(com.arjuna.ats.internal.jts.interposition.ServerControlWrapper) SubordinateAtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.SubordinateAtomicTransaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.TransactionImple) SubordinateAtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.SubordinateAtomicTransaction) AtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.AtomicTransaction) InvalidTerminationStateException(com.arjuna.ats.jta.exceptions.InvalidTerminationStateException) InactiveTransactionException(com.arjuna.ats.jta.exceptions.InactiveTransactionException) Test(org.junit.Test)

Example 3 with InvalidTerminationStateException

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

the class TransactionImple method doOnePhaseCommit.

public void doOnePhaseCommit() throws IllegalStateException, javax.transaction.HeuristicMixedException, javax.transaction.SystemException, RollbackException {
    try {
        SubordinateAtomicAction subAct = (SubordinateAtomicAction) super._theTransaction;
        if (!endSuspendedRMs())
            _theTransaction.preventCommit();
        int status = subAct.doOnePhaseCommit();
        switch(status) {
            case ActionStatus.COMMITTED:
            case ActionStatus.COMMITTING:
            case ActionStatus.H_COMMIT:
                TransactionImple.removeTransaction(this);
                break;
            case ActionStatus.ABORTED:
            case ActionStatus.ABORTING:
            case ActionStatus.H_ROLLBACK:
                TransactionImple.removeTransaction(this);
                // in which case IllegalState may be a better option?
                throw new RollbackException();
            case ActionStatus.INVALID:
                throw new InvalidTerminationStateException();
            case ActionStatus.H_HAZARD:
            case ActionStatus.H_MIXED:
            default:
                throw new javax.transaction.HeuristicMixedException();
        }
    } catch (ClassCastException ex) {
        ex.printStackTrace();
        UnexpectedConditionException unexpectedConditionException = new UnexpectedConditionException(ex.toString());
        unexpectedConditionException.initCause(ex);
        throw unexpectedConditionException;
    }
}
Also used : InvalidTerminationStateException(com.arjuna.ats.jta.exceptions.InvalidTerminationStateException) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException)

Example 4 with InvalidTerminationStateException

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

the class TransactionImple method rollback.

public void rollback() throws java.lang.IllegalStateException, java.lang.SecurityException, javax.transaction.SystemException {
    if (jtaxLogger.logger.isTraceEnabled()) {
        jtaxLogger.logger.trace("TransactionImple.rollback");
    }
    boolean endSuspendedFailed = false;
    if (_theTransaction != null) {
        try {
            if ((getStatus() != Status.STATUS_ACTIVE) && (getStatus() != Status.STATUS_MARKED_ROLLBACK))
                throw new NoTransaction();
            /*
	                         * Call end on any suspended resources. If this fails, then there's
	                         * not a lot else we can do because the transaction is about to roll
	                         * back anyway!
	                         */
            endSuspendedFailed = !endSuspendedRMs();
            if (endSuspendedFailed) {
                jtaxLogger.i18NLogger.warn_jtax_transaction_jts_endsuspendfailed1();
            }
            _theTransaction.abort();
        } catch (WrongTransaction e1) {
            InactiveTransactionException inactiveTransactionException = new InactiveTransactionException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_wrongstatetx());
            inactiveTransactionException.initCause(e1);
            throw inactiveTransactionException;
        } catch (org.omg.CORBA.NO_PERMISSION e2) {
            throw new SecurityException(e2);
        } catch (INVALID_TRANSACTION e3) {
            InactiveTransactionException inactiveTransactionException = new InactiveTransactionException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_invalidtx2());
            inactiveTransactionException.initCause(e3);
            throw inactiveTransactionException;
        } catch (NoTransaction e4) {
            throw new IllegalStateException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_notx(), e4);
        } catch (org.omg.CORBA.SystemException e5) {
            javax.transaction.SystemException systemException = new javax.transaction.SystemException(e5.toString());
            systemException.initCause(e5);
            throw systemException;
        } finally {
            TransactionImple.removeTransaction(this);
        }
        if (endSuspendedFailed)
            throw new InvalidTerminationStateException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_endsuspendfailed2());
    } else
        throw new IllegalStateException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_inactivetx());
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) InvalidTerminationStateException(com.arjuna.ats.jta.exceptions.InvalidTerminationStateException) WrongTransaction(org.omg.CORBA.WrongTransaction) InactiveTransactionException(com.arjuna.ats.jta.exceptions.InactiveTransactionException)

Aggregations

InvalidTerminationStateException (com.arjuna.ats.jta.exceptions.InvalidTerminationStateException)4 InactiveTransactionException (com.arjuna.ats.jta.exceptions.InactiveTransactionException)2 Test (org.junit.Test)2 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.TransactionImple)1 AtomicTransaction (com.arjuna.ats.internal.jta.transaction.jts.AtomicTransaction)1 SubordinateAtomicTransaction (com.arjuna.ats.internal.jta.transaction.jts.subordinate.SubordinateAtomicTransaction)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.subordinate.TransactionImple)1 ServerControlWrapper (com.arjuna.ats.internal.jts.interposition.ServerControlWrapper)1 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 RollbackException (javax.transaction.RollbackException)1 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)1 WrongTransaction (org.omg.CORBA.WrongTransaction)1 NoTransaction (org.omg.CosTransactions.NoTransaction)1