Class NumberSeriesManager
java.lang.Object
de.hybris.platform.jalo.Manager
de.hybris.platform.jalo.numberseries.NumberSeriesManager
- All Implemented Interfaces:
ItemLifecycleListener,Serializable
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
For getting the next number of a series you can simply call
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classNested classes/interfaces inherited from class de.hybris.platform.jalo.Manager
Manager.GenericManagerSingletonCreator, Manager.ManagerSingletonCreator -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.since ages - number series is created during init - there is no need to check each time a new number is fetched!voidDeprecated.since ages - number series are created during init - there is no need to check each time we need a new number !protected voidcheckBeforeItemRemoval(SessionContext ctx, Item item) Superclass method overridden to avoid calls to ejb layer.protected intcheckDigits(String key, int digits) Checks digits and ifdigits < 0fetches default digits for given series key.voidcreateEssentialData(Map params, JspContext jspc) createNumberSeries(String key, String startValue, int type) Deprecated.since 5.0 - please usecreateNumberSeries(String, String, int, int, String)instead.createNumberSeries(String key, String startValue, int type, int digits) Deprecated.since 5.0 - please usecreateNumberSeries(String, String, int, int, String).createNumberSeries(String key, String startValue, int type, int digits, String template) Creates a new number series, sets the given start value viasetStartValue(String, String)and the given digits viasetDigits(String, int)persistent.Makes a snapshot of all number series currently existing in the database.Returns all keys where number series exists.intReturns the configured digits for the given number series.static NumberSeriesManagerGets the instance of this manager.getNumberSeries(String key) Makes a snapshot of the number series linked to the given key.Returns standard number series for customer IDs.Returns standard number series for order codes.getStartValue(String key) Returns the original start value of the given series.getUniqueNumber(String key) Returns a unique number for a given number series key.getUniqueNumber(String key, int digits) Returns a unique number for a given series key and a digit length.Returns the unique number object rather than its formatted representation (seegetUniqueNumber(String, int).booleanPart ofDataCreatorinterface.protected voidnotifyItemRemoval(SessionContext ctx, Item item) Superclass method overridden to avoid calls to ejb layer.voidremoveDigits(String key) Removes the digits setting from NumberSeriesManager for the given series.voidremoveNumberSeries(String key) Removes a number series and removes the digits and start value setting for this series.voidremoveStartValue(String key) Removes the original start value property and value.voidresetNumberSeries(String key, String startValue, int type) Deprecated.since 5.0 - please useresetNumberSeries(String, String, int, String).voidresetNumberSeries(String key, String startValue, int type, String template) Resets the number series with the given key to the given start value and type.voidSaves the digits for the given number series.voidsetStartValue(String key, String startvalue) Changes the original start value of the given series.Methods inherited from class de.hybris.platform.jalo.Manager
afterItemCreation, beforeItemCreation, destroy, extractNonRequiredRemoteFromItem, extractRequiredRemoteFromItem, getAllValuesSessionContext, getAttribute, getAttributeMap, getFirstItemByAttribute, getFirstItemByAttribute, getRemote, getRemoteManagerClass, getSession, getSingletonManagerInstance, getTenant, getTransientObject, getTransientObjectMap, init, setAttribute, setTenant, setTransientObject, wrap
-
Field Details
-
BEAN_NAME
Identifier of this manager used at core-spring.xml spring configuration.- See Also:
-
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:
-
DEFAULT_NUMBER_CACHE_SIZE
public static final int DEFAULT_NUMBER_CACHE_SIZEDefault cache size for number series. The cache size specifies the number of numbers fetched at once.- See Also:
-
-
Constructor Details
-
NumberSeriesManager
public NumberSeriesManager()
-
-
Method Details
-
getInstance
Gets the instance of this manager.- Returns:
- instance of this manager
-
checkBeforeItemRemoval
protected void checkBeforeItemRemoval(SessionContext ctx, Item item) throws ConsistencyCheckException Superclass method overridden to avoid calls to ejb layer.- Overrides:
checkBeforeItemRemovalin classManager- Parameters:
ctx- the current session contextitem- the item which should be removed- Throws:
ConsistencyCheckException- thrown to abort removal due to consistency errors- Since:
- 2.10
-
notifyItemRemoval
Superclass method overridden to avoid calls to ejb layer.- Overrides:
notifyItemRemovalin classManager- Parameters:
ctx- the currency session contextitem- the item which is going to be removed- Since:
- 2.10
-
getUniqueNumber
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
Checks digits and ifdigits < 0fetches default digits for given series key.- Parameters:
key- the series keydigits- the given digits
-
getUniqueNumber
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
Returns the unique number object rather than its formatted representation (seegetUniqueNumber(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
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
-
createNumberSeries
@Deprecated(since="5.0", forRemoval=false) public NumberSeries createNumberSeries(String key, String startValue, int type) throws JaloInvalidParameterException Deprecated.since 5.0 - please usecreateNumberSeries(String, String, int, int, String)instead.Creates a number series and sets the start value viasetStartValue(String, String). CallsetDigits(String, int)to assure that the right digits are set or usecreateNumberSeries(String, String, int, int). Otherwise you may get an exception on other moduls like hybris platform hmc.- Parameters:
key- the key of the number series, e.g. "Order"startValue- the star value of this serie: numeric series must have a Long parseable value, alphanumeric must match ['0'..'9''A'..'Z']*type- one ofNumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERICandNumberGenerator.NumberSeriesConstants.TYPES.NUMERIC- Throws:
JaloInvalidParameterException
-
createNumberSeries
public NumberSeries createNumberSeries(String key, String startValue, int type, int digits, String template) throws JaloInvalidParameterException Creates a new number series, sets the given start value viasetStartValue(String, String)and the given digits viasetDigits(String, int)persistent.- Parameters:
key- the number series key.startValue- the number series start value.type- the number series typeNumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERICorNumberGenerator.NumberSeriesConstants.TYPES.NUMERICdigits- the number of digitstemplate- the template to be applied on generated value- Returns:
- A
NumberSeriesobject. - Throws:
JaloInvalidParameterException- if there is no series registered for given key
-
createNumberSeries
@Deprecated(since="5.0", forRemoval=false) public NumberSeries createNumberSeries(String key, String startValue, int type, int digits) throws JaloInvalidParameterException Deprecated.since 5.0 - please usecreateNumberSeries(String, String, int, int, String).Creates a new number series, sets the given start value viasetStartValue(String, String)and the given digits viasetDigits(String, int)persistent.- Parameters:
key- the number series key.startValue- the number series start value.type- the number series typeNumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERICorNumberGenerator.NumberSeriesConstants.TYPES.NUMERICdigits- the number of digits- Returns:
- A
NumberSeriesobject. - Throws:
JaloInvalidParameterException- if there is no series registered for given key
-
getAllNumberSeriesKeys
Returns all keys where number series exists.- Returns:
- A collection of strings.
-
getAllNumberSeries
Makes a snapshot of all number series currently existing in the database.- Returns:
- A collection of
NumberSeriesobjects or an empty list.
-
getNumberSeries
Makes a snapshot of the number series linked to the given key. If the key doesn't exists anJaloInvalidParameterExceptionwill be thrown.- Parameters:
key- the series key- Returns:
- The
NumberSeriesobject for the key. - Throws:
JaloInvalidParameterException
-
resetNumberSeries
@Deprecated(since="5.0", forRemoval=false) public void resetNumberSeries(String key, String startValue, int type) throws JaloInvalidParameterException Deprecated.since 5.0 - please useresetNumberSeries(String, String, int, String).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(String key, String startValue, int type, 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 typetemplate- the template to be applied on generated value- Throws:
JaloInvalidParameterException- if no series was found for given key
-
setDigits
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
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
Removes the digits setting from NumberSeriesManager for the given series.- Parameters:
key- the number series key. Must not be null.
-
setStartValue
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 callresetNumberSeries(String, String, int). Therefore you can use thegetStartValue(String)method.- Parameters:
key- the series key, must not benullstartvalue- the series start value
-
getStartValue
Returns the original start value of the given series. May useful if you like to reset a series using theresetNumberSeries(String, String, int)method.- Parameters:
key- the series key, must not benull- Returns:
- the original start value.
-
removeStartValue
Removes the original start value property and value.- Parameters:
key- the series key, must not benull
-
isCreatorDisabled
public boolean isCreatorDisabled()Part ofDataCreatorinterface. Returnstrue.- Returns:
true
-
createEssentialData
-
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 keyNumberSeriesConstants.Series.CUSTOMER_IDis created. If not existent it will be created. The series can be used at unique customer id generation. -
getOrCreateCustomerIDSeries
Returns standard number series for customer IDs. If no series exists it will be created automatically. -
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 keyNumberSeriesConstants.Series.ORDER_CODEis created. If not existent it will be created. The series can be used at unique customer id generation. -
getOrCreateOrderCodeSeries
Returns standard number series for order codes. If no series exists it will be created automatically. -
writeReplace
- Specified by:
writeReplacein classManager- Throws:
ObjectStreamException
-