This topic provides the information that programmers need to write transactional CORBA applications for the Oracle Tuxedo system. Before you begin, you should read Chapter 1, “Introducing Transactions.”Oracle Tuxedo provides a Transaction Service that supports transactions in CORBA applications. The Transaction Service provides an implementation of the CORBA Services Transaction Service that is described in the OMG CORBA Services Transaction Service Specification. This specification defines the interfaces for an object service that provides transactional functions.A lightweight client runs on a single-user, unmanaged desktop system that has irregular availability. Owners may turn their desktop systems off when they are not in use. These single-user, unmanaged desktop systems should not be required to perform network functions such as transaction coordination. In particular, unmanaged systems should not be responsible for ensuring atomicity, consistency, isolation, and durability (ACID) properties across failures for transactions involving server resources. Oracle Tuxedo CORBA remote clients are lightweight clients.For CORBA applications, the OMG CORBA Services Transaction Service specification states that a client can choose to propagate a transaction context either implicitly or explicitly. Oracle Tuxedo provides implicit propagation. Explicit propagation is strongly discouraged.Objects that are related to transaction contexts that are passed around using explicit transaction propagation should not be mixed with implicit transaction propagation APIs. It should be noted, however, that explicit propagation does not place any constraints on when transactional methods can be processed. There is no guarantee that all transactional methods will be completed before the transaction is committed.Checked transaction behavior provides transaction integrity by guaranteeing that a commit will not succeed unless all transactional objects involved in the transaction have completed the processing of their transactional requests. If implicit transaction propagation is used, the Transaction Service provides checked transaction behavior that is equivalent to that provided by the request/response interprocess communication models defined by The Open Group. For CORBA applications, for example, the Transaction Service performs reply checks, commit checks, and resume checks, as described in the OMG CORBA Services Transaction Service Specification.Unchecked transaction behavior relies completely on the application to provide transaction integrity. If explicit propagation is used, the Transaction Service does not provide checked transaction behavior and transaction integrity is not guaranteed.Oracle Tuxedo CORBA allows transactions to be terminated only by the client that created the transaction.Oracle Tuxedo CORBA supports remote clients invoking methods on server objects in different Oracle Tuxedo domains in the same transaction.Remote CORBA clients with multiple connections to the same Oracle Tuxedo domain may make invocations to server objects on these separate connections within the same transaction.In Oracle Tuxedo applications, transactions can span multiple domains as long as factory-based routing is properly configured across multiple domains. To support transactions across multiple domains, you must configure the factory_finder.ini file to identify factory objects that are used in the current (local) domain but that are resident in a different (remote) domain. For more information, see Using the Oracle Tuxedo Domains Component.A client application can have only one active Bootstrap object and TransactionCurrent object within a single domain. Oracle Tuxedo CORBA does not support exporting or importing transactions to or from remote Oracle Tuxedo domains.
• Support for the OSI TP protocol. Open Systems Interconnect Transaction Processing (OSI TP) is the transactional protocol defined by the International Organization for Standardization (ISO). Oracle Tuxedo CORBA does not support interactions with OSI TP transactions.
• Support for the LU 6.2 protocol. Systems Network Architecture (SNA) LU 6.2 is a transactional protocol defined by IBM. Oracle Tuxedo CORBA does not support interactions with LU 6.2 transactions.
• Support for the ODMG standard. ODMG-93 is a standard defined by the Object Database Management Group (ODMG) that describes a portable interface to access Object Database Management Systems. Oracle Tuxedo CORBA does not support interactions with ODMG transactions.
• In Oracle Tuxedo CORBA, a client or a server object cannot invoke methods on an object that is infected with (or participating in) another transaction. The method invocation issued by the client or the server will return an exception.
• For CORBA applications, a server application object using transactions from the Oracle Tuxedo CORBA Transaction Service library requires the TP Framework functionality. For more information about the TP Framework, see “TP Framework” in the CORBA Programming Reference.
• As a result, the objects that were infected by (or participating in) the rolled back transaction get their states cleared by Oracle Tuxedo a little later. Therefore, no other client can infect these objects with a different transaction until Oracle Tuxedo clears the states of these objects. This condition exists for a very short amount of time and is typically not noticeable in a production application. A simple workaround for this race condition is to try the appropriate operation after a short (typically a 1-second) delay.
• In Oracle Tuxedo CORBA applications, clients may not make one-way method invocations within the context of a transaction to server objects having the NEVER, OPTIONAL, or ALWAYS transaction policies.No error or exception will be returned to the client because it is a one-way method invocation. However, the method on the server object will not be executed, and an appropriate error message will be written to the log. Clients may make one-way method invocations within the context of a transaction to server objects with the IGNORE transaction policy. In this case, the method on the server object will be executed, but not in the context of a transaction. For more information about the transaction policies, see “Implementation Configuration File (ICF)” in the CORBA Programming Reference.
1.
2. Invoke the resolve_initial_reference("TransactionCurrent") method on the Bootstrap object. The invocation returns a standard CORBA object pointer. For a description of this Bootstrap object method, see the CORBA Programming Reference.
3. If an application requires only the Transaction Service APIs, it should issue a CosTransactionsCurrent::_narrow() (in C++) on the object pointer returned from step 2 above.If an application requires the Transaction Service APIs with the extensions, it should issue a Tobj::TransactionCurrent::_narrow() (in C++) on the object pointer returned from step 2 above.Oracle Tuxedo also supports the use of the CORBA Interoperable Naming Service (INS) by third-party clients to obtain initial transaction object references. INS uses the ORB::resolve_initial_references() operation.Listing 2‑1 shows an example of how a client application, using INS, gets an object reference to the TransactionFactory object. For a complete code example, see the client application in the University Sample.For more information about using the ORB::resolve_initial_references() operation, see “CORBA Bootstrapping Programming Reference” in the CORBA Programming Reference.These sections describe the CORBA-based components of the CosTransactions modules that Oracle Tuxedo implements to support the Transaction Service. For more information about these components, see the OMG CORBA Services Transaction Service Specification, Version 1.1, May 2000.Listing 2‑2 shows the supported data types.Listing 2‑2 Data Types Supported by the Transaction Serviceenum Status {
StatusActive,
StatusMarkedRollback,
StatusPrepared,
StatusCommitted,
StatusRolledBack,
StatusUnknown,
StatusNoTransaction,
StatusPreparing,
StatusCommitting,
StatusRollingBack
};
// This information comes from the OMG Transaction Service
// Specification, Version 1.1, May 2000. Used with permission
// of the OMG.Listing 2‑3 shows the supported exceptions in IDL code.Listing 2‑3 Exceptions Supported by the Transaction ServiceTable 2‑1 describes the exceptions.
Note: This information comes from the OMG CORBA Services Transaction Service Specification, Version 1.1, May 2000. Used with permission of the OMG.
A request raises this exception to report that a heuristic decision was made, that the disposition of all relevant updates is not known, and that for those updates whose disposition is known, either all have been committed or all have been rolled back. Therefore, the HeuristicMixed exception takes priority over the HeuristicHazard exception. This exception is raised for the Current interface begin method if the client already has an associated transaction. This exception is raised for the Current interface rollback and rollback_only methods if there is no transaction associated with the client application. This exception is raised for the Current interface resume method if the parameter is not valid in the current execution environment. This exception is raised for the Control interface get_terminator and get_coordinator methods if the Control interface cannot provide the requested object.The Current interface defines methods that allow a client of the Transaction Service to explicitly manage the association between threads and transactions. The Current interface also defines methods that simplify the use of the Transaction Service for most applications. These methods can be used to begin and end transactions, to suspend and resume transactions, and to obtain information about the current transaction.Listing 2‑4 Current Interface IDL};
// This information comes from the OMG Transaction Service
// Specification, Version 1.1, May 2000. Used with permission
// of the OMG.Table 2‑2 provides a description of the Current transaction methods.
Note: This information was taken from the OMG CORBA Services Transaction Service Specification, Version 1.1, May 2000. Used with permission of the OMG.
Creates a new transaction. The transaction context of the client application is modified so that the thread is associated with the new transaction. If the client application is currently associated with a transaction, the SubtransactionsUnavailable exception is raised. If the client application cannot be placed in transaction mode due to an error while starting the transaction, the standard system exception INVALID_TRANSACTION is raised. If the call was made in an improper context, the standard system exception BAD_INV_ORDER is raised. If there is no transaction associated with the client application, the NoTransaction exception is raised.If the call was made in an improper context, the standard system exception BAD_INV_ORDER is raised.If the system decides to roll back the transaction, the standard exception TRANSACTION_ROLLEDBACK is raised and the thread’s transaction context is set to NULL.A HeuristicMixed exception is raised to report that a heuristic decision was made and that some relevant updates have been committed and others have been rolled back. A HeuristicHazard exception is raised to report that a heuristic decision was made, and that the disposition of all relevant updates is not known; for those updates whose disposition is known, either all have been committed or all have been rolled back. The HeuristicMixed exception takes priority over the HeuristicHazard exception. If a heuristic exception is raised or the operation completes normally, the thread’s transaction exception context is set to NULL. If there is no transaction associated with the client application, the NoTransaction exception is raised.If the call was made in an improper context, the standard system exception BAD_INV_ORDER is raised. If there is no transaction associated with the client application, the NoTransaction exception is raised. Otherwise, the transaction associated with the client application is modified so that the only possible outcome is to roll back the transaction. If there is no transaction associated with the client application, the StatusNoTransaction value is returned. Otherwise, this method returns the status of the transaction associated with the client application. If there is no transaction associated with the client application, an empty string is returned. Otherwise, this method returns a printable string describing the transaction (specifically, the XID as specified by The Open Group). The returned string is intended to support debugging. The initial transaction timeout value is 300 seconds. Calling set_timeout() with an argument value larger than zero specifies a new timeout value. Calling set_timeout() with a zero argument sets the timeout value back to the default of 300 seconds.After calling set_timeout(), transactions created by subsequent invocations of begin are subject to being rolled back if they do not complete before the specified number of seconds after their creation.
Note: The initial transaction timeout value is 300 seconds. If a transaction is started via AUTOTRAN instead of the begin method, then the timeout value is determined by the TRANTIME value in the Oracle Tuxedo configuration file. For more information, see Chapter 5, “Administering Transactions.” If the client is not associated with a transaction, a NULL object reference is returned. Otherwise, a Control object is returned that represents the transaction context currently associated with the client application. This object may be given to the resume method to reestablish this context. If the client application is not associated with a transaction, a NULL object reference is returned.If the associated transaction is in a state such that the only possible outcome of the transaction is to be rolled back, the standard system exception TRANSACTION_ROLLEDBACK is raised and the client application becomes associated with no transaction.If the call was made in an improper context, the standard system exception BAD_INV_ORDER is raised. The caller's state with respect to the transaction is not changed.Otherwise, an object is returned that represents the transaction context currently associated with the client application. The same client can subsequently give this object to the resume method to reestablish this context. In addition, the client application becomes associated with no transaction.
Note: As defined in The Common Object Request Broker: Architecture and Specification, Revision 2.4, the standard system exception TRANSACTION_ROLLEDBACK indicates that the transaction associated with the request has already been rolled back or has been marked to roll back. Thus, the requested method either could not be performed or was not performed because further computation on behalf of the transaction would be fruitless. If the client application is already associated with a transaction which is in a state such that the only possible outcome of the transaction is to be rolled back, the standard system exception TRANSACTION_ROLLEDBACK is raised and the client application becomes associated with no transaction.If the call was made in an improper context, the standard system exception BAD_INV_ORDER is raised.If the system is unable to resume the global transaction because the caller is currently participating in work outside any global transaction with one or more resource managers, the standard system exception INVALID_TRANSACTION is raised.If the parameter is a NULL object reference, the client application becomes associated with no transaction. If the parameter is valid in the current execution environment, the client application becomes associated with that transaction (in place of any previous transaction). Otherwise, the InvalidControl exception is raised.
Note: The Control interface allows a program to explicitly manage or propagate a transaction context. An object that supports the Control interface is implicitly associated with one specific transaction.Listing 2‑5 Control Interfaceinterface Control {
Terminator get_terminator()
raises(Unavailable);
Coordinator get_coordinator()
raises(Unavailable);
};
// This information comes from the OMG Transaction Service
// Specification, Version 1.1, May 2000. Used with permission
// of the OMG.Listing 2‑6 shows the Terminator interface.Listing 2‑6 Terminator Interfaceinterface Terminator {
void commit(in boolean report_heuristics)
raises(
HeuristicMixed,
HeuristicHazard
);
void rollback();
};
// This information was taken from the OMG Transaction Service
// Specification, Version 1.1, May 2000. Used with permission
// of the OMG.Table 2‑3 describes the Terminator interface methods.
Table 2‑3 Termination Interface Methods If the transaction has not been marked rollback only, and all of the participants in the transaction agree to commit, the transaction is committed and the operation terminates normally. Otherwise, the transaction is rolled back (as described below for the rollback method) and the TRANSACTION_ROLLEDBACK standard exception is raised.If the report_heuristics parameter is true, the Transaction Service will report inconsistent or possibly inconsistent outcomes using the HeuristicMixed and HeuristicHazard exceptions. A Transaction Service implementation may optionally use the CORBA Notification Service to report heuristic decisions.The commit operation may roll back the transaction if there are subtransactions of the transaction that have not themselves been committed or rolled back or if there are existing or potential activities associated with the transaction that have not completed. The nature and extent of such error checking is implementation-dependent. When a top-level transaction is committed, all changes to recoverable objects made in the scope of this transaction are made permanent and visible to other transactions or clients. When a subtransaction is committed, the changes are made visible to other related transactions as appropriate to the degree of isolation enforced by the resources. In Oracle Tuxedo release 8.0 and later, the CosTransactions::TransactionalObject is no longer used by an object to indicate that it is transactional. If an interface inherits from a TransactionalObject and the ICF indicates a different transaction policy, a warning is issued. The TransactionalObject is not used for any other purpose. For details on transaction policies that need to be set to infect objects with transactions, see “Implementation Configuration File (ICF)” in the CORBA Programming Reference.The CosTransactions module defines the TransactionalObject interface (shown in Listing 2‑7). This interface defines no methods; it is simply a marker.Listing 2‑7 TransactionalObject Interfaceinterface TransactionalObject {
};
// This information was taken from the OMG Transaction Service
// Specification, Version 1.1, May 2000. Used with permission
// of the OMG.The TransactionFactory interface is provided to allow the transaction originator to begin a transaction. This interface defines two operations, create and recreate, which create a new representation of a top-level transaction. A TransactionFactory is located using the FactoryFinder interface of the life cycle service and not by the resolve_initial_reference() operation on the ORB interface.Listing 2‑8 shows the TransactionFactory interface.
Note: Listing 2‑8 TransactionFactory Interfaceinterface TransactionFactory {
Control create(in unsigned long time_out);
Control recreate(in PropagationContext ctx);
};
// This information was taken from the OMG Transaction Service
// Specification, Version 1.1, May 2000. Used with permission
// of the OMG.Table 2‑4 describes the TransactionFactory interface methods.
Table 2‑4 TransactionFactory Interface Methods A new top-level transaction is created and a Control object is returned. The Control object can be used to manage or to control participation in the new transaction. An implementation of the Transaction Service may restrict the ability for the Control object to be transmitted to or used in other execution environments; at a minimum, it can be used by the client application.If the parameter has a nonzero value n, then the new transaction will be subject to being rolled back if it does not complete before n seconds have elapsed. If the parameter is zero, then no application specified timeout is established. All other CORBAservices Object Transaction Service interfaces are not supported. Note that the Current interface described earlier is supported only if it has been obtained from the Bootstrap object. The Control interface described earlier is supported only if it has been obtained using the get_control and the suspend methods on the Current object.This interface supports all the methods of the Current interface in the CosTransactions module and is described in “C++ Bootstrap Object Programming Reference” in the CORBA Programming Reference. Additionally, this interface supports APIs to open and close the resource manager.Listing 2‑9 TransactionCurrent InterfaceInterface TransactionCurrent: CosTransactions::Current {
void open_xa_rm()
raises(RMfailed);
void close_xa_rm()
raises(Rmfailed);
}Table 2‑5 describes APIs that are specific to the resource manager. For more information about these APIs, see the CORBA Programming Reference.
This method opens The Open Group resource manager to which this process is linked. A RMfailed exception is raised if there is a failure while opening the resource manager. This method closes The Open Group resource manager to which this process is linked. An RMfailed exception is raised if there is a failure while closing the resource manager. A BAD_INV_ORDER standard system exception is raised if the function was called in an improper context (for example, the caller is in transaction mode).
• For transaction-bound objects, consider doing all state handling in the Tobj_ServantBase::deactivate_object() operation. This makes it easier for the object to handle its state properly, because the outcome of the transaction is known at the time that deactivate_object() is invoked.
• Assign the optional transaction policy.
• If an object with the always transaction policy is involved in a transaction that is started by the Oracle Tuxedo system, and not the client application, note the following:
• If the server application marks the transaction for rollback only and the server does not throw a CORBA exception, the client application receives the OBJ_ADAPTER exception. In this case, the Oracle Tuxedo system automatically rolls back the transaction. However, the client application is completely unaware that a transaction has been scoped in the Oracle Tuxedo domain.
• If the server does not throw a CORBA exception, the client application receives the TRANSACTION_ROLLEDBACK exception.Table 2‑6 describes the methods in the UserTransaction object.
Table 2‑6 Methods in the UserTransaction Object Returns the transaction status, or STATUS_NO_TRANSACTION if no transaction is associated with the current thread. Specifies the timeout value for the transactions started by the current thread with the begin method. If an application has not called the begin method, then the Transaction Service uses a default value for the transaction timeout.Table 2‑7 describes exceptions thrown by methods of the UserTransaction object.