|
|
This topic includes the following sections:
This topic describes how to use transactions in CORBA C++, CORBA Java, and ActiveX client applications for the WebLogic Enterprise (WLE) software. Before you begin, you should read Introducing Transactions.
For an example of how transactions are implemented in working client applications, see Chapter 6, "Transactions Sample CORBA C++ XA Application." For an overview of the TransactionCurrent object, see "Client Application Development Concepts" in Creating CORBA Client Applications.
Client applications use transaction processing to ensure that data remains correct, consistent, and persistent. The transactions in the WLE software allow client applications to begin and terminate transactions and to get the status of transactions. The WLE software uses transactions as defined in the CORBAservices Object Transaction Service, with extensions for ease of use.
Transactions are defined on interfaces. The application designer decides which interfaces within a WLE client/server application will handle transactions. Transaction policies are defined in the Implementation Configuration File (ICF) for C++ server applications, or in the Server Description file (XML) for Java server applications. Generally, the ICF file or the Server Description file for the available interfaces is provided to the client programmer by the application designer.
If you prefer, you can use the Transaction application programming interface (API) defined in the javax.transaction
package that is shipped with the WLE (Java) software.
To add transactions to a client application, complete the following steps:
Overview of WLE CORBA Transactions
Summary of the Development Process for Transactions
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 Chapter 6, "Transactions Sample CORBA C++ XA Application."
The Transactions University sample application is located in the following directory on the WLE software kit:
drive:/wledir/samples/corba/university/transactions
Use the Bootstrap
object to obtain an object reference to the TransactionCurrent
object for the specified WLE domain. For more information about the TransactionCurrent
object, see "Client Application Development Concepts" in Creating CORBA Client Applications.
The following C++, Java, and Visual Basic examples illustrate how the Bootstrap
object is used to return the TransactionCurrent
object.
CORBA::Object_var var_transaction_current_oref = org.omg.CORBA.Object transCurObj = Set objTransactionCurrent = 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:
Step 1: Use the Bootstrap Object to Obtain the TransactionCurrent Object
C++ Example
Bootstrap.resolve_initial_references("TransactionCurrent");
CosTransactions::Current_var transaction_current_oref=
CosTransactions::Current::_narrow(
var_transaction_current_oref.in()); Java Example
gBootstrapObjRef.resolve_initial_references(
"TransactionCurrent");
org.omg.CosTransactions.Current gTransCur=
org.omg.CosTransactions.CurrentHelper.narrow(transCurObj); Visual Basic Example
objBootstrap.CreateObject("Tobj.TransactionCurrent")Step 2: Use the TransactionCurrent Methods
A basic transaction works in the following way:
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:
//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;
}
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);
}
' 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
|
Copyright © 1999 BEA Systems, Inc. All rights reserved.
|