Overview | Completes the current transaction. |
Original interface | CosTransactions::Current Interface |
Exceptions | HeuristicHazard |
HeuristicMixed | |
NoTransaction | |
NO_PERMISSION standard exception |
Intended Usage
If there is no current transaction, the NoTransaction exception is raised. If the current thread does not have permission to commit the transaction, the standard NO_PERMISSION exception is raised. (The commit operation is restricted to the transaction originator in some circumstances.)
The effect of this operation is equivalent to performing the Terminator::commit 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.
If transactions are rolling back for no apparent reason you may be trying to invoke the commit operation on an object with an active exception.
Syntax
void commit(in boolean report_heuristics) raises (NoTransaction,HeuristicMixed,HeuristicHazard);
Input parameters
Return values
None.
Examples
The following examples demonstrate the usage of CosTransactions::Current::commit.
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 // resource objects 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 // rolled the transaction back because an error was detected. ... } catch (...) { // A general exception has occurred. ... } ...