Class TransactionalResourceHelper


  • public abstract class TransactionalResourceHelper
    extends java.lang.Object
    Helper class that will look up or create transactional resources. This shortcuts some of the "if not existing, then create" code.
    Since:
    3.2
    Author:
    Derek Hulley
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int decrementCount​(java.lang.Object resourceKey, boolean allowNegative)
      Decrement a count value for a named key
      static int getCount​(java.lang.Object resourceKey)
      Get the current count value for a named key
      static <V> java.util.List<V> getList​(java.lang.Object resourceKey)
      Support method to retrieve or create and bind a ArrayList to the current transaction.
      static <K,​V>
      java.util.Map<K,​V>
      getMap​(java.lang.Object resourceKey)
      Support method to retrieve or create and bind a HashMap to the current transaction.
      static <V> java.util.Set<V> getSet​(java.lang.Object resourceKey)
      Support method to retrieve or create and bind a HashSet to the current transaction.
      static <V> java.util.TreeSet<V> getTreeSet​(java.lang.Object resourceKey)
      Support method to retrieve or create and bind a TreeSet to the current transaction.
      static int incrementCount​(java.lang.Object resourceKey)
      Increment a count value for named key
      static boolean isResourcePresent​(java.lang.Object resourceKey)
      Support method to determine if there is already a resource associated with the given key.
      static void resetCount​(java.lang.Object resourceKey)
      Reset the current count value for a named key.
      • Methods inherited from class java.lang.Object

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

      • TransactionalResourceHelper

        public TransactionalResourceHelper()
    • Method Detail

      • getCount

        public static final int getCount​(java.lang.Object resourceKey)
        Get the current count value for a named key
        Parameters:
        resourceKey - the key to count against
        Returns:
        the current value for the named key
      • resetCount

        public static final void resetCount​(java.lang.Object resourceKey)
        Reset the current count value for a named key. After this operation, the effective value will be 0.
        Parameters:
        resourceKey - the key to count against
      • incrementCount

        public static final int incrementCount​(java.lang.Object resourceKey)
        Increment a count value for named key
        Parameters:
        resourceKey - the key to count against
        Returns:
        the newly-incremented value
      • decrementCount

        public static final int decrementCount​(java.lang.Object resourceKey,
                                               boolean allowNegative)
        Decrement a count value for a named key
        Parameters:
        resourceKey - the key to count against
        allowNegative - true to allow negative values otherwise zero will be the floor
        Returns:
        the newly-decremented value (negative, if allowed)
      • isResourcePresent

        public static final boolean isResourcePresent​(java.lang.Object resourceKey)
        Support method to determine if there is already a resource associated with the given key. This method allows quick conditional checking of the key without building a new collection.
        Parameters:
        resourceKey - the key of the resource to check
        Returns:
        true if a resource is already present at the key
      • getMap

        public static final <K,​V> java.util.Map<K,​V> getMap​(java.lang.Object resourceKey)
        Support method to retrieve or create and bind a HashMap to the current transaction.
        Type Parameters:
        K - the map key type
        V - the map value type
        Parameters:
        resourceKey - the key under which the resource will be stored
        Returns:
        Returns an previously-bound Map or else a newly-bound HashMap
      • getSet

        public static final <V> java.util.Set<V> getSet​(java.lang.Object resourceKey)
        Support method to retrieve or create and bind a HashSet to the current transaction.
        Type Parameters:
        V - the set value type
        Parameters:
        resourceKey - the key under which the resource will be stored
        Returns:
        Returns an previously-bound Set or else a newly-bound HashSet
      • getTreeSet

        public static final <V> java.util.TreeSet<V> getTreeSet​(java.lang.Object resourceKey)
        Support method to retrieve or create and bind a TreeSet to the current transaction.
        Type Parameters:
        V - the set value type
        Parameters:
        resourceKey - the key under which the resource will be stored
        Returns:
        Returns an previously-bound TreeSet or else a newly-bound TreeSet
      • getList

        public static final <V> java.util.List<V> getList​(java.lang.Object resourceKey)
        Support method to retrieve or create and bind a ArrayList to the current transaction.
        Type Parameters:
        V - the list value type
        Parameters:
        resourceKey - the key under which the resource will be stored
        Returns:
        Returns an previously-bound List or else a newly-bound ArrayList