Class UserTransactionHelper


  • public class UserTransactionHelper
    extends java.lang.Object

    A helper for obtaining a handle to a UserTransaction...

    To ensure proper cleanup of the InitalContext used to create/lookup the UserTransaction, be sure to always call returnUserTransaction() when you are done with the UserTransaction.

    Author:
    James House
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getUserTxLocation()  
      static jakarta.transaction.UserTransaction lookupUserTransaction()
      Create/Lookup a UserTransaction in the InitialContext via the name set in setUserTxLocation().
      static void returnUserTransaction​(jakarta.transaction.UserTransaction userTransaction)
      Return a UserTransaction that was retrieved via getUserTransaction().
      static void setUserTxLocation​(java.lang.String userTxURL)
      Set the JNDI URL at which the Application Server's UserTransaction can be found.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_USER_TX_LOCATION

        public static final java.lang.String DEFAULT_USER_TX_LOCATION
        See Also:
        Constant Field Values
    • Method Detail

      • getUserTxLocation

        public static java.lang.String getUserTxLocation()
      • setUserTxLocation

        public static void setUserTxLocation​(java.lang.String userTxURL)
        Set the JNDI URL at which the Application Server's UserTransaction can be found. If not set, the default value is "java:comp/UserTransaction" - which works for nearly all application servers.
      • lookupUserTransaction

        public static jakarta.transaction.UserTransaction lookupUserTransaction()
                                                                         throws SchedulerException
        Create/Lookup a UserTransaction in the InitialContext via the name set in setUserTxLocation().
        Throws:
        SchedulerException
      • returnUserTransaction

        public static void returnUserTransaction​(jakarta.transaction.UserTransaction userTransaction)
        Return a UserTransaction that was retrieved via getUserTransaction(). This will make sure that the InitalContext used to lookup/create the UserTransaction is properly cleaned up.