Class TransactionContext
- java.lang.Object
- 
- org.apache.tomcat.dbcp.dbcp2.managed.TransactionContext
 
- 
 public class TransactionContext extends java.lang.ObjectTransactionContext represents the association between a single XAConnectionFactory and a Transaction. This context contains a single shared connection which should be used by all ManagedConnections for the XAConnectionFactory, the ability to listen for the transaction completion event, and a method to check the status of the transaction.- Since:
- 2.0
 
- 
- 
Constructor SummaryConstructors Constructor Description TransactionContext(TransactionRegistry transactionRegistry, Transaction transaction)Provided for backwards compatibilityTransactionContext(TransactionRegistry transactionRegistry, Transaction transaction, TransactionSynchronizationRegistry transactionSynchronizationRegistry)Creates a TransactionContext for the specified Transaction and TransactionRegistry.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTransactionContextListener(TransactionContextListener listener)Adds a listener for transaction completion events.voidcompleteTransaction()Sets the transaction complete flag to true.java.sql.ConnectiongetSharedConnection()Gets the connection shared by all ManagedConnections in the transaction.booleanisActive()True if the transaction is active or marked for rollback only.booleanisTransactionComplete()Gets the transaction complete flag to true.voidsetSharedConnection(java.sql.Connection sharedConnection)Sets the shared connection for this transaction.
 
- 
- 
- 
Constructor Detail- 
TransactionContextpublic TransactionContext(TransactionRegistry transactionRegistry, Transaction transaction) Provided for backwards compatibility- Parameters:
- transactionRegistry- the TransactionRegistry used to obtain the XAResource for the shared connection
- transaction- the transaction
 
 - 
TransactionContextpublic TransactionContext(TransactionRegistry transactionRegistry, Transaction transaction, TransactionSynchronizationRegistry transactionSynchronizationRegistry) Creates a TransactionContext for the specified Transaction and TransactionRegistry. The TransactionRegistry is used to obtain the XAResource for the shared connection when it is enlisted in the transaction.- Parameters:
- transactionRegistry- the TransactionRegistry used to obtain the XAResource for the shared connection
- transaction- the transaction
- transactionSynchronizationRegistry- The optional TSR to register synchronizations with
- Since:
- 2.6.0
 
 
- 
 - 
Method Detail- 
addTransactionContextListenerpublic void addTransactionContextListener(TransactionContextListener listener) throws java.sql.SQLException Adds a listener for transaction completion events.- Parameters:
- listener- the listener to add
- Throws:
- java.sql.SQLException- if a problem occurs adding the listener to the transaction
 
 - 
completeTransactionpublic void completeTransaction() Sets the transaction complete flag to true.- Since:
- 2.4.0
 
 - 
getSharedConnectionpublic java.sql.Connection getSharedConnection() Gets the connection shared by all ManagedConnections in the transaction. Specifically, connection using the same XAConnectionFactory from which the TransactionRegistry was obtained.- Returns:
- the shared connection for this transaction
 
 - 
isActivepublic boolean isActive() throws java.sql.SQLExceptionTrue if the transaction is active or marked for rollback only.- Returns:
- true if the transaction is active or marked for rollback only; false otherwise
- Throws:
- java.sql.SQLException- if a problem occurs obtaining the transaction status
 
 - 
isTransactionCompletepublic boolean isTransactionComplete() Gets the transaction complete flag to true.- Returns:
- The transaction complete flag.
- Since:
- 2.4.0
 
 - 
setSharedConnectionpublic void setSharedConnection(java.sql.Connection sharedConnection) throws java.sql.SQLExceptionSets the shared connection for this transaction. The shared connection is enlisted in the transaction.- Parameters:
- sharedConnection- the shared connection
- Throws:
- java.sql.SQLException- if a shared connection is already set, if XAResource for the connection could not be found in the transaction registry, or if there was a problem enlisting the connection in the transaction
 
 
- 
 
-