Class DefaultCachingSerialNumberGenerator

  • All Implemented Interfaces:
    SerialNumberGenerator

    public class DefaultCachingSerialNumberGenerator
    extends java.lang.Object
    implements SerialNumberGenerator
    Default implementation of SerialNumberGenerator which caches number ranges for each key.

    Cache size may be specified in project.properties like this:

        # set cache size for single series 'myseries' to 50
        numberseries.cache.size.myseries=50
    
        # set default cache size to 999
        numberseries.cache.size=999
     
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void clearAll()
      Completely clear all (cached) ranges.
      void createSeries​(java.lang.String key, int type, long startValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ages
      void createSeries​(java.lang.String key, int type, long startValue, java.lang.String template)
      Creates a new number series with the specified key, type and start value.
      java.util.Collection<NumberSeries> getAllInfo()
      Returns snapshot of all number series of this tenant.
      protected int getCacheSize​(java.lang.String key)  
      SerialNumberDAO getDao()  
      NumberSeries getInfo​(java.lang.String key)
      Returns a snapshot of a specified number series.
      protected Tenant getTenant()  
      NumberSeries getUniqueNumber​(java.lang.String key)
      Generates a new unique number for the given series.
      void removeSeries​(java.lang.String key)
      Removes a existing number series.
      void resetSeries​(java.lang.String key, int type, long startValue)
      Resets type and start value of a existing series.
      • Methods inherited from class java.lang.Object

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

      • DefaultCachingSerialNumberGenerator

        public DefaultCachingSerialNumberGenerator​(Tenant t,
                                                   SerialNumberDAO dao)
    • Method Detail

      • createSeries

        public void createSeries​(java.lang.String key,
                                 int type,
                                 long startValue,
                                 java.lang.String template)
        Description copied from interface: SerialNumberGenerator
        Creates a new number series with the specified key, type and start value.
        Specified by:
        createSeries in interface SerialNumberGenerator
        Parameters:
        key - the series key
        type - the type; use one of NumberSeries.TYPE_ALPHANUMERIC and NumberSeries.TYPE_NUMERIC
        startValue - the start value - must be positive long
        template - the template to be applied on generated value
      • createSeries

        @Deprecated(since="ages",
                    forRemoval=true)
        public void createSeries​(java.lang.String key,
                                 int type,
                                 long startValue)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since ages
        Description copied from interface: SerialNumberGenerator
        Creates a new number series with the specified key, type and start value.
        Specified by:
        createSeries in interface SerialNumberGenerator
        Parameters:
        key - the series key
        type - the type; use one of NumberSeries.TYPE_ALPHANUMERIC and NumberSeries.TYPE_NUMERIC
        startValue - the start value - must be positive long
      • getUniqueNumber

        public NumberSeries getUniqueNumber​(java.lang.String key)
        Description copied from interface: SerialNumberGenerator
        Generates a new unique number for the given series. The returned number is consumed and will never be returned again. Please note that transactions have no effect upon number generation!
        Specified by:
        getUniqueNumber in interface SerialNumberGenerator
        Parameters:
        key - the series key
      • resetSeries

        public void resetSeries​(java.lang.String key,
                                int type,
                                long startValue)
        Description copied from interface: SerialNumberGenerator
        Resets type and start value of a existing series. Please use with care since duplicate numbers are likely to be generated if start value is moved 'back'!
        Specified by:
        resetSeries in interface SerialNumberGenerator
        Parameters:
        key - the series key
        type - the series type
        startValue - the start value
      • clearAll

        public void clearAll()
        Description copied from interface: SerialNumberGenerator
        Completely clear all (cached) ranges. This is only called after the 'numberseries' table has been dropped.
        Specified by:
        clearAll in interface SerialNumberGenerator
      • getTenant

        protected Tenant getTenant()
      • getCacheSize

        protected int getCacheSize​(java.lang.String key)