Note: This topic describes using the C++ interface to the CORBA Services Object Transaction service. For a complete description of all the transaction features available in the CORBA environment of the Oracle Tuxedo product and instructions for implementing the transaction features, see Using CORBA Transactions in the Oracle Tuxedo online documentation.The CORBA environment in the Oracle Tuxedo product provides a C++ interface to the Object Transaction Service. The OTS is accessed through the TransactionCurrent environmental object. For information about using the TransactionCurrent environmental object, see Creating CORBA Client Applications in the Oracle Tuxedo online documentation.Figure 5‑1 illustrates how transactions work in a Oracle Tuxedo CORBA application.
2. A client application begins a transaction using the Tobj::TransactionCurrent::begin() method, and issues a request to the CORBA interface through the TP Framework. All operations on the CORBA interface execute within the scope of a transaction.
• If no exceptions occur, the client application commits the current transaction using the Tobj::TransactionCurrent::commit() method. This method ends the transaction and starts the processing of the operation. The transaction is committed only if all of the participants in the transaction agree to commit.
3. The Tobj::TransactionCurrent:commit() method causes the TP Framework to call the Transaction Manager to complete the transaction.
Note:
• If the student exceeds the maximum number of credits the student can take, the CORBA server application returns a TooManyCredits user exception to the CORBA client application. The CORBA client application provides a brief message explaining that the request was rejected. The CORBA client application then rolls back the transaction.Figure 5‑2 illustrates how the Transactions sample application works.Figure 5‑2 Transactions Sample ApplicationThis topic describes the development steps for writing a Oracle Tuxedo CORBA application that includes transactions. Table 5‑1 lists the development steps.
The Transactions sample application is used to demonstrate these development steps. The source files for the Transactions sample application are located in the \samples\corba\university directory of the Oracle Tuxedo software. For information about building and running the Transactions sample application, see Guide to the CORBA University Sample Application in the Oracle Tuxedo online documentation.For the Transactions sample application, you would define in OMG IDL the Registrar interface and the register_for_courses() operation. The register_for_courses() operation has a parameter, NotRegisteredList, which returns to the CORBA client application the list of courses for which registration failed. If the value of NotRegisteredList is empty, the CORBA client application commits the transaction. You also need to define the TooManyCredits user exception.Listing 5‑1 includes the OMG IDL code for the Transactions sample application.Transaction policies are used on a per-interface basis. During design, it is decided which interfaces within a Oracle Tuxedo CORBA application will handle transactions. The transaction policies are listed in the following table.
The interface is not transactional; however, requests made to this interface within a scope of a transaction are allowed. The AUTOTRAN parameter, specified in the UBBCONFIG file for this interface, is ignored. The interface is not transactional. Objects created for this interface can never be involved in a transaction. The Oracle Tuxedo system generates the INVALID_TRANSACTION exception if an interface with this policy is involved in a transaction.
Note: To define transactional properties for a request you can also use the autotran parameter.In the Transactions sample application, the transaction policy of the Registrar interface is set to always.
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.Listing 5‑2 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;
}When using transactions in CORBA server applications, you need to write methods that implement the interface’s operations. In the Transactions sample application, you would write a method implementation for the register_for_courses() operation.If your Oracle Tuxedo CORBA application uses a database, you need to include code in the CORBA server application that opens and closes an XA resource manager. These operations are included in the Server::initialize() and Server::release() operations of the Server object.Listing 5‑3 shows the portion of the code for the Server object in the Transactions sample application that opens and closes the XA resource manager.
Note: For a complete example of a C++ server application that implements transactions, see the Transactions sample application in Using CORBA Transactions in the Oracle Tuxedo online documentation.
• In the SERVERS section specify the transactional group for the CORBA server application and for the application that manages the database.
• In the GROUPS section define the server group. In the OPENINFO and CLOSEINFO parameters of the GROUPS section, include information to open and close the XA resource manager for the database. You obtain this information from the product documentation for your database. Note that the default version of the com.beasys.Tobj.Server.initialize() operation automatically opens the resource manager.
• Include the pathname to the transaction log (TLOG) in the TLOGDEVICE parameter. For more information about the transaction log, see Administering a Oracle Tuxedo Application at Run Time in the Oracle Tuxedo online documentation.Listing 5‑4 includes the portions of the configuration file that define this information for the Transactions sample application.For information about the transaction log and defining parameters in the Configuration file, see Setting Up a Oracle Tuxedo Application in the Oracle Tuxedo online documentation.