Class TransactionHelperImpl

  • All Implemented Interfaces:
    TransactionHelper
    Direct Known Subclasses:
    SunTransactionHelper

    public abstract class TransactionHelperImpl
    extends Object
    implements TransactionHelper
    This is an abstract class which is a generic implementation of the TransactionHelper interface. Each concrete implementation that extends this class is used for information about the distributed transaction environment. The class that extends this class must implement getTransaction and getUserTransaction methods and replace any other method implementation if it is necessary. Such class must register itself by a static method at class initialization time. For example,
     import com.sun.jdo.spi.persistence.support.sqlstore.ejb.*;
     class blackHerringTransactionHelper extends TransactionHelperImpl {
        static EJBHelper.register(new blackHerringTransactionHelper());
        ...
     } 
     
    • Constructor Detail

      • TransactionHelperImpl

        public TransactionHelperImpl()
    • Method Detail

      • isManaged

        public boolean isManaged()
        Identifies the managed environment behavior.
        Specified by:
        isManaged in interface TransactionHelper
        Returns:
        true as this implementation represents the managed environment.
      • getTransaction

        public abstract jakarta.transaction.Transaction getTransaction()
        Identify the Transaction context for the calling thread, and return a Transaction instance that can be used to register synchronizations, and used as the key for HashMaps. The returned Transaction must implement equals() and hashCode() based on the global transaction id.

        All Transaction instances returned by this method called in the same Transaction context must compare equal and return the same hashCode. The Transaction instance returned will be held as the key to an internal HashMap until the Transaction completes. If there is no transaction associated with the current thread, this method returns null.

        Specified by:
        getTransaction in interface TransactionHelper
        Returns:
        the Transaction instance for the calling thread
      • getUserTransaction

        public abstract jakarta.transaction.UserTransaction getUserTransaction()
        Returns the UserTransaction associated with the calling thread. If there is no transaction currently in progress, this method returns null.
        Specified by:
        getUserTransaction in interface TransactionHelper
        Returns:
        the UserTransaction instance for the calling thread
      • translateStatus

        public int translateStatus​(int st)
        Translate local representation of the Transaction Status to jakarta.transaction.Status value if necessary. Otherwise this method should return the value passed to it as an argument.

        This method is used during afterCompletion callbacks to translate the parameter value passed by the application server to the afterCompletion method. The return value must be one of: jakarta.transaction.Status.STATUS_COMMITTED or jakarta.transaction.Status.STATUS_ROLLED_BACK.

        Specified by:
        translateStatus in interface TransactionHelper
        Parameters:
        st - local Status value
        Returns:
        the jakarta.transaction.Status value of the status
      • replaceInternalPersistenceManagerFactory

        public PersistenceManagerFactory replaceInternalPersistenceManagerFactory​(PersistenceManagerFactory pmf)
        Replace newly created instance of PersistenceManagerFactory with the hashed one if it exists. The replacement is necessary only if the JNDI lookup always returns a new instance. Otherwise this method returns the object passed to it as an argument. PersistenceManagerFactory is uniquely identified by ConnectionFactory.hashCode() if ConnectionFactory is not null; otherwise by ConnectionFactoryName.hashCode() if ConnectionFactoryName is not null; otherwise by the combination of URL.hashCode() + userName.hashCode() + password.hashCode() + driverName.hashCode();
        Specified by:
        replaceInternalPersistenceManagerFactory in interface TransactionHelper
        Parameters:
        pmf - PersistenceManagerFactory instance to be replaced
        Returns:
        the PersistenceManagerFactory known to the runtime
      • preInvoke

        public Object preInvoke​(Object component)
        Called at the beginning of the Transaction.beforeCompletion() to register the component with the app server only if necessary. The component argument is an array of Objects. The first element is com.sun.jdo.spi.persistence.support.sqlstore.Transaction object responsible for transaction completion. The second element is com.sun.jdo.api.persistence.support.PersistenceManager object that has been associated with the Transaction context for the calling thread. The third element is jakarta.transaction.Transaction object that has been associated with the given instance of PersistenceManager. The return value is passed unchanged to the postInvoke method.
        Specified by:
        preInvoke in interface TransactionHelper
        Parameters:
        component - an array of Objects
        Returns:
        implementation-specific Object
      • postInvoke

        public void postInvoke​(Object im)
        Called at the end of the Transaction.beforeCompletion() to de-register the component with the app server if necessary. The parameter is the return value from preInvoke, and can be any Object.
        Specified by:
        postInvoke in interface TransactionHelper
        Parameters:
        im - implementation-specific Object
      • registerSynchronization

        public void registerSynchronization​(jakarta.transaction.Transaction jta,
                                            jakarta.transaction.Synchronization sync)
                                     throws jakarta.transaction.RollbackException,
                                            jakarta.transaction.SystemException
        Called in a managed environment to register internal Synchronization object with the Transaction Synchronization. If available, this registration provides special handling of the registered instance, calling it after all user defined Synchronization instances.
        Specified by:
        registerSynchronization in interface TransactionHelper
        Parameters:
        jta - the Transaction instance for the calling thread.
        sync - the internal Synchronization instance to register.
        Throws:
        jakarta.transaction.SystemException
        jakarta.transaction.RollbackException
      • getConnection

        public Connection getConnection​(Object resource,
                                        String username,
                                        char[] password)
                                 throws SQLException
        Called in a managed environment to get a Connection from the application server specific resource. In a non-managed environment returns null as it should not be called. This is a generic implementation for the case of javax.sql.DataSource as the resource type.
        Specified by:
        getConnection in interface TransactionHelper
        Parameters:
        resource - the application server specific resource.
        username - the resource username. If null, Connection is requested without username and password validation.
        password - the password for the resource username.
        Returns:
        a Connection.
        Throws:
        SQLException
      • getNonTransactionalConnection

        public abstract Connection getNonTransactionalConnection​(Object resource,
                                                                 String username,
                                                                 char[] password)
                                                          throws SQLException
        Called in a managed environment to get a non-transactional Connection from the application server specific resource.
        Specified by:
        getNonTransactionalConnection in interface TransactionHelper
        Parameters:
        resource - the application server specific resource.
        username - the resource username. If null, Connection is requested without username and password validation.
        password - the password for the resource username.
        Returns:
        a Connection.
        Throws:
        SQLException
      • getLocalTransactionManager

        public abstract jakarta.transaction.TransactionManager getLocalTransactionManager()
        Called in a managed environment to access a TransactionManager for managing local transaction boundaries and registering synchronization for call backs during completion of a local transaction.
        Specified by:
        getLocalTransactionManager in interface TransactionHelper
        Returns:
        jakarta.transaction.TransactionManager
      • setPersistenceManagerFactoryDefaults

        public void setPersistenceManagerFactoryDefaults​(PersistenceManagerFactory pmf)
        Set environment specific default values for the given PersistenceManagerFactory. In most app servers optimistic and retainValues flags should be false. For any other settings this method should be overritten.
        Specified by:
        setPersistenceManagerFactoryDefaults in interface TransactionHelper
        Parameters:
        pmf - the PersistenceManagerFactory.
      • getDDLNamePrefix

        public String getDDLNamePrefix​(Object info)
        Returns name prefix for DDL files extracted from the info instance by the application server specific code.
        Specified by:
        getDDLNamePrefix in interface TransactionHelper
        Parameters:
        info - the instance to use for the name generation.
        Returns:
        name prefix as String.
      • registerApplicationLifeCycleEventListener

        public void registerApplicationLifeCycleEventListener​(ApplicationLifeCycleEventListener listener)
        Description copied from interface: TransactionHelper
        Called to register a ApplicationLifeCycleEventListener. If ApplicationLifeCycle management is active (typically in managed environment), the registered listener will receive a call back for lifecycle events.
        Specified by:
        registerApplicationLifeCycleEventListener in interface TransactionHelper
        Parameters:
        listener - An instance of ApplicationLifeCycleEventListener.
      • notifyApplicationUnloaded

        public void notifyApplicationUnloaded​(ClassLoader cl)
        Description copied from interface: TransactionHelper
        Called to notify a ApplicationLifeCycleEventListeners that an application is unloaded. If ApplicationLifeCycle management is active (typically in managed environment), the registered listener will handle the notification.
        Specified by:
        notifyApplicationUnloaded in interface TransactionHelper
        Parameters:
        cl - An instance of the ClassLoader that loaded the application.