Tuxedo
0

Using CORBA Transactions

 Previous Next Contents Index View as PDF  

Transactions in CORBA Client Applications

This topic includes the following sections:

This topic describes how to use transactions in CORBA C++, Java, and ActiveX client applications for the BEA Tuxedo CORBA software. Before you begin, you should read Introducing Transactions.

Note: BEA Tuxedo also supports use of the CORBA Interoperable Naming Service (INS) bootstrapping mechanism. For information on INS, see the "CORBA Bootstrapping Programming Reference" in the CORBA Programming Reference. For limitations when using INS, see Support for Third-Party Clients Using INS.

For an example of how transactions are implemented in working client applications, see the The Transaction Sample Application in the BEA Tuxedo online documentation. For an overview of the TransactionCurrent object, see "Client Application Development Concepts" in Creating CORBA Client Applications.

 


Overview of BEA Tuxedo CORBA Transactions

Client applications use transaction processing to ensure that data remains correct, consistent, and persistent. The transactions in the BEA Tuxedo software allow client applications to begin and terminate transactions and to get the status of transactions. The BEA Tuxedo software uses transactions as defined in the CORBA services Object Transaction Service, with extensions for ease of use.

Transactions are defined on interfaces. The application designer decides which interfaces within a BEA Tuxedo client/server application will handle transactions. Transaction policies are defined in the Implementation Configuration File (ICF) for server applications. Generally, the ICF file for the available interfaces is provided to the client programmer by the application designer.

 


Summary of the Development Process for Transactions

To add transactions to a client application, complete the following steps:

The rest of this topic describes these steps using portions of the client applications in the Transactions University sample application. For information about the Transactions University sample application, see The Transactions Sample Application in the BEA Tuxedo online documentation.

The Transactions University sample application is located in the following directory on the BEA Tuxedo software kit:

 


Step 1: Using the Bootstrap Object to Obtain the TransactionCurrent Object

If you are using the BEA Tuxedo CORBA client software, you should use the Bootstrap object to obtain an object reference to the TransactionCurrent object for the specified BEA Tuxedo domain. For more information about the TransactionCurrent object, see "Client Application Development Concepts" in Creating CORBA Client Applications.

Note: If you are using a third-party client ORB, you should the CORBA Interoperable Naming Service (INS) CORBA::ORB::resolve_initial_references operation to obtain an object reference to the FactoryFinder object for the specified BEA Tuxedo domain. For information on how to use INS to get initial object references for transaction clients, see "CORBA Bootstrapping Programming Reference" in the CORBA Programming Reference.

The following C++, Java, and Visual Basic examples illustrate how the Bootstrap object is used to return the TransactionCurrent object.

C++ Example

CORBA::Object_var var_transaction_current_oref =  
Bootstrap.resolve_initial_references("TransactionCurrent");
CosTransactions::Current_var transaction_current_oref=
CosTransactions::Current::_narrow(
var_transaction_current_oref.in());

Java Example

org.omg.CORBA.Object transCurObj =
gBootstrapObjRef.resolve_initial_references(
"TransactionCurrent");
org.omg.CosTransactions.Current gTransCur=
org.omg.CosTransactions.CurrentHelper.narrow(transCurObj);

Visual Basic Example

Set objTransactionCurrent =
objBootstrap.CreateObject("Tobj.TransactionCurrent")

 


Step 2: Using the TransactionCurrent Methods

The TransactionCurrent object has methods that allow a client application to manage transactions. These methods can be used to begin and end transactions and to obtain information about the current transaction.

Note: Alternatively, a CORBA Java client could use the UserTransaction object instead.

Table  4-1 describes the methods in the TransactionCurrent object.

Table 4-1 Methods in the TransactionCurrent Object  

Method

Description

begin

Creates a new transaction. Future operations take place within the scope of this transaction. When a client application begins a transaction, the default transaction timeout is 300 seconds. You can change this default, using the set_timeout method.

commit

Ends the transaction successfully. Indicates that all operations on this client application have completed successfully.

rollback

Forces the transaction to roll back.

rollback_only

Marks the transaction so that the only possible action is to roll back. Generally, this method is used only in server applications.

suspend

Suspends participation in the current transaction. This method returns an object that identifies the transaction and allows the client application to resume the transaction later.

resume

Resumes participation in the specified transaction.

get_status

Returns the status of a transaction with a client application.

get_transaction_name

Returns a printable string describing the transaction.

set_timeout

Modifies the timeout period associated with transactions. The default transaction timeout value is 300 seconds. If a transaction is automatically started instead of explicitly started with the begin method, the timeout value is determined by the value of the TRANTIME parameter in the UBBCONFIG file. For more information about setting the TRANTIME parameter, see Chapter  5, "Administering Transactions."

get_control

Returns a control object that represents the transaction.

A basic transaction works in the following way:

  1. A client application begins a transaction using the Tobj::TransactionCurrent::begin method. This method does not return a value.

  2. The operations on the CORBA interface execute within the scope of a transaction. If a call to any of these operations raises an exception (either explicitly or as a result of a communications failure), the exception can be caught and the transaction can be rolled back.

  3. Use the Tobj::TransactionCurrent::commit method to commit the current transaction. 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.

    The association between the transaction and the client application ends when the client application calls the Tobj::TransactionCurrent:commit method or the Tobj::TransactionCurrent:rollback method.The following C++, Java, and Visual Basic examples illustrate using a transaction to encapsulate the operation of a student registering for a class.

C++ Example

//Begin the transaction
transaction_current_oref->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;
transaction_current_ref->commit(report_heuristics);
}
catch (CORBA::Exception &) {
//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 {
transaction_current_ref->rollback();
}
catch (CORBA::Exception &) {
TP::userlog("rollback failed");

throw;
}

Java Example

try{
gTransCur.begin();
//Perform the operation inside the transaction
not_registered =
gRegistrarObjRef.register_for_courses(student_id,selected_course_numbers);


if (not_registered != null)

//If operation executes with no errors, commit the transaction
boolean report_heuristics = true;
gTransCur.commit(report_heuristics);

} else gTransCur.rollback();


} catch(org.omg.CosTransactions.NoTransaction nte) {
System.err.println("NoTransaction: " + nte);
System.exit(1);
} catch(org.omg.CosTransactions.SubtransactionsUnavailable e) {
System.err.println("Subtransactions Unavailable: " + e);
System.exit(1);
} catch(org.omg.CosTransactions.HeuristicHazard e) {
System.err.println("HeuristicHazard: " + e);
System.exit(1);
} catch(org.omg.CosTransactions.HeuristicMixed e) {
System.err.println("HeuristicMixed: " + e);
System.exit(1);
}

Visual Basic Example

' Begin the transaction
'
objTransactionCurrent.begin
'
' Try to register for courses
'
NotRegisteredList = objRegistrar.register_for_courses(mStudentID,
CourseList, exception)
'
If exception.EX_majorCode = NO_EXCEPTION then
' Request succeeded, commit the transaction
'
Dim report_heuristics As Boolean
report_heuristics = True
objTransactionCurrent.commit report_heuristics
Else
' Request failed, Roll back the transaction
'
objTransactionCurrent.rollback
MsgBox "Transaction Rolled Back"
End If

 

Back to Top Previous Next
Contact e-docsContact BEAwebmasterprivacy