Package org.apache.commons.dbcp.managed
Class TransactionContext
- java.lang.Object
-
- org.apache.commons.dbcp.managed.TransactionContext
-
public class TransactionContext extends java.lang.Object
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.- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description private java.sql.Connection
sharedConnection
private java.lang.ref.WeakReference
transactionRef
private TransactionRegistry
transactionRegistry
-
Constructor Summary
Constructors Constructor Description TransactionContext(TransactionRegistry transactionRegistry, javax.transaction.Transaction transaction)
Creates a TransactionContext for the specified Transaction and TransactionRegistry.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTransactionContextListener(TransactionContextListener listener)
Adds a listener for transaction completion events.java.sql.Connection
getSharedConnection()
Gets the connection shared by all ManagedConnections in the transaction.private javax.transaction.Transaction
getTransaction()
boolean
isActive()
True if the transaction is active or marked for rollback only.void
setSharedConnection(java.sql.Connection sharedConnection)
Sets the shared connection for this transaction.
-
-
-
Field Detail
-
transactionRegistry
private final TransactionRegistry transactionRegistry
-
transactionRef
private final java.lang.ref.WeakReference transactionRef
-
sharedConnection
private java.sql.Connection sharedConnection
-
-
Constructor Detail
-
TransactionContext
public TransactionContext(TransactionRegistry transactionRegistry, javax.transaction.Transaction transaction)
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 transaction
-
-
Method Detail
-
getSharedConnection
public 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
-
setSharedConnection
public void setSharedConnection(java.sql.Connection sharedConnection) throws java.sql.SQLException
Sets 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
-
addTransactionContextListener
public 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
-
isActive
public boolean isActive() throws java.sql.SQLException
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:
java.sql.SQLException
- if a problem occurs obtaining the transaction status
-
getTransaction
private javax.transaction.Transaction getTransaction() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-