![]() |
Overview Rolls back the transaction associated with the current thread. Original interface CosTransactions::Current Interface Exceptions NoTransaction NO_PERMISSION standard exception
Intended Usage
If there is no transaction associated with the current thread, the NoTransaction exception is raised. If the current thread does not have permission to rollback the transaction, the standard NO_PERMISSION exception is raised.
The effect of this request is equivalent to performing the rollback Operation in the corresponding Terminator Interface.
The current thread transaction is modified as follows: If the transaction has been begun by a thread (using begin) in the same execution environment, the thread's transaction context is restored to its state prior to the begin request. Otherwise, the thread's transaction context is set to NULL.
IDL Syntax
void rollback() raises(NoTransaction);
Input parameters
None.
Return values
Examples
The following examples demonstrate the usage of CosTransactions::Current::rollback.
C++ Example
#include <CosTransactions.hh> // CosTransactions module ... ::CORBA::Boolean rollback_required = FALSE; ... //Access the CosTransactions::Current object. CORBA::Object_ptr orbCurrentPtr = CBSeriesGlobal::orb()->resolve_initial_references("TransactionCurrent"); CosTransactions::Current_ptr current = CosTransactions::Current::_narrow(orbCurrentPtr); // Invoke the begin operation on the CosTransactions::Current object. current->begin(); // Perform work for the transaction and set rollback_required to TRUE if // an error is detected. ... // Invoke commit or rollback depending on whether rollback_required is // set. This must be called within a try...catch structure as the // transaction service may raise an exception if an error occurs. try { if (rollback_required == TRUE) { current->rollback(); } else // commit required { current->commit(/* report_heuristics = */ TRUE); } } catch (CORBA::TRANSACTION_ROLLEDBACK &exc) { // The application called commit, but the transaction service rolled // the transaction back because an error was detected. ... } catch (CosTransactions::HeuristicMixed &exc) { // The transaction service has reported that some or all of the // resourceobjects have made a heuristic decision. This has // resulted in heuristic damage. ... } catch (CosTransactions::HeuristicHazard &exc) { // The transaction service has reported that not all of the // resource objects could participate properly in determining the // outcome of the transaction. There is a possibility of // heuristic damage. ... } catch (CORBA::UserException &exc) { // Another type of user exception has occurred. ... } catch (CORBA::SystemException &exc) { // The application called commit, but the transaction service // rolledthe transaction back because an error was detected. ... } catch (...) { // A general exception has occurred. ... } ...
Java Example
import org.omg.CosTransactions.*; // CosTransactions module ... org.omg.CORBA.Boolean rollback_required = FALSE; ... //Access the org.omg.CosTransactions.Current object. org.omg.CORBA.Object orbCurrentPtr = com.ibm.CBCUtil.CBSeriesGlobal.orb().resolve_initial_references( "TransactionCurrent"); org.omg.CosTransactions.Current current = org.omg.CosTransactions.CurrentHelper.narrow(orbCurrentPtr); // Invoke the begin operation on the org.omg.CosTransactions.Current object. current.begin(); // Perform work for the transaction and set rollback_required to TRUE if // an error is detected. ... // Invoke commit or rollback depending on whether rollback_required is // set. This must be called within a try...catch structure as the // transaction service may raise an exception if an error occurs. try { if (rollback_required == TRUE) { current.rollback(); } else // commit required { current.commit(/* report_heuristics = */ TRUE); } } catch (org.omg.CORBA.TRANSACTION_ROLLEDBACK exc) { // The application called commit, but the transaction service rolled // the transaction back because an error was detected. ... } catch (org.omg.CosTransactions.HeuristicMixed exc) { // The transaction service has reported that some or all of the // resourceobjects have made a heuristic decision. This has // resulted in heuristic damage. ... } catch (org.omg.CosTransactions.HeuristicHazard exc) { // The transaction service has reported that not all of the // resource objects could participate properly in determining the // outcome of the transaction. There is a possibility of // heuristic damage. ... } catch (org.omg.CORBA.UserException exc) { // Another type of user exception has occurred. ... } catch (org.omg.CORBA.SystemException exc) { // The application called commit, but the transaction service // rolledthe transaction back because an error was detected. ... } catch (Exception exc) { // A general exception has occurred. ... } ...