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 voidaddTransactionAssociationListener(TransactionManagerMonitor listener)voidbegin()Create a new transaction and associate it with the current thread.javax.transaction.Transactionbegin(long transactionTimeoutMilliseconds)voidcommit()Complete the transaction associated with the current thread.voidcommit(javax.transaction.Transaction tx, boolean onePhase)voidforget(javax.transaction.Transaction tx)longgetActiveCount()Returns the number of active transactions.java.util.Map<javax.transaction.xa.Xid,TransactionImpl>getExternalXids()java.lang.ObjectgetResource(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.booleangetRollbackOnly()Get the rollbackOnly status of the transaction bound to the current thread at the time this method is called.intgetStatus()Obtain the status of the transaction associated with the current thread.longgetTotalCommits()Return the number of total commitslonggetTotalRollbacks()Returns the number of total rollbacksjavax.transaction.TransactiongetTransaction()Get the transaction object that represents the transaction context of the calling thread.java.lang.ObjectgetTransactionKey()Return an opaque object to represent the transaction bound to the current thread at the time this method is called.intgetTransactionStatus()Return the status of the transaction bound to the current thread at the time this method is called.javax.transaction.TransactionimportXid(javax.transaction.xa.Xid xid, long transactionTimeoutMilliseconds)intprepare(javax.transaction.Transaction tx)voidputResource(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.voidrecoveryError(java.lang.Exception e)voidregisterInterposedSynchronization(javax.transaction.Synchronization synchronization)jta 1.1 method so the jpa implementations can be told to flush their caches.voidregisterNamedXAResourceFactory(NamedXAResourceFactory namedXAResourceFactory)voidremoveTransactionAssociationListener(TransactionManagerMonitor listener)voidresetStatistics()Reset statisticsvoidresume(javax.transaction.Transaction tx)Resume the transaction context association of the calling thread with the transaction represented by the supplied Transaction object.voidrollback()Roll back the transaction associated with the current thread.voidrollback(javax.transaction.Transaction tx)voidsetRollbackOnly()Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.voidsetTransactionTimeout(int seconds)Modify the timeout value that is associated with transactions started by the current thread with the begin method.javax.transaction.Transactionsuspend()Suspend the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended.voidunregisterNamedXAResourceFactory(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.TransactionManagerGet the transaction object that represents the transaction context of the calling thread.- Specified by:
 getTransactionin interfacejavax.transaction.TransactionManager- Returns:
 - the 
Transactionobject representing the transaction associated with the calling thread. 
 
- 
setTransactionTimeout
public void setTransactionTimeout(int seconds) throws javax.transaction.SystemExceptionDescription copied from interface:javax.transaction.TransactionManagerModify 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:
 setTransactionTimeoutin interfacejavax.transaction.TransactionManager- Specified by:
 setTransactionTimeoutin 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.SystemExceptionDescription copied from interface:javax.transaction.TransactionManagerObtain the status of the transaction associated with the current thread.- Specified by:
 getStatusin interfacejavax.transaction.TransactionManager- Specified by:
 getStatusin 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.SystemExceptionDescription copied from interface:javax.transaction.TransactionManagerCreate a new transaction and associate it with the current thread.- Specified by:
 beginin interfacejavax.transaction.TransactionManager- Specified by:
 beginin 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.NotSupportedExceptionjavax.transaction.SystemException
 
- 
suspend
public javax.transaction.Transaction suspend() throws javax.transaction.SystemExceptionDescription copied from interface:javax.transaction.TransactionManagerSuspend 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:
 suspendin 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.SystemExceptionDescription copied from interface:javax.transaction.TransactionManagerResume 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:
 resumein interfacejavax.transaction.TransactionManager- Parameters:
 tx- TheTransactionobject 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.TransactionSynchronizationRegistryGet 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:
 getResourcein 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.TransactionSynchronizationRegistryGet the rollbackOnly status of the transaction bound to the current thread at the time this method is called.- Specified by:
 getRollbackOnlyin interfacejavax.transaction.TransactionSynchronizationRegistry- Returns:
 - the rollbackOnly status.
 
 
- 
getTransactionKey
public java.lang.Object getTransactionKey()
Description copied from interface:javax.transaction.TransactionSynchronizationRegistryReturn 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:
 getTransactionKeyin 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.TransactionSynchronizationRegistryReturn 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:
 getTransactionStatusin 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.TransactionSynchronizationRegistryAdd 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:
 putResourcein 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:
 registerInterposedSynchronizationin interfacejavax.transaction.TransactionSynchronizationRegistry- Parameters:
 synchronization- interposed synchronization
 
- 
setRollbackOnly
public void setRollbackOnly() throws java.lang.IllegalStateExceptionDescription copied from interface:javax.transaction.TransactionManagerModify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.- Specified by:
 setRollbackOnlyin interfacejavax.transaction.TransactionManager- Specified by:
 setRollbackOnlyin interfacejavax.transaction.TransactionSynchronizationRegistry- Specified by:
 setRollbackOnlyin 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.SystemExceptionDescription copied from interface:javax.transaction.TransactionManagerComplete the transaction associated with the current thread. When this method completes, the thread is no longer associated with a transaction.- Specified by:
 commitin interfacejavax.transaction.TransactionManager- Specified by:
 commitin 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.SystemExceptionDescription copied from interface:javax.transaction.TransactionManagerRoll back the transaction associated with the current thread. When this method completes, the thread is no longer associated with a transaction.- Specified by:
 rollbackin interfacejavax.transaction.TransactionManager- Specified by:
 rollbackin 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:
 importXidin interfaceXidImporter- Throws:
 javax.transaction.xa.XAExceptionjavax.transaction.SystemException
 
- 
commit
public void commit(javax.transaction.Transaction tx, boolean onePhase) throws javax.transaction.xa.XAException- Specified by:
 commitin interfaceXidImporter- Throws:
 javax.transaction.xa.XAException
 
- 
forget
public void forget(javax.transaction.Transaction tx) throws javax.transaction.xa.XAException- Specified by:
 forgetin interfaceXidImporter- Throws:
 javax.transaction.xa.XAException
 
- 
prepare
public int prepare(javax.transaction.Transaction tx) throws javax.transaction.xa.XAException- Specified by:
 preparein interfaceXidImporter- Throws:
 javax.transaction.xa.XAException
 
- 
rollback
public void rollback(javax.transaction.Transaction tx) throws javax.transaction.xa.XAException- Specified by:
 rollbackin interfaceXidImporter- Throws:
 javax.transaction.xa.XAException
 
- 
recoveryError
public void recoveryError(java.lang.Exception e)
- Specified by:
 recoveryErrorin interfaceRecoverableTransactionManager
 
- 
registerNamedXAResourceFactory
public void registerNamedXAResourceFactory(NamedXAResourceFactory namedXAResourceFactory)
- Specified by:
 registerNamedXAResourceFactoryin interfaceRecoverableTransactionManager
 
- 
unregisterNamedXAResourceFactory
public void unregisterNamedXAResourceFactory(java.lang.String namedXAResourceFactoryName)
- Specified by:
 unregisterNamedXAResourceFactoryin interfaceRecoverableTransactionManager
 
- 
getExternalXids
public java.util.Map<javax.transaction.xa.Xid,TransactionImpl> getExternalXids()
- Specified by:
 getExternalXidsin interfaceXidImporter
 
- 
addTransactionAssociationListener
public void addTransactionAssociationListener(TransactionManagerMonitor listener)
- Specified by:
 addTransactionAssociationListenerin interfaceMonitorableTransactionManager
 
- 
removeTransactionAssociationListener
public void removeTransactionAssociationListener(TransactionManagerMonitor listener)
- Specified by:
 removeTransactionAssociationListenerin 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 
 - 
 
 -