5.4.3 Step 3: Write the CORBA Client Application

The CORBA client application needs code that performs the following tasks:

  1. Obtains a reference to the TransactionCurrent or TransactionFactory object from the Bootstrap object.
  2. Begins a transaction by invoking the Tobj::TransactionCurrent::begin() operation on the TransactionCurrent object.
  3. Invokes operations on the object. In the Transactions sample application, the CORBA client application invokes the register_for_courses() operation on the Registrar object, passing a list of courses.

The following code snippet illustrates the portion of the CORBA C++ client application in the Transactions sample application that illustrates the development steps for transactions.

CORBA::Object_var var_transaction_current_oref=Bootstrap.resolve_initial_references("TransactionCurrent");
CosTransactions::Current_var var_transaction_current_ref=CosTransactions::Current::_narrow(var_transaction_current_oref.in());
//Begin the transaction
var_transaction_current_ref->begin();

try {
  // Perform the operation inside the transaction
  pointer_Registar_ref->register_for_courses(student_id, course_number_list);
  // ...
  // If operation executes with no errors, commit the transaction:
  CORBA: :Boolean report_heuristics=CORBA_TRUE;
  var_transaction_current_ref->commit(report_heuristics);
}

catch (...) {

  // If the operation has problems executing, rollback the
  // transaction. Then throw the original exception again.
  // If the rollback fails, ignore the exception and throw the
  // original exception again.
  try {
    var_transaction_current_ref->rollback();
  }

  catch (...) {
    TP: :userlog("rollback failed");
  }

  throw;
}