Class NumberSeriesManager

  • All Implemented Interfaces:
    ItemLifecycleListener, java.io.Serializable

    public class NumberSeriesManager
    extends Manager
    This is the extension manager of the NumberSeries extension.
    A number series is a sequence of unique numbers identified by a unique key. Before using a series you have to create it using the createNumberSeries(String, String, int, int) method. With that you create a new series identified by a unique key where the series starts at the specified start value and contains of specified number of digits. The type of a series specified whether it is numeric using NumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERIC (consisting only of digits) or alpha numeric using NumberGenerator.NumberSeriesConstants.TYPES.NUMERIC (consisting of letters too). The digits and start value will be stored persistent for a series.
    For getting the next number of a series you can simply call getUniqueNumber(String). For resetting a series to a specific start value you can call resetNumberSeries(String, String, int). The setDigits(String, int) method can be called any time for changing the length of the generated numbers. The setStartValue(String, String) should not be called, the property is only used for storing the original start value of a series and will have no effect after series creation. It only is useful if storing a new start value for a later resetting of the series using the stored start value.
    See Also:
    Serialized Form
    • Field Detail

      • BEAN_NAME

        public static final java.lang.String BEAN_NAME
        Identifier of this manager used at core-spring.xml spring configuration.
        See Also:
        Constant Field Values
      • CONFIG_PARAM_NUMBER_CACHE

        public static final java.lang.String CONFIG_PARAM_NUMBER_CACHE
        Allows to set number series cache size globally and per series:
         # set global cache size
         numberseries.cache.size=100
        
         # set custom cache size for a single series
         numberseries.cache.size.mySeries=1
         
        See Also:
        Constant Field Values
      • DEFAULT_NUMBER_CACHE_SIZE

        public static final int DEFAULT_NUMBER_CACHE_SIZE
        Default cache size for number series. The cache size specifies the number of numbers fetched at once.
        See Also:
        Constant Field Values
    • Constructor Detail

      • NumberSeriesManager

        public NumberSeriesManager()
    • Method Detail

      • getInstance

        public static NumberSeriesManager getInstance()
        Gets the instance of this manager.
        Returns:
        instance of this manager
      • notifyItemRemoval

        protected void notifyItemRemoval​(SessionContext ctx,
                                         Item item)
        Superclass method overridden to avoid calls to ejb layer.
        Overrides:
        notifyItemRemoval in class Manager
        Parameters:
        ctx - the currency session context
        item - the item which is going to be removed
        Since:
        2.10
      • getUniqueNumber

        public java.lang.String getUniqueNumber​(java.lang.String key,
                                                int digits)
                                         throws JaloInvalidParameterException
        Returns a unique number for a given series key and a digit length. Assure that a number series with given key was created before.
        Parameters:
        key - the key of the number series, e.g. "Order"
        digits - the length of the result number string; if the actual number is smaller it will be filled with leading '0's - but if it is larger it wont be truncated !
        Throws:
        JaloInvalidParameterException - if a number series with given key is unknown
      • checkDigits

        protected int checkDigits​(java.lang.String key,
                                  int digits)
        Checks digits and if digits < 0 fetches default digits for given series key.
        Parameters:
        key - the series key
        digits - the given digits
      • getUniqueNumber

        public java.lang.String getUniqueNumber​(java.lang.String key)
                                         throws JaloInvalidParameterException
        Returns a unique number for a given number series key. The digit length is taken from previous value. Assure that a number series with given key was created before.
        Parameters:
        key - the key of the number series, e.g. "Order"
        Throws:
        JaloInvalidParameterException - if a number series with given key is unknown
      • getUniqueNumberUnformatted

        public NumberSeries getUniqueNumberUnformatted​(java.lang.String key)
                                                throws JaloInvalidParameterException
        Returns the unique number object rather than its formatted representation (see getUniqueNumber(String, int). Use as follows:
         NumberSeries ns = NumberSeriesManager.getInstance().getUniqueNumberUnformatted("fooSeries");
         // get 10 digits text
         String number10 = ns.getFormatted(10);
         // get real number
         long number = ns.getCurrentNumber();
         
        Parameters:
        key - the number series key
        Throws:
        JaloInvalidParameterException - if no series exists for key
      • removeNumberSeries

        public void removeNumberSeries​(java.lang.String key)
                                throws JaloInvalidParameterException
        Removes a number series and removes the digits and start value setting for this series.
        Parameters:
        key - the key of the number series, e.g. "Order"
        Throws:
        JaloInvalidParameterException
      • getAllNumberSeriesKeys

        public java.util.Collection<java.lang.String> getAllNumberSeriesKeys()
        Returns all keys where number series exists.
        Returns:
        A collection of strings.
      • getAllNumberSeries

        public java.util.Collection getAllNumberSeries()
        Makes a snapshot of all number series currently existing in the database.
        Returns:
        A collection of NumberSeries objects or an empty list.
      • resetNumberSeries

        @Deprecated(since="5.0",
                    forRemoval=false)
        public void resetNumberSeries​(java.lang.String key,
                                      java.lang.String startValue,
                                      int type)
                               throws JaloInvalidParameterException
        Deprecated.
        Resets the number series with the given key to the given start value and type. The new start value will be saved. The formerly defined digits will be used. The resetting has the effect, that the next gathering of a number will begin at the given start value.
        Parameters:
        key - the number series key, must not be null.
        startValue - the series new startvalue.
        type - the series type
        Throws:
        JaloInvalidParameterException - if no series was found for given key
      • resetNumberSeries

        public void resetNumberSeries​(java.lang.String key,
                                      java.lang.String startValue,
                                      int type,
                                      java.lang.String template)
                               throws JaloInvalidParameterException
        Resets the number series with the given key to the given start value and type. The new start value will be saved. The formerly defined digits will be used. The resetting has the effect, that the next gathering of a number will begin at the given start value.
        Parameters:
        key - the number series key, must not be null.
        startValue - the series new startvalue.
        type - the series type
        template - the template to be applied on generated value
        Throws:
        JaloInvalidParameterException - if no series was found for given key
      • setDigits

        public void setDigits​(java.lang.String key,
                              int digits)
        Saves the digits for the given number series. All following gathering of numbers will this new digits length.
        Parameters:
        key - the number series key. key must not be null.
        digits - the digits
      • getDigits

        public int getDigits​(java.lang.String key)
        Returns the configured digits for the given number series.
        Parameters:
        key - the number series key. must not be null.
        Returns:
        the digits or -1 if there is no digit set.
      • removeDigits

        public void removeDigits​(java.lang.String key)
        Removes the digits setting from NumberSeriesManager for the given series.
        Parameters:
        key - the number series key. Must not be null.
      • setStartValue

        public void setStartValue​(java.lang.String key,
                                  java.lang.String startvalue)
        Changes the original start value of the given series. The call of this method will not influence the number generation, it only changes the original start value to the new one. The start value will only be used at series creation. You may change it for later usage at resetting a series. For resetting a number series to a new start value call resetNumberSeries(String, String, int). Therefore you can use the getStartValue(String) method.
        Parameters:
        key - the series key, must not be null
        startvalue - the series start value
      • getStartValue

        public java.lang.String getStartValue​(java.lang.String key)
        Returns the original start value of the given series. May useful if you like to reset a series using the resetNumberSeries(String, String, int) method.
        Parameters:
        key - the series key, must not be null
        Returns:
        the original start value.
      • removeStartValue

        public void removeStartValue​(java.lang.String key)
        Removes the original start value property and value.
        Parameters:
        key - the series key, must not be null
      • isCreatorDisabled

        public boolean isCreatorDisabled()
        Part of DataCreator interface. Returns true.
        Returns:
        true
      • createEssentialData

        public void createEssentialData​(java.util.Map params,
                                        JspContext jspc)
      • assureCustomerIDSeriesCreated

        @Deprecated(since="ages",
                    forRemoval=false)
        public void assureCustomerIDSeriesCreated()
        Deprecated.
        since ages - number series is created during init - there is no need to check each time a new number is fetched!
        Assures that the number series with key NumberSeriesConstants.Series.CUSTOMER_ID is created. If not existent it will be created. The series can be used at unique customer id generation.
      • getOrCreateCustomerIDSeries

        public NumberSeries getOrCreateCustomerIDSeries()
        Returns standard number series for customer IDs. If no series exists it will be created automatically.
      • assureOrderCodeSeriesCreated

        @Deprecated(since="ages",
                    forRemoval=false)
        public void assureOrderCodeSeriesCreated()
        Deprecated.
        since ages - number series are created during init - there is no need to check each time we need a new number !
        Assures that the number series with key NumberSeriesConstants.Series.ORDER_CODE is created. If not existent it will be created. The series can be used at unique customer id generation.
      • getOrCreateOrderCodeSeries

        public NumberSeries getOrCreateOrderCodeSeries()
        Returns standard number series for order codes. If no series exists it will be created automatically.
      • writeReplace

        public java.lang.Object writeReplace()
                                      throws java.io.ObjectStreamException
        Specified by:
        writeReplace in class Manager
        Throws:
        java.io.ObjectStreamException