Class NumberSeriesManager
- java.lang.Object
-
- de.hybris.platform.jalo.Manager
-
- de.hybris.platform.jalo.numberseries.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 thecreateNumberSeries(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 usingNumberGenerator.NumberSeriesConstants.TYPES.ALPHANUMERIC(consisting only of digits) or alpha numeric usingNumberGenerator.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 callgetUniqueNumber(String). For resetting a series to a specific start value you can callresetNumberSeries(String, String, int). ThesetDigits(String, int)method can be called any time for changing the length of the generated numbers. ThesetStartValue(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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classNumberSeriesManager.NumberSeriesManagerSerializableDTO-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.Manager
Manager.GenericManagerSingletonCreator, Manager.ManagerSingletonCreator
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBEAN_NAMEIdentifier of this manager used at core-spring.xml spring configuration.static java.lang.StringCONFIG_PARAM_NUMBER_CACHEAllows to set number series cache size globally and per series:static intDEFAULT_NUMBER_CACHE_SIZEDefault cache size for number series.
-
Constructor Summary
Constructors Constructor Description NumberSeriesManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidassureCustomerIDSeriesCreated()Deprecated.since ages - number series is created during init - there is no need to check each time a new number is fetched!voidassureOrderCodeSeriesCreated()Deprecated.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(java.lang.String key, int digits)Checks digits and ifdigits < 0fetches default digits for given series key.voidcreateEssentialData(java.util.Map params, JspContext jspc)NumberSeriescreateNumberSeries(java.lang.String key, java.lang.String startValue, int type)Deprecated.since 5.0 - please usecreateNumberSeries(String, String, int, int, String)instead.NumberSeriescreateNumberSeries(java.lang.String key, java.lang.String startValue, int type, int digits)Deprecated.since 5.0 - please usecreateNumberSeries(String, String, int, int, String).NumberSeriescreateNumberSeries(java.lang.String key, java.lang.String startValue, int type, int digits, java.lang.String template)Creates a new number series, sets the given start value viasetStartValue(String, String)and the given digits viasetDigits(String, int)persistent.java.util.CollectiongetAllNumberSeries()Makes a snapshot of all number series currently existing in the database.java.util.Collection<java.lang.String>getAllNumberSeriesKeys()Returns all keys where number series exists.intgetDigits(java.lang.String key)Returns the configured digits for the given number series.static NumberSeriesManagergetInstance()Gets the instance of this manager.NumberSeriesgetNumberSeries(java.lang.String key)Makes a snapshot of the number series linked to the given key.NumberSeriesgetOrCreateCustomerIDSeries()Returns standard number series for customer IDs.NumberSeriesgetOrCreateOrderCodeSeries()Returns standard number series for order codes.java.lang.StringgetStartValue(java.lang.String key)Returns the original start value of the given series.java.lang.StringgetUniqueNumber(java.lang.String key)Returns a unique number for a given number series key.java.lang.StringgetUniqueNumber(java.lang.String key, int digits)Returns a unique number for a given series key and a digit length.NumberSeriesgetUniqueNumberUnformatted(java.lang.String key)Returns the unique number object rather than its formatted representation (seegetUniqueNumber(String, int).booleanisCreatorDisabled()Part ofDataCreatorinterface.protected voidnotifyItemRemoval(SessionContext ctx, Item item)Superclass method overridden to avoid calls to ejb layer.voidremoveDigits(java.lang.String key)Removes the digits setting from NumberSeriesManager for the given series.voidremoveNumberSeries(java.lang.String key)Removes a number series and removes the digits and start value setting for this series.voidremoveStartValue(java.lang.String key)Removes the original start value property and value.voidresetNumberSeries(java.lang.String key, java.lang.String startValue, int type)Deprecated.since 5.0 - please useresetNumberSeries(String, String, int, String).voidresetNumberSeries(java.lang.String key, java.lang.String startValue, int type, java.lang.String template)Resets the number series with the given key to the given start value and type.voidsetDigits(java.lang.String key, int digits)Saves the digits for the given number series.voidsetStartValue(java.lang.String key, java.lang.String startvalue)Changes the original start value of the given series.java.lang.ObjectwriteReplace()-
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 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
-
-
Method Detail
-
getInstance
public static NumberSeriesManager 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
protected void notifyItemRemoval(SessionContext ctx, Item item)
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
public java.lang.String getUniqueNumber(java.lang.String key, int digits) throws JaloInvalidParameterExceptionReturns 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 ifdigits < 0fetches default digits for given series key.- Parameters:
key- the series keydigits- the given digits
-
getUniqueNumber
public java.lang.String getUniqueNumber(java.lang.String key) throws JaloInvalidParameterExceptionReturns 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 (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
public void removeNumberSeries(java.lang.String key) throws JaloInvalidParameterExceptionRemoves 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(java.lang.String key, java.lang.String startValue, int type) throws JaloInvalidParameterExceptionDeprecated.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(java.lang.String key, java.lang.String startValue, int type, int digits, java.lang.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(java.lang.String key, java.lang.String startValue, int type, int digits) throws JaloInvalidParameterExceptionDeprecated.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
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
NumberSeriesobjects or an empty list.
-
getNumberSeries
public NumberSeries getNumberSeries(java.lang.String key) throws JaloInvalidParameterException
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(java.lang.String key, java.lang.String startValue, int type) throws JaloInvalidParameterExceptionDeprecated.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(java.lang.String key, java.lang.String startValue, int type, java.lang.String template) throws JaloInvalidParameterExceptionResets 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
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 callresetNumberSeries(String, String, int). Therefore you can use thegetStartValue(String)method.- Parameters:
key- the series key, must not benullstartvalue- 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 theresetNumberSeries(String, String, int)method.- Parameters:
key- the series key, must not benull- 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 benull
-
isCreatorDisabled
public boolean isCreatorDisabled()
Part ofDataCreatorinterface. Returnstrue.- 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 keyNumberSeriesConstants.Series.CUSTOMER_IDis 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 keyNumberSeriesConstants.Series.ORDER_CODEis 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:
writeReplacein classManager- Throws:
java.io.ObjectStreamException
-
-