Class TransactionImpl

  • All Implemented Interfaces:
    Transaction, Transaction, jakarta.transaction.Synchronization

    public class TransactionImpl
    extends Object
    implements Transaction
    The Transaction interface allows operations to be performed against the transaction in the target Transaction object. A Transaction object is created corresponding to each global transaction creation. The Transaction object can be used for resource enlistment, synchronization registration, transaction completion and status query operations. This implementation is completely internal. All externally documented methods are on the Transaction interface. Note on synchronized(this): There are a number of places that calls are made outside the transaction system. For example, Synchronization.beforeCompletion() and XAResource.start(). It is important that no locks are held when these callbacks are made. This requires more state checking up return from these calls, and the methods are careful to check state transitions after release the lock and reacquiring it. Also be careful NOT to call into a lower method with the lock, if that method may call out of the transaction system. Take care if you make methods "synchronized" because: synchronized methodName() is not the same lock as a more localized: synchronized(this) This is tested in the regression tests (see "Lock Test")
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterCompletion​(int st)
      Called in the managed environment only for transaction completion
      void beforeCompletion()
      Called in the managed environment only for transaction completion
      void begin()
      Begin a transaction.
      void begin​(jakarta.transaction.Transaction t)
      Begin a transaction in managed environment
      void commit()
      Commit the transaction represented by this Transaction object
      Connection getConnection()
      Returns a Connection.
      boolean getNontransactionalRead()
      If this flag is set to true, then queries and navigation are allowed without an active transaction
      boolean getOptimistic()
      Optimistic transactions do not hold data store locks until commit time.
      PersistenceManager getPersistenceManager()
      Returns PersistenceManager associated with this transaction
      int getQueryTimeout()
      Gets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instance
      boolean getRestoreValues()
      If true, at rollback time instances restore their field values.
      boolean getRetainValues()
      If true, at commit time instances retain their field values.
      int getStatus()
      Obtain the status of this transaction object.
      jakarta.transaction.Synchronization getSynchronization()
      The user-specified Synchronization instance for this Transaction instance.
      int getTransactionType()  
      int getUpdateTimeout()
      Gets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instance
      boolean isActive()
      Returns whether there is a transaction currently active.
      void releaseConnection()
      Close a connection.
      void replaceConnection()
      Replace a connection.
      void rollback()
      Rollback the transaction represented by this transaction object.
      void setNontransactionalRead​(boolean flag)
      If this flag is set to true, then queries and navigation are allowed without an active transaction
      void setOptimistic​(boolean flag)
      Optimistic transactions do not hold data store locks until commit time.
      void setPersistenceManager​(PersistenceManager pm)
      Set PersistenceManager
      void setQueryTimeout​(int timeout)
      Sets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instance
      void setRestoreValues​(boolean flag)
      If true, at rollback instances restore their values and the instances transition to persistent-nontransactional.
      void setRetainValues​(boolean flag)
      If true, at commit instances retain their values and the instances transition to persistent-nontransactional.
      void setRollbackOnly()
      Modify the transaction object such that the only possible outcome of the transaction is to roll back.
      void setSynchronization​(jakarta.transaction.Synchronization sync)
      The user can specify a Synchronization instance to be notified on transaction completions.
      void setUpdateTimeout​(int timeout)
      Sets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instance
      static String statusString​(int status)
      Translates a jakarta.transaction.Status value into a string.
      String toString()
      Returns a string representation of this transaction object.
      boolean verify​(String username, char[] password)
      Verify that username and password are equal to ones stored before
    • Constructor Detail

      • TransactionImpl

        public TransactionImpl​(PersistenceManager pm,
                               String username,
                               char[] password,
                               int seconds)
        Constructor
    • Method Detail

      • setPersistenceManager

        public void setPersistenceManager​(PersistenceManager pm)
        Set PersistenceManager
      • getPersistenceManager

        public PersistenceManager getPersistenceManager()
        Returns PersistenceManager associated with this transaction
        Specified by:
        getPersistenceManager in interface Transaction
        Returns:
        the PersistenceManager for this Transaction instance
      • isActive

        public boolean isActive()
        Description copied from interface: Transaction
        Returns whether there is a transaction currently active.
        Specified by:
        isActive in interface Transaction
        Returns:
        boolean
      • setRetainValues

        public void setRetainValues​(boolean flag)
        Description copied from interface: Transaction
        If true, at commit instances retain their values and the instances transition to persistent-nontransactional.

        Setting this flag also sets the NontransactionalRead flag.

        Specified by:
        setRetainValues in interface Transaction
        Parameters:
        flag - the value of the retainValues property
      • getRetainValues

        public boolean getRetainValues()
        Description copied from interface: Transaction
        If true, at commit time instances retain their field values.
        Specified by:
        getRetainValues in interface Transaction
        Returns:
        the value of the retainValues property
      • setRestoreValues

        public void setRestoreValues​(boolean flag)
        Description copied from interface: Transaction
        If true, at rollback instances restore their values and the instances transition to persistent-nontransactional.
        Specified by:
        setRestoreValues in interface Transaction
        Parameters:
        flag - the value of the restoreValues property
      • getRestoreValues

        public boolean getRestoreValues()
        Description copied from interface: Transaction
        If true, at rollback time instances restore their field values.
        Specified by:
        getRestoreValues in interface Transaction
        Returns:
        the value of the restoreValues property
      • setNontransactionalRead

        public void setNontransactionalRead​(boolean flag)
        Description copied from interface: Transaction
        If this flag is set to true, then queries and navigation are allowed without an active transaction
        Specified by:
        setNontransactionalRead in interface Transaction
        Parameters:
        flag - the value of the nontransactionalRead property.
      • getNontransactionalRead

        public boolean getNontransactionalRead()
        Description copied from interface: Transaction
        If this flag is set to true, then queries and navigation are allowed without an active transaction
        Specified by:
        getNontransactionalRead in interface Transaction
        Returns:
        the value of the nontransactionalRead property.
      • setQueryTimeout

        public void setQueryTimeout​(int timeout)
        Sets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instance
        Specified by:
        setQueryTimeout in interface Transaction
        Parameters:
        timeout - new timout value in seconds; zero means unlimited
      • getQueryTimeout

        public int getQueryTimeout()
        Gets the number of seconds to wait for a query statement to execute in the datastore associated with this Transaction instance
        Specified by:
        getQueryTimeout in interface Transaction
        Returns:
        timout value in seconds; zero means unlimited
      • setUpdateTimeout

        public void setUpdateTimeout​(int timeout)
        Sets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instance
        Specified by:
        setUpdateTimeout in interface Transaction
        Parameters:
        timeout - new timout value in seconds; zero means unlimited
      • getUpdateTimeout

        public int getUpdateTimeout()
        Gets the number of seconds to wait for an update statement to execute in the datastore associated with this Transaction instance
        Specified by:
        getUpdateTimeout in interface Transaction
        Returns:
        timout value in seconds; zero means unlimited
      • setOptimistic

        public void setOptimistic​(boolean flag)
        Description copied from interface: Transaction
        Optimistic transactions do not hold data store locks until commit time.
        Specified by:
        setOptimistic in interface Transaction
        Parameters:
        flag - the value of the Optimistic flag.
      • getOptimistic

        public boolean getOptimistic()
        Description copied from interface: Transaction
        Optimistic transactions do not hold data store locks until commit time.
        Specified by:
        getOptimistic in interface Transaction
        Returns:
        the value of the Optimistic property.
      • setSynchronization

        public void setSynchronization​(jakarta.transaction.Synchronization sync)
        Description copied from interface: Transaction
        The user can specify a Synchronization instance to be notified on transaction completions. The beforeCompletion method is called prior to flushing instances to the data store.

        The afterCompletion method is called after performing the data store commit operation.

        Specified by:
        setSynchronization in interface Transaction
        Parameters:
        sync - the Synchronization instance to be notified; null for none
      • getSynchronization

        public jakarta.transaction.Synchronization getSynchronization()
        Description copied from interface: Transaction
        The user-specified Synchronization instance for this Transaction instance.
        Specified by:
        getSynchronization in interface Transaction
        Returns:
        the user-specified Synchronization instance.
      • getTransactionType

        public int getTransactionType()
      • verify

        public boolean verify​(String username,
                              char[] password)
        Verify that username and password are equal to ones stored before
        Parameters:
        username - as String
        password - as String
        Returns:
        true if they are equal
      • begin

        public void begin​(jakarta.transaction.Transaction t)
        Begin a transaction in managed environment
        Specified by:
        begin in interface Transaction
      • commit

        public void commit()
        Commit the transaction represented by this Transaction object
        Specified by:
        commit in interface Transaction
      • beforeCompletion

        public void beforeCompletion()
        Called in the managed environment only for transaction completion
        Specified by:
        beforeCompletion in interface jakarta.transaction.Synchronization
      • afterCompletion

        public void afterCompletion​(int st)
        Called in the managed environment only for transaction completion
        Specified by:
        afterCompletion in interface jakarta.transaction.Synchronization
      • rollback

        public void rollback()
        Rollback the transaction represented by this transaction object.
        Specified by:
        rollback in interface Transaction
      • setRollbackOnly

        public void setRollbackOnly()
        Modify the transaction object such that the only possible outcome of the transaction is to roll back.
        Specified by:
        setRollbackOnly in interface Transaction
      • getStatus

        public int getStatus()
        Obtain the status of this transaction object.
        Returns:
        The transaction status.
      • statusString

        public static String statusString​(int status)
        Translates a jakarta.transaction.Status value into a string.
        Parameters:
        status - Status object to translate.
        Returns:
        Printable String for a Status object.
      • getConnection

        public Connection getConnection()
        Returns a Connection. If there is no existing one, asks ConnectionFactory for a new Connection
        Specified by:
        getConnection in interface Transaction
      • replaceConnection

        public void replaceConnection()
        Replace a connection. Used in a managed environment only. In a J2EE RI Connection need to be replaced at the beforeCompletion.
        Specified by:
        replaceConnection in interface Transaction
      • releaseConnection

        public void releaseConnection()
        Close a connection. Connection cannot be closed if it is part of the commit/rollback operation or inside a pessimistic transaction
        Specified by:
        releaseConnection in interface Transaction
      • toString

        public String toString()
        Returns a string representation of this transaction object.
        Overrides:
        toString in class Object
        Returns:
        String describing contents of this Transaction object.