Class TransactionManagerImpl

java.lang.Object
org.apache.geronimo.transaction.manager.TransactionManagerImpl
All Implemented Interfaces:
EventListener, javax.transaction.TransactionManager, javax.transaction.TransactionSynchronizationRegistry, javax.transaction.UserTransaction, MonitorableTransactionManager, RecoverableTransactionManager, XidImporter
Direct Known Subclasses:
GeronimoTransactionManager

public class TransactionManagerImpl extends Object implements javax.transaction.TransactionManager, javax.transaction.UserTransaction, javax.transaction.TransactionSynchronizationRegistry, XidImporter, MonitorableTransactionManager, RecoverableTransactionManager
Simple implementation of a transaction manager.
  • Constructor Details

  • Method Details

    • 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 interface javax.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 interface javax.transaction.TransactionManager
      Specified by:
      setTransactionTimeout in interface javax.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 interface javax.transaction.TransactionManager
      Specified by:
      getStatus in interface javax.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 interface javax.transaction.TransactionManager
      Specified by:
      begin in interface javax.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 interface javax.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 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 interface javax.transaction.TransactionManager
      Parameters:
      tx - The Transaction object that represents the transaction to be resumed.
      Throws:
      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 Object getResource(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 of Map.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 interface javax.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 interface javax.transaction.TransactionSynchronizationRegistry
      Returns:
      the rollbackOnly status.
    • getTransactionKey

      public 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 interface javax.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 interface javax.transaction.TransactionSynchronizationRegistry
      Returns:
      the status of the transaction bound to the current thread at the time this method is called.
    • putResource

      public void putResource(Object key, 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 of Map.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 interface javax.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 interface javax.transaction.TransactionSynchronizationRegistry
      Parameters:
      synchronization - interposed synchronization
    • setRollbackOnly

      public void setRollbackOnly() throws 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 interface javax.transaction.TransactionManager
      Specified by:
      setRollbackOnly in interface javax.transaction.TransactionSynchronizationRegistry
      Specified by:
      setRollbackOnly in interface javax.transaction.UserTransaction
      Throws:
      IllegalStateException - Thrown if the current thread is not associated with a transaction.
    • commit

      public void commit() throws javax.transaction.HeuristicMixedException, javax.transaction.HeuristicRollbackException, IllegalStateException, javax.transaction.RollbackException, 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 interface javax.transaction.TransactionManager
      Specified by:
      commit in interface javax.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.
      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.
      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 IllegalStateException, 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 interface javax.transaction.TransactionManager
      Specified by:
      rollback in interface javax.transaction.UserTransaction
      Throws:
      IllegalStateException - Thrown if the current thread is not associated with a transaction.
      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(Xid xid, long transactionTimeoutMilliseconds) throws XAException, javax.transaction.SystemException
      Specified by:
      importXid in interface XidImporter
      Throws:
      XAException
      javax.transaction.SystemException
    • commit

      public void commit(javax.transaction.Transaction tx, boolean onePhase) throws XAException
      Specified by:
      commit in interface XidImporter
      Throws:
      XAException
    • forget

      public void forget(javax.transaction.Transaction tx) throws XAException
      Specified by:
      forget in interface XidImporter
      Throws:
      XAException
    • prepare

      public int prepare(javax.transaction.Transaction tx) throws XAException
      Specified by:
      prepare in interface XidImporter
      Throws:
      XAException
    • rollback

      public void rollback(javax.transaction.Transaction tx) throws XAException
      Specified by:
      rollback in interface XidImporter
      Throws:
      XAException
    • recoveryError

      public void recoveryError(Exception e)
      Specified by:
      recoveryError in interface RecoverableTransactionManager
    • registerNamedXAResourceFactory

      public void registerNamedXAResourceFactory(NamedXAResourceFactory namedXAResourceFactory)
      Specified by:
      registerNamedXAResourceFactory in interface RecoverableTransactionManager
    • unregisterNamedXAResourceFactory

      public void unregisterNamedXAResourceFactory(String namedXAResourceFactoryName)
      Specified by:
      unregisterNamedXAResourceFactory in interface RecoverableTransactionManager
    • getExternalXids

      public Map<Xid,TransactionImpl> getExternalXids()
      Specified by:
      getExternalXids in interface XidImporter
    • addTransactionAssociationListener

      public void addTransactionAssociationListener(TransactionManagerMonitor listener)
      Specified by:
      addTransactionAssociationListener in interface MonitorableTransactionManager
    • removeTransactionAssociationListener

      public void removeTransactionAssociationListener(TransactionManagerMonitor listener)
      Specified by:
      removeTransactionAssociationListener in interface MonitorableTransactionManager
    • 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