Class PersistentKeyGenerator
- java.lang.Object
-
- de.hybris.platform.servicelayer.keygenerator.impl.PersistentKeyGenerator
-
- All Implemented Interfaces:
KeyGenerator
- Direct Known Subclasses:
PrefixablePersistentKeyGenerator,PrefixablePersistentKeyGenerator
public class PersistentKeyGenerator extends java.lang.Object implements KeyGenerator
This implementation is an adapter to theNumberSeriesfunctionality of the platform for getting unique numbers in a series persisted via database. It provides several setter methods for configuration of the used number series like the key of the series at database. It is lazily initialized on first call.- Since:
- 4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPersistentKeyGenerator.Type
-
Field Summary
Fields Modifier and Type Field Description protected intdigitsAmount of digits used for one key.protected java.lang.StringkeyKey of series.protected booleannumericIs the series numeric or alpha-numeric?protected java.lang.StringstartStart value for series (used in case the series is not created yet and at a reset).protected java.lang.StringtemplateTemplate to be applied on generated value
-
Constructor Summary
Constructors Constructor Description PersistentKeyGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected NumberSeriescreateSeriesAfterLookupError(NumberSeriesManager nsm)java.lang.Objectgenerate()Generates a new unique key.java.lang.ObjectgenerateFor(java.lang.Object object)Generates a new unique key in relation to given object.voidinit()Deprecated.since 5.0 favour lazy initialization while fetching the sequence for the first timevoidinitializeKeyGenerator()protected NumberSerieslookup(NumberSeriesManager nsm)voidreset()Resets the key generation so that an already generated key can be generated once again.voidsetDigits(int digits)Sets the amount of digits within one generated key.voidsetKey(java.lang.String key)Sets the key of the number series to use.voidsetNumeric(boolean numeric)Deprecated.since ages - usesetType(de.hybris.platform.servicelayer.keygenerator.impl.PersistentKeyGenerator.Type)instead.voidsetStart(java.lang.String start)voidsetTemplate(java.lang.String template)Sets the template of the number series to use.voidsetType(PersistentKeyGenerator.Type type)Sets type of the key generator.
-
-
-
Field Detail
-
key
protected java.lang.String key
Key of series.
-
digits
protected int digits
Amount of digits used for one key.
-
start
protected java.lang.String start
Start value for series (used in case the series is not created yet and at a reset).
-
template
protected java.lang.String template
Template to be applied on generated value
-
numeric
protected boolean numeric
Is the series numeric or alpha-numeric?
-
-
Method Detail
-
initializeKeyGenerator
@PostConstruct public void initializeKeyGenerator()
-
generate
public java.lang.Object generate()
Description copied from interface:KeyGeneratorGenerates a new unique key. If this method is called twice it will never return the same key twice (if key A is returned by first call and key B by second call, A does not equals B). A order of returned keys is not guaranteed (depends on implementation). After a call of theKeyGenerator.reset()method the generator is reseted so that a key can be returned which already was returned before callingKeyGenerator.reset().- Specified by:
generatein interfaceKeyGenerator- Returns:
- unique key
-
generateFor
public java.lang.Object generateFor(java.lang.Object object)
Description copied from interface:KeyGeneratorGenerates a new unique key in relation to given object. The key will be unique overall as inKeyGenerator.generate()method and furthermore it is guaranteed that the key will only be produced for this object (think of a PK which contains the type information, a media PK will not be generated for a product, nevertheless it is unique overall).- Specified by:
generateForin interfaceKeyGenerator- Parameters:
object- object for which a key will be generated- Returns:
- unique key in relation to given object
-
reset
public void reset()
Description copied from interface:KeyGeneratorResets the key generation so that an already generated key can be generated once again.- Specified by:
resetin interfaceKeyGenerator
-
init
@Deprecated public void init()
Deprecated.since 5.0 favour lazy initialization while fetching the sequence for the first timeChecks if a number series with configured key is already existent and creates a new one if not using configured start value.
-
lookup
protected NumberSeries lookup(NumberSeriesManager nsm) throws JaloInvalidParameterException
- Throws:
JaloInvalidParameterException
-
createSeriesAfterLookupError
protected NumberSeries createSeriesAfterLookupError(NumberSeriesManager nsm)
-
setTemplate
public void setTemplate(java.lang.String template)
Sets the template of the number series to use.- Parameters:
template- number series template
-
setKey
public void setKey(java.lang.String key)
Sets the key of the number series to use.- Parameters:
key- number series key
-
setDigits
public void setDigits(int digits)
Sets the amount of digits within one generated key.- Parameters:
digits- amount of digits
-
setStart
public void setStart(java.lang.String start)
Sets the start value for the series in case the series has to be created new at call ofinit()or at areset().- Parameters:
start- start value
-
setNumeric
@Deprecated public void setNumeric(boolean numeric)
Deprecated.since ages - usesetType(de.hybris.platform.servicelayer.keygenerator.impl.PersistentKeyGenerator.Type)instead.Sets if the series is numeric or alpha-numeric in case the series has to be created new at call ofinit()or at areset().- Parameters:
numeric- is the series numeric?
-
setType
public void setType(PersistentKeyGenerator.Type type)
Sets type of the key generator. Available type are: alphanumeric, numeric and uuid. Alphanumeric and numeric series handling is delegated toNumberSeries- Parameters:
type- type of key generator
-
-