Class EJBHelper


  • public class EJBHelper
    extends Object
    Provides helper methods for a Forte for Java implementation with the application server specific information in the distributed transaction environment. Calls corresponding methods on the registered class which implements TransactionHelper interface.
    • Constructor Detail

      • EJBHelper

        public EJBHelper()
    • Method Detail

      • registerTransactionHelper

        public static void registerTransactionHelper​(TransactionHelper h)
        Register class that implements TransactionHelper interface Should be called by a static method at class initialization time. If null is passed, sets the reference to the DefaultTransactionHelper.
        Parameters:
        h - application server specific implemetation of the TransactionHelper interface.
      • getTransaction

        public static jakarta.transaction.Transaction getTransaction()
        Returns Transaction instance that can be used to register synchronizations. In a non-managed environment or if there is no transaction associated with the current thread, this method returns null.
        Returns:
        the Transaction instance for the calling thread
        See Also:
        TransactionHelper.getTransaction()
      • getUserTransaction

        public static jakarta.transaction.UserTransaction getUserTransaction()
        Returns the UserTransaction associated with the calling thread. In a non-managed environment or if there is no transaction currently in progress, this method returns null.
        Returns:
        the UserTransaction instance for the calling thread
        See Also:
        TransactionHelper.getUserTransaction()
      • isManaged

        public static boolean isManaged()
        Identifies the managed environment behavior.
        Returns:
        true if this implementation represents the managed environment.
      • translateStatus

        public static int translateStatus​(int st)
        Translates local representation of the Transaction Status to jakarta.transaction.Status value. In a non-managed environment returns the value passed to it as an argument.
        Parameters:
        st - Status value
        Returns:
        the jakarta.transaction.Status value of the status
        See Also:
        TransactionHelper.translateStatus(int st)
      • preInvoke

        public static Object preInvoke​(Object component)
        Called at the beginning of the Transaction.beforeCompletion() to register the component with the app server if necessary. In a non-managed environment or if the postInvoke method does not use the value, this method returns null.
        Parameters:
        component - an array of Objects
        Returns:
        implementation-specific Object
        See Also:
        TransactionHelper.preInvoke(Object component)
      • postInvoke

        public static void postInvoke​(Object im)
        Called in a managed environment at the end of the Transaction.beforeCompletion() to de-register the component with the app server if necessary.
        Parameters:
        im - implementation-specific Object
        See Also:
        TransactionHelper.postInvoke(Object im)
      • registerSynchronization

        public static 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.
        Parameters:
        jta - the Transaction instance for the calling thread.
        sync - the internal Synchronization instance to register.
        Throws:
        jakarta.transaction.RollbackException
        jakarta.transaction.SystemException
        See Also:
        Transaction.registerSynchronization(Synchronization sync), TransactionHelper.registerSynchronization(Transaction jta, Synchronization sync)
      • getConnection

        public static 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 throws an Exception as it should not be called.
        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 static 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. In a non-managed environment throws an Exception as it should not be called.
        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 static jakarta.transaction.TransactionManager getLocalTransactionManager()
        Called in a managed environment to access a TransactionManager for managing local transaction boundaries and synchronization for local transaction completion.
        Returns:
        jakarta.transaction.TransactionManager
      • unwrapStatement

        public static Statement unwrapStatement​(Statement stmt)
        This method unwraps given Statement and return the Statement from JDBC driver if possible.
      • setPersistenceManagerFactoryDefaults

        public static void setPersistenceManagerFactoryDefaults​(PersistenceManagerFactory pmf)
        Set environment specific default values for the given PersistenceManagerFactory.
        Parameters:
        pmf - the PersistenceManagerFactory.
      • getDDLNamePrefix

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

        public static void registerApplicationLifeCycleEventListener​(ApplicationLifeCycleEventListener listener)
        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.
        Parameters:
        listener - An instance of ApplicationLifeCycleEventListener.
      • notifyApplicationUnloaded

        public static void notifyApplicationUnloaded​(ClassLoader cl)
        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.
        Parameters:
        cl - An instance of the ClassLoader that loaded the application.