Class TransactionManagerImpl
- java.lang.Object
-
- org.apache.geronimo.transaction.manager.TransactionManagerImpl
-
- All Implemented Interfaces:
java.util.EventListener
,javax.transaction.TransactionManager
,javax.transaction.TransactionSynchronizationRegistry
,javax.transaction.UserTransaction
,MonitorableTransactionManager
,RecoverableTransactionManager
,XidImporter
- Direct Known Subclasses:
GeronimoTransactionManager
public class TransactionManagerImpl extends java.lang.Object implements javax.transaction.TransactionManager, javax.transaction.UserTransaction, javax.transaction.TransactionSynchronizationRegistry, XidImporter, MonitorableTransactionManager, RecoverableTransactionManager
Simple implementation of a transaction manager.
-
-
Constructor Summary
Constructors Constructor Description TransactionManagerImpl()
TransactionManagerImpl(int defaultTransactionTimeoutSeconds)
TransactionManagerImpl(int defaultTransactionTimeoutSeconds, TransactionLog transactionLog)
TransactionManagerImpl(int defaultTransactionTimeoutSeconds, XidFactory xidFactory, TransactionLog transactionLog)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTransactionAssociationListener(TransactionManagerMonitor listener)
void
begin()
Create a new transaction and associate it with the current thread.javax.transaction.Transaction
begin(long transactionTimeoutMilliseconds)
void
commit()
Complete the transaction associated with the current thread.void
commit(javax.transaction.Transaction tx, boolean onePhase)
void
forget(javax.transaction.Transaction tx)
long
getActiveCount()
Returns the number of active transactions.java.util.Map<javax.transaction.xa.Xid,TransactionImpl>
getExternalXids()
java.lang.Object
getResource(java.lang.Object key)
Get an object from the Map of resources being managed for the transaction bound to the current thread at the time this method is called.boolean
getRollbackOnly()
Get the rollbackOnly status of the transaction bound to the current thread at the time this method is called.int
getStatus()
Obtain the status of the transaction associated with the current thread.long
getTotalCommits()
Return the number of total commitslong
getTotalRollbacks()
Returns the number of total rollbacksjavax.transaction.Transaction
getTransaction()
Get the transaction object that represents the transaction context of the calling thread.java.lang.Object
getTransactionKey()
Return an opaque object to represent the transaction bound to the current thread at the time this method is called.int
getTransactionStatus()
Return the status of the transaction bound to the current thread at the time this method is called.javax.transaction.Transaction
importXid(javax.transaction.xa.Xid xid, long transactionTimeoutMilliseconds)
int
prepare(javax.transaction.Transaction tx)
void
putResource(java.lang.Object key, java.lang.Object value)
Add or replace an object in the Map of resources being managed for the transaction bound to the current thread at the time this method is called.void
recoveryError(java.lang.Exception e)
void
registerInterposedSynchronization(javax.transaction.Synchronization synchronization)
jta 1.1 method so the jpa implementations can be told to flush their caches.void
registerNamedXAResourceFactory(NamedXAResourceFactory namedXAResourceFactory)
void
removeTransactionAssociationListener(TransactionManagerMonitor listener)
void
resetStatistics()
Reset statisticsvoid
resume(javax.transaction.Transaction tx)
Resume the transaction context association of the calling thread with the transaction represented by the supplied Transaction object.void
rollback()
Roll back the transaction associated with the current thread.void
rollback(javax.transaction.Transaction tx)
void
setRollbackOnly()
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.void
setTransactionTimeout(int seconds)
Modify the timeout value that is associated with transactions started by the current thread with the begin method.javax.transaction.Transaction
suspend()
Suspend the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended.void
unregisterNamedXAResourceFactory(java.lang.String namedXAResourceFactoryName)
-
-
-
Constructor Detail
-
TransactionManagerImpl
public TransactionManagerImpl() throws javax.transaction.xa.XAException
- Throws:
javax.transaction.xa.XAException
-
TransactionManagerImpl
public TransactionManagerImpl(int defaultTransactionTimeoutSeconds) throws javax.transaction.xa.XAException
- Throws:
javax.transaction.xa.XAException
-
TransactionManagerImpl
public TransactionManagerImpl(int defaultTransactionTimeoutSeconds, TransactionLog transactionLog) throws javax.transaction.xa.XAException
- Throws:
javax.transaction.xa.XAException
-
TransactionManagerImpl
public TransactionManagerImpl(int defaultTransactionTimeoutSeconds, XidFactory xidFactory, TransactionLog transactionLog) throws javax.transaction.xa.XAException
- Throws:
javax.transaction.xa.XAException
-
-
Method Detail
-
getTransaction
public javax.transaction.Transaction getTransaction()
Description copied from interface:javax.transaction.TransactionManager
Get the transaction object that represents the transaction context of the calling thread.- Specified by:
getTransaction
in interfacejavax.transaction.TransactionManager
- Returns:
- the
Transaction
object representing the transaction associated with the calling thread.
-
setTransactionTimeout
public void setTransactionTimeout(int seconds) throws javax.transaction.SystemException
Description copied from interface:javax.transaction.TransactionManager
Modify the timeout value that is associated with transactions started by the current thread with the begin method.If an application has not called this method, the transaction service uses some default value for the transaction timeout.
- Specified by:
setTransactionTimeout
in interfacejavax.transaction.TransactionManager
- Specified by:
setTransactionTimeout
in interfacejavax.transaction.UserTransaction
- Parameters:
seconds
- The value of the timeout in seconds. If the value is zero, the transaction service restores the default value. If the value is negative a SystemException is thrown.- Throws:
javax.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition.
-
getStatus
public int getStatus() throws javax.transaction.SystemException
Description copied from interface:javax.transaction.TransactionManager
Obtain the status of the transaction associated with the current thread.- Specified by:
getStatus
in interfacejavax.transaction.TransactionManager
- Specified by:
getStatus
in interfacejavax.transaction.UserTransaction
- Returns:
- The transaction status. If no transaction is associated with the current thread, this method returns the Status.NoTransaction value.
- Throws:
javax.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition.
-
begin
public void begin() throws javax.transaction.NotSupportedException, javax.transaction.SystemException
Description copied from interface:javax.transaction.TransactionManager
Create a new transaction and associate it with the current thread.- Specified by:
begin
in interfacejavax.transaction.TransactionManager
- Specified by:
begin
in interfacejavax.transaction.UserTransaction
- Throws:
javax.transaction.NotSupportedException
- Thrown if the thread is already associated with a transaction and the Transaction Manager implementation does not support nested transactions.javax.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition.
-
begin
public javax.transaction.Transaction begin(long transactionTimeoutMilliseconds) throws javax.transaction.NotSupportedException, javax.transaction.SystemException
- Throws:
javax.transaction.NotSupportedException
javax.transaction.SystemException
-
suspend
public javax.transaction.Transaction suspend() throws javax.transaction.SystemException
Description copied from interface:javax.transaction.TransactionManager
Suspend the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended. If the calling thread is not associated with a transaction, the method returns a null object reference. When this method returns, the calling thread is not associated with a transaction.- Specified by:
suspend
in interfacejavax.transaction.TransactionManager
- Returns:
- Transaction object representing the suspended transaction.
- Throws:
javax.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition.
-
resume
public void resume(javax.transaction.Transaction tx) throws java.lang.IllegalStateException, javax.transaction.InvalidTransactionException, javax.transaction.SystemException
Description copied from interface:javax.transaction.TransactionManager
Resume the transaction context association of the calling thread with the transaction represented by the supplied Transaction object. When this method returns, the calling thread is associated with the transaction context specified.- Specified by:
resume
in interfacejavax.transaction.TransactionManager
- Parameters:
tx
- TheTransaction
object that represents the transaction to be resumed.- Throws:
java.lang.IllegalStateException
- Thrown if the thread is already associated with another transaction.javax.transaction.InvalidTransactionException
- Thrown if the parameter transaction object contains an invalid transaction.javax.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition.
-
getResource
public java.lang.Object getResource(java.lang.Object key)
Description copied from interface:javax.transaction.TransactionSynchronizationRegistry
Get an object from the Map of resources being managed for the transaction bound to the current thread at the time this method is called. The key should have been supplied earlier by a call to putResouce in the same transaction. If the key cannot be found in the current resource Map, null is returned. The general contract of this method is that ofMap.get(Object)
for a Map that supports non-null keys and null values. For example, the returned value is null if there is no entry for the parameter key or if the value associated with the key is actually null.- Specified by:
getResource
in interfacejavax.transaction.TransactionSynchronizationRegistry
- Parameters:
key
- the key for the Map entry.- Returns:
- the value associated with the key.
-
getRollbackOnly
public boolean getRollbackOnly()
Description copied from interface:javax.transaction.TransactionSynchronizationRegistry
Get the rollbackOnly status of the transaction bound to the current thread at the time this method is called.- Specified by:
getRollbackOnly
in interfacejavax.transaction.TransactionSynchronizationRegistry
- Returns:
- the rollbackOnly status.
-
getTransactionKey
public java.lang.Object getTransactionKey()
Description copied from interface:javax.transaction.TransactionSynchronizationRegistry
Return an opaque object to represent the transaction bound to the current thread at the time this method is called. This object overrides hashCode and equals to allow its use as the key in a hashMap for use by the caller. If there is no transaction currently active, return null.This object will return the same hashCode and compare equal to all other objects returned by calling this method from any component executing in the same transaction context in the same application server.
The toString method returns a String that might be usable by a human reader to usefully understand the transaction context. The toString result is otherwise not defined. Specifically, there is no forward or backward compatibility guarantee of the results of toString.
The object is not necessarily serializable, and has no defined behavior outside the virtual machine whence it was obtained.
- Specified by:
getTransactionKey
in interfacejavax.transaction.TransactionSynchronizationRegistry
- Returns:
- an opaque object representing the transaction bound to the current thread at the time this method is called.
-
getTransactionStatus
public int getTransactionStatus()
Description copied from interface:javax.transaction.TransactionSynchronizationRegistry
Return the status of the transaction bound to the current thread at the time this method is called. This is the result of executing TransactionManager.getStatus() in the context of the transaction bound to the current thread at the time this method is called.- Specified by:
getTransactionStatus
in interfacejavax.transaction.TransactionSynchronizationRegistry
- Returns:
- the status of the transaction bound to the current thread at the time this method is called.
-
putResource
public void putResource(java.lang.Object key, java.lang.Object value)
Description copied from interface:javax.transaction.TransactionSynchronizationRegistry
Add or replace an object in the Map of resources being managed for the transaction bound to the current thread at the time this method is called. The supplied key should be of an caller- defined class so as not to conflict with other users. The class of the key must guarantee that the hashCode and equals methods are suitable for use as keys in a map. The key and value are not examined or used by the implementation. The general contract of this method is that ofMap.put(Object, Object)
for a Map that supports non-null keys and null values. For example, if there is already an value associated with the key, it is replaced by the value parameter.- Specified by:
putResource
in interfacejavax.transaction.TransactionSynchronizationRegistry
- Parameters:
key
- the key for the Map entry.value
- the value for the Map entry.
-
registerInterposedSynchronization
public void registerInterposedSynchronization(javax.transaction.Synchronization synchronization)
jta 1.1 method so the jpa implementations can be told to flush their caches.- Specified by:
registerInterposedSynchronization
in interfacejavax.transaction.TransactionSynchronizationRegistry
- Parameters:
synchronization
- interposed synchronization
-
setRollbackOnly
public void setRollbackOnly() throws java.lang.IllegalStateException
Description copied from interface:javax.transaction.TransactionManager
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.- Specified by:
setRollbackOnly
in interfacejavax.transaction.TransactionManager
- Specified by:
setRollbackOnly
in interfacejavax.transaction.TransactionSynchronizationRegistry
- Specified by:
setRollbackOnly
in interfacejavax.transaction.UserTransaction
- Throws:
java.lang.IllegalStateException
- Thrown if the current thread is not associated with a transaction.
-
commit
public void commit() throws javax.transaction.HeuristicMixedException, javax.transaction.HeuristicRollbackException, java.lang.IllegalStateException, javax.transaction.RollbackException, java.lang.SecurityException, javax.transaction.SystemException
Description copied from interface:javax.transaction.TransactionManager
Complete the transaction associated with the current thread. When this method completes, the thread is no longer associated with a transaction.- Specified by:
commit
in interfacejavax.transaction.TransactionManager
- Specified by:
commit
in interfacejavax.transaction.UserTransaction
- Throws:
javax.transaction.HeuristicMixedException
- Thrown to indicate that a heuristic decision was made and that some relevant updates have been committed while others have been rolled back.javax.transaction.HeuristicRollbackException
- Thrown to indicate that a heuristic decision was made and that all relevant updates have been rolled back.java.lang.IllegalStateException
- Thrown if the current thread is not associated with a transaction.javax.transaction.RollbackException
- Thrown to indicate that the transaction has been rolled back rather than committed.java.lang.SecurityException
- Thrown to indicate that the thread is not allowed to commit the transaction.javax.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition.
-
rollback
public void rollback() throws java.lang.IllegalStateException, java.lang.SecurityException, javax.transaction.SystemException
Description copied from interface:javax.transaction.TransactionManager
Roll back the transaction associated with the current thread. When this method completes, the thread is no longer associated with a transaction.- Specified by:
rollback
in interfacejavax.transaction.TransactionManager
- Specified by:
rollback
in interfacejavax.transaction.UserTransaction
- Throws:
java.lang.IllegalStateException
- Thrown if the current thread is not associated with a transaction.java.lang.SecurityException
- Thrown to indicate that the thread is not allowed to roll back the transaction.javax.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition.
-
importXid
public javax.transaction.Transaction importXid(javax.transaction.xa.Xid xid, long transactionTimeoutMilliseconds) throws javax.transaction.xa.XAException, javax.transaction.SystemException
- Specified by:
importXid
in interfaceXidImporter
- Throws:
javax.transaction.xa.XAException
javax.transaction.SystemException
-
commit
public void commit(javax.transaction.Transaction tx, boolean onePhase) throws javax.transaction.xa.XAException
- Specified by:
commit
in interfaceXidImporter
- Throws:
javax.transaction.xa.XAException
-
forget
public void forget(javax.transaction.Transaction tx) throws javax.transaction.xa.XAException
- Specified by:
forget
in interfaceXidImporter
- Throws:
javax.transaction.xa.XAException
-
prepare
public int prepare(javax.transaction.Transaction tx) throws javax.transaction.xa.XAException
- Specified by:
prepare
in interfaceXidImporter
- Throws:
javax.transaction.xa.XAException
-
rollback
public void rollback(javax.transaction.Transaction tx) throws javax.transaction.xa.XAException
- Specified by:
rollback
in interfaceXidImporter
- Throws:
javax.transaction.xa.XAException
-
recoveryError
public void recoveryError(java.lang.Exception e)
- Specified by:
recoveryError
in interfaceRecoverableTransactionManager
-
registerNamedXAResourceFactory
public void registerNamedXAResourceFactory(NamedXAResourceFactory namedXAResourceFactory)
- Specified by:
registerNamedXAResourceFactory
in interfaceRecoverableTransactionManager
-
unregisterNamedXAResourceFactory
public void unregisterNamedXAResourceFactory(java.lang.String namedXAResourceFactoryName)
- Specified by:
unregisterNamedXAResourceFactory
in interfaceRecoverableTransactionManager
-
getExternalXids
public java.util.Map<javax.transaction.xa.Xid,TransactionImpl> getExternalXids()
- Specified by:
getExternalXids
in interfaceXidImporter
-
addTransactionAssociationListener
public void addTransactionAssociationListener(TransactionManagerMonitor listener)
- Specified by:
addTransactionAssociationListener
in interfaceMonitorableTransactionManager
-
removeTransactionAssociationListener
public void removeTransactionAssociationListener(TransactionManagerMonitor listener)
- Specified by:
removeTransactionAssociationListener
in interfaceMonitorableTransactionManager
-
getActiveCount
public long getActiveCount()
Returns the number of active transactions.- Returns:
- the count of active transactions
-
getTotalCommits
public long getTotalCommits()
Return the number of total commits- Returns:
- the number of commits since statistics were reset
-
getTotalRollbacks
public long getTotalRollbacks()
Returns the number of total rollbacks- Returns:
- the number of rollbacks since statistics were reset
-
resetStatistics
public void resetStatistics()
Reset statistics
-
-