[Enterprise Extensions only]

Current::commit

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.

IDL Syntax

  void commit(in boolean report_heuristics)
      raises (NoTransaction,HeuristicMixed,HeuristicHazard); 

Input parameters

report_heuristics
Flag indicating whether heuristic reporting is required.

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.
          ...
  }
      ... 

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
          // resource objects 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
          // rolled the transaction back because an error was detected.
 
          ...
  }
  catch (Exception exc)
  {
          // A general exception has occurred.
          ...
  }
      ...