Search in sources :

Example 1 with WrongTransaction

use of org.omg.CORBA.WrongTransaction in project narayana by jbosstm.

the class AtomicTransaction method commit.

/*
	 * Commit the transaction. If the current transaction associated with the
	 * thread is not this transaction, then this transaction is rolled back and
	 * leave current alone.
	 * 
	 * @param report_heuristics indicates whether heuristic reporting is
	 * desired.
	 * 
	 * @exception org.omg.CosTransactions.NoTransaction if the transaction has
	 * already been terminated.
	 * 
	 * @exception org.omg.CORBA.TRANSACTION_ROLLEDBACK if the transaction rolls
	 * back.
	 * 
	 * @exception org.omg.CosTransactions.HeuristicMixed if some of the
	 * transaction participants committed, while some rolled back.
	 * 
	 * @exception org.omg.CosTransactions.HeuristicHazard if some of the
	 * transaction participants committed, some rolled back, and the outcome of
	 * others is indeterminate.
	 * 
	 * @exception org.omg.CORBA.WRONG_TRANSACTION if the current transaction is
	 * not this transaction.
	 */
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, WrongTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("AtomicTransaction::commit ( " + report_heuristics + " ) for " + _theAction);
    }
    synchronized (_theStatus) {
        if (_theAction == null) {
            throw new NoTransaction();
        }
    }
    if (!validTransaction()) {
        throw new WrongTransaction();
    }
    /*
		 * OK to use current since we have just guaranteed that the transaction
		 * is the same as current. Use current rather than saved control since
		 * it will do thread tracking for us.
		 */
    CurrentImple current = OTSImpleManager.current();
    try {
        current.commit(report_heuristics);
        _theStatus = Status.StatusCommitted;
    } catch (NoTransaction e) {
        _theStatus = Status.StatusNoTransaction;
        throw e;
    } catch (HeuristicMixed e) {
        _theStatus = getStatus();
        throw e;
    } catch (HeuristicHazard e) {
        _theStatus = getStatus();
        throw e;
    } catch (TRANSACTION_ROLLEDBACK e) {
        _theStatus = Status.StatusRolledBack;
        throw e;
    } catch (SystemException e) {
        _theStatus = getStatus();
        throw e;
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) WrongTransaction(org.omg.CORBA.WrongTransaction) SystemException(org.omg.CORBA.SystemException) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 2 with WrongTransaction

use of org.omg.CORBA.WrongTransaction in project narayana by jbosstm.

the class AtomicTransaction method rollback.

/*
	 * Rollback the transaction. If the current transaction associated with the
	 * thread is not this transaction, then this transaction is rolled back and
	 * leave current alone.
	 * 
	 * @exception org.omg.CosTransactions.NoTransaction if the transaction has
	 * already been terminated.
	 * 
	 * @exception org.omg.CORBA.WRONG_TRANSACTION if the current transaction is
	 * not this transaction.
	 */
public void rollback() throws NoTransaction, WrongTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("AtomicTransaction::rollback for " + _theAction);
    }
    synchronized (_theStatus) {
        if (_theAction == null) {
            throw new NoTransaction();
        }
    }
    if (!validTransaction()) {
        throw new WrongTransaction();
    }
    /*
		 * OK to use current since we have just guaranteed that the transaction
		 * is the same as current. Use current rather than saved control since
		 * it will do thread tracking for us.
		 */
    CurrentImple current = OTSImpleManager.current();
    try {
        current.rollback();
        _theStatus = Status.StatusRolledBack;
    } catch (NoTransaction e) {
        _theStatus = Status.StatusNoTransaction;
        throw e;
    } catch (TRANSACTION_ROLLEDBACK e) {
        _theStatus = Status.StatusRolledBack;
    } catch (SystemException e) {
        _theStatus = getStatus();
        throw e;
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) WrongTransaction(org.omg.CORBA.WrongTransaction) SystemException(org.omg.CORBA.SystemException) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK)

Example 3 with WrongTransaction

use of org.omg.CORBA.WrongTransaction 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)

Example 4 with WrongTransaction

use of org.omg.CORBA.WrongTransaction in project narayana by jbosstm.

the class SubordinateTxUnitTest method testAtomicTransaction.

@Test
public void testAtomicTransaction() throws Exception {
    XidImple xid = new XidImple(new Uid());
    SubordinateAtomicTransaction saa1 = new SubordinateAtomicTransaction(new Uid());
    SubordinateAtomicTransaction saa2 = new SubordinateAtomicTransaction(new Uid(), xid, 0);
    assertEquals(saa2.getXid(), xid);
    try {
        saa2.end(true);
        fail();
    } catch (final WrongTransaction ex) {
    }
    try {
        saa2.abort();
        fail();
    } catch (final WrongTransaction ex) {
    }
    DummySubordinateAtomicTransaction dsat = new DummySubordinateAtomicTransaction();
    assertFalse(dsat.checkForCurrent());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) SubordinateAtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction) WrongTransaction(org.omg.CORBA.WrongTransaction) Test(org.junit.Test)

Aggregations

WrongTransaction (org.omg.CORBA.WrongTransaction)4 NoTransaction (org.omg.CosTransactions.NoTransaction)3 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)2 SystemException (org.omg.CORBA.SystemException)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 SubordinateAtomicTransaction (com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction)1 InactiveTransactionException (com.arjuna.ats.jta.exceptions.InactiveTransactionException)1 InvalidTerminationStateException (com.arjuna.ats.jta.exceptions.InvalidTerminationStateException)1 XidImple (com.arjuna.ats.jta.xa.XidImple)1 Test (org.junit.Test)1 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)1 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)1 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)1