5.4.3 ステップ3: CORBAクライアント・アプリケーションの記述
CORBAクライアント・アプリケーションでは、次のタスクを実行するコードが必要です:
- BootstrapオブジェクトからTransactionCurrentオブジェクトまたはTransactionFactoryオブジェクトのリファレンスを取得します。
- TransactionCurrentオブジェクトの
Tobj::TransactionCurrent::begin()操作を呼び出してトランザクションを開始します。 - オブジェクトの操作を呼び出します。Transactionsサンプル・アプリケーションでは、CORBAクライアント・アプリケーションが(コースのリストを渡して)
Registrarオブジェクトのregister_for_courses()操作を呼び出します。
次のコード・スニペットは、トランザクションの開発ステップを示すTransactionsサンプル・アプリケーションのCORBA C++クライアント・アプリケーションの部分です。
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;
}親トピック: 開発ステップ