Transaction Manager

Each active transaction is represented by a transaction object, which implements the interface javax.transaction.Transaction. This object keeps track of its own status, indicating if it is active, if it has been committed or rolled back, and so on. The transaction also keeps track of the resources that were enlisted with it, such as JDBC connections. A transaction object lasts for the space of exactly one transaction—when the transaction begins, a new transaction object is created. After the transaction ends, the transaction object is discarded.

A transaction is usually associated with a thread, which is how a transaction appears to be carried along throughout the duration of a request or other sequence of actions. Only one transaction can be associated with a thread at any one time. This leads to the notion of the current transaction, which is the transaction that is currently associated with a thread.

An application server can have many active transactions at once, each associated with a different thread running in the server. A central service, called the Transaction Manager, is responsible for keeping track of all these transactions, and for remembering which transaction is associated with which thread. When a transaction is started, the Transaction Manager associates it with the appropriate thread. When a transaction ends, the Transaction Manager dissociates it from its thread.

The Transaction Manager is implemented through the Java Transaction API (JTA). The JTA includes two main interfaces for managing transactions, javax.transaction.TransactionManager and javax.transaction.UserTransaction.

The TransactionManager interface is intended to be used by the application server, and it provides a full range of methods for managing transactions. It allows transactions to be created, suspended, resumed, committed, and rolled back. It also provides direct access to the javax.transaction.Transaction object, through which synchronizations can be registered and resources can be enlisted.

In Oracle ATG Web Commerce applications, the TransactionManager object is represented by a Nucleus component, /atg/dynamo/transaction/TransactionManager. Depending on what application server you are running, this component is configured in various ways to point to the appropriate TransactionManager implementation. See the ATG Installation and Configuration Guide for information about how the Nucleus TransactionManager component is configured on your application server.

The TransactionManager object keeps track of the transactions running in Oracle ATG Web Commerce applications, and which threads are associated with which transactions. Nucleus components can get a pointer directly to the /atg/dynamo/transaction/TransactionManager component. Oracle ATG Web Commerce also exposes this component to standard J2EE components, such as servlets and EJBs, through the JNDI name dynamo:/atg/dynamo/transaction/TransactionManager. However, it is not a standard practice in J2EE for an application to access the TransactionManager interface directly.

J2EE applications instead use the UserTransaction interface, which provides a subset of the methods in the TransactionManager interface. A UserTransaction object can begin, commit, and rollback transactions, set the rollback-only flag, and examine the status of the current transaction, but it cannot suspend or resume transactions, or directly access a Transaction object. The UserTransaction object is represented in Oracle ATG Web Commerce by the Nucleus component /atg/dynamo/transaction/UserTransaction. This component actually delegates all of its calls to the /atg/dynamo/transaction/TransactionManager component, but limits those calls to the methods that are part of the UserTransaction interface.

The methods of both interfaces always operate in the context of the calling thread. For example, the begin method creates a new Transaction and associates it with the calling thread, or throws an exception if there is already a Transaction associated with the calling thread.