Search in sources :

Example 16 with NoTransaction

use of org.omg.CosTransactions.NoTransaction in project narayana by jbosstm.

the class Test12 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        boolean correct = true;
        Current current = OTS.get_current();
        current.begin();
        current.commit(false);
        try {
            current.rollback_only();
            correct = false;
        } catch (NoTransaction noTransaction) {
        }
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Test12.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Test12.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) Current(org.omg.CosTransactions.Current)

Example 17 with NoTransaction

use of org.omg.CosTransactions.NoTransaction 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 18 with NoTransaction

use of org.omg.CosTransactions.NoTransaction in project narayana by jbosstm.

the class CurrentImple method commit.

/**
 * It's not possible to commit/abort out of order using the current
 * interface.
 *
 * Do we delete the control if the transaction gives an heuristic result?
 * CurrentImplely we do.
 *
 * If another thread has already terminated the transaction then: (i) if it
 * committed, we do nothing - could throw TransactionRequired of
 * INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
 * it would be better to distinguish between the situation where the
 * transaction has already been terminated and there really is no
 * transaction for this thread. (ii) if it rolledback, we throw
 * TRANSACTION_ROLLEDBACK.
 */
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::commit ( " + report_heuristics + " )");
    }
    ControlWrapper currentAction = _theManager.current();
    if (currentAction != null) {
        try {
            ThreadAssociationControl.updateAssociation(currentAction, TX_COMMITTED);
        } catch (Exception e) {
            /*
				 * An error happened, so mark the transaction as rollback only
				 * (in case it hasn't already been so marked.)
				 */
            rollback_only();
        }
        try {
            currentAction.commit(report_heuristics);
            _theManager.popAction();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            /*
				 * Is ok to destroy transaction. Different for heuristics.
				 */
            _theManager.popAction();
            throw e1;
        } catch (HeuristicMixed e2) {
            _theManager.popAction();
            if (report_heuristics)
                throw e2;
        } catch (HeuristicHazard e3) {
            _theManager.popAction();
            if (report_heuristics)
                throw e3;
        } catch (SystemException e4) {
            _theManager.popAction();
            throw e4;
        } catch (Unavailable e5) {
            /*
				 * If terminated by some other thread then the reference we have
				 * will no longer be valid.
				 */
            _theManager.popAction();
            throw new INVALID_TRANSACTION();
        }
    } else
        throw new NoTransaction();
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Example 19 with NoTransaction

use of org.omg.CosTransactions.NoTransaction in project narayana by jbosstm.

the class TransactionFactoryImple method unresolvedTransactions.

private final org.omg.CosTransactions.otid_t[] unresolvedTransactions() throws Inactive, NoTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("TransactionFactoryImple::terminatedTransactions ()");
    }
    InputObjectState uids = new InputObjectState();
    if (!TxStoreLog.getTransactions(uids, StateStatus.OS_COMMITTED_HIDDEN)) {
        throw new NoTransaction();
    } else {
        Uid theUid = null;
        int count = 0;
        boolean finished = false;
        while (!finished) {
            try {
                theUid = UidHelper.unpackFrom(uids);
                if (theUid.equals(Uid.nullUid()))
                    finished = true;
                else
                    count++;
            } catch (Exception e) {
                finished = true;
            }
        }
        org.omg.CosTransactions.otid_t[] ids = new org.omg.CosTransactions.otid_t[count];
        uids.reread();
        for (int i = 0; i < count; i++) {
            try {
                theUid = UidHelper.unpackFrom(uids);
                ids[i] = Utility.uidToOtid(theUid.stringForm());
            } catch (Exception e) {
            }
        }
        return ids;
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) CosTransactions.otid_t(org.omg.CosTransactions.otid_t) SystemException(org.omg.CORBA.SystemException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 20 with NoTransaction

use of org.omg.CosTransactions.NoTransaction in project narayana by jbosstm.

the class CurrentImple method rollback.

/**
 * If another thread has already terminated the transaction then: (i) if it
 * rolled back, we do nothing - could throw TransactionRequired of
 * INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
 * it would be better to distinguish between the situation where the
 * transaction has already been terminated and there really is no
 * transaction for this thread. (ii) if it committed, we throw
 * INVALID_TRANSACTION.
 */
public void rollback() throws NoTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::rollback ()");
    }
    ControlWrapper currentAction = _theManager.current();
    if (currentAction != null) {
        ThreadAssociationControl.updateAssociation(currentAction, TX_ABORTED);
        try {
            currentAction.rollback();
            _theManager.popAction();
        } catch (INVALID_TRANSACTION e1) {
            /*
				 * If transaction has already terminated, then throw
				 * INVALID_TRANSACTION. Differentiates between this stat and not
				 * actually having a transaction associated with the thread.
				 */
            _theManager.popAction();
            throw e1;
        } catch (SystemException e2) {
            _theManager.popAction();
            throw e2;
        } catch (Unavailable e) {
            /*
				 * If no terminator then not allowed!
				 */
            _theManager.popAction();
            throw new INVALID_TRANSACTION();
        }
    } else
        throw new NoTransaction();
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Aggregations

NoTransaction (org.omg.CosTransactions.NoTransaction)32 Current (org.omg.CosTransactions.Current)17 SystemException (org.omg.CORBA.SystemException)9 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)5 CosTransactions.otid_t (org.omg.CosTransactions.otid_t)5 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)4 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)4 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)4 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)4 Inactive (org.omg.CosTransactions.Inactive)4 BAD_PARAM (org.omg.CORBA.BAD_PARAM)3 WrongTransaction (org.omg.CORBA.WrongTransaction)3 Unavailable (org.omg.CosTransactions.Unavailable)3 GlobalTransactionInfo (com.arjuna.ArjunaOTS.GlobalTransactionInfo)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)2 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)2 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2 Test (org.junit.Test)2 UserException (org.omg.CORBA.UserException)2