Package org.apache.commons.dbcp2.managed
Class TransactionContext
java.lang.Object
org.apache.commons.dbcp2.managed.TransactionContext
TransactionContext 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Connectionprivate booleanprivate final WeakReference<jakarta.transaction.Transaction> private final TransactionRegistryprivate final jakarta.transaction.TransactionSynchronizationRegistry -
Constructor Summary
ConstructorsConstructorDescriptionTransactionContext(TransactionRegistry transactionRegistry, jakarta.transaction.Transaction transaction) Provided for backwards compatibilityTransactionContext(TransactionRegistry transactionRegistry, jakarta.transaction.Transaction transaction, jakarta.transaction.TransactionSynchronizationRegistry transactionSynchronizationRegistry) Creates a TransactionContext for the specified Transaction and TransactionRegistry. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener for transaction completion events.voidSets the transaction complete flag to true.Gets the connection shared by all ManagedConnections in the transaction.private jakarta.transaction.TransactionbooleanisActive()True if the transaction is active or marked for rollback only.booleanGets the transaction complete flag to true.voidsetSharedConnection(Connection sharedConnection) Sets the shared connection for this transaction.
-
Field Details
-
transactionRegistry
-
transactionRef
-
transactionSynchronizationRegistry
private final jakarta.transaction.TransactionSynchronizationRegistry transactionSynchronizationRegistry -
transactionComplete
private boolean transactionComplete
-
-
Constructor Details
-
TransactionContext
public TransactionContext(TransactionRegistry transactionRegistry, jakarta.transaction.Transaction transaction) Provided for backwards compatibility- Parameters:
transactionRegistry- the TransactionRegistry used to obtain the XAResource for the shared connectiontransaction- the transaction
-
TransactionContext
public TransactionContext(TransactionRegistry transactionRegistry, jakarta.transaction.Transaction transaction, jakarta.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 connectiontransaction- the transactiontransactionSynchronizationRegistry- The optional TSR to register synchronizations with- Since:
- 2.6.0
-
-
Method Details
-
addTransactionContextListener
Adds a listener for transaction completion events.- Parameters:
listener- the listener to add- Throws:
SQLException- if a problem occurs adding the listener to the transaction
-
completeTransaction
public void completeTransaction()Sets the transaction complete flag to true.- Since:
- 2.4.0
-
getTransaction
- Throws:
SQLException
-
isActive
True 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:
SQLException- if a problem occurs obtaining the transaction status
-
isTransactionComplete
public boolean isTransactionComplete()Gets the transaction complete flag to true.- Returns:
- The transaction complete flag.
- Since:
- 2.4.0
-