Class TransactionSupportUtil


  • public abstract class TransactionSupportUtil
    extends Object
    Helper class to manage transaction synchronization. This provides helpers to ensure that the necessary TransactionSynchronization instances are registered on behalf of the application code.
    Author:
    mrogers
    • Field Detail

      • SESSION_SYNCHRONIZATION_ORDER

        public static final int SESSION_SYNCHRONIZATION_ORDER
        The order of synchronization set to be 100 less than the Hibernate synchronization order
        See Also:
        Constant Field Values
      • RESOURCE_KEY_TXN_SYNCH

        protected static final String RESOURCE_KEY_TXN_SYNCH
        resource key to store the transaction synchronizer instance
        See Also:
        Constant Field Values
      • RESOURCE_KEY_TXN_COMPLETING

        protected static final String RESOURCE_KEY_TXN_COMPLETING
        resource binding during after-completion phase
        See Also:
        Constant Field Values
    • Constructor Detail

      • TransactionSupportUtil

        public TransactionSupportUtil()
    • Method Detail

      • getTransactionStartTime

        public static long getTransactionStartTime()
        Returns:
        Returns the system time when the transaction started, or -1 if there is no current transaction.
      • getTransactionId

        public static String getTransactionId()
        Get a unique identifier associated with each transaction of each thread. Null is returned if no transaction is currently active.
        Returns:
        Returns the transaction ID, or null if no transaction is present
      • isActualTransactionActive

        public static boolean isActualTransactionActive()
      • getResource

        public static <R> R getResource​(Object key)
        Gets a resource associated with the current transaction, which must be active.

        All necessary synchronization instances will be registered automatically, if required.

        Parameters:
        key - the thread resource map key
        Returns:
        Returns a thread resource of null if not present
        See Also:
        for helper methods to create and bind common collection types
      • bindResource

        public static void bindResource​(Object key,
                                        Object resource)
        Binds a resource to the current transaction, which must be active.

        All necessary synchronization instances will be registered automatically, if required.

        Parameters:
        key - Object
        resource - Object
      • unbindResource

        public static void unbindResource​(Object key)
        Unbinds a resource from the current transaction, which must be active.

        All necessary synchronization instances will be registered automatically, if required.

        Parameters:
        key - Object
      • bindListener

        public static boolean bindListener​(TransactionListener listener,
                                           int priority)
        Bind listener to the specified priority. Duplicate bindings The priority specifies the position for the listener during commit. For example flushing of caches needs to happen very late.
        Parameters:
        listener - the listener to bind.
        priority - 0 = Normal priority
        Returns:
        true if the new listener was bound. False if the listener was already bound.
      • getListeners

        public static Set<TransactionListener> getListeners()
        Returns:
        Returns all the listeners in a list disconnected from the original set