public class SmartSequenceStrategy extends Object implements SequenceStrategy
SQLSequenceStrategy
or MongoSequenceStrategy
based on the available configuration.
This is the standard strategy which determines if a JDBC database is present or a MongoDB and pick the effective strategy accordingly.
Constructor and Description |
---|
SmartSequenceStrategy() |
Modifier and Type | Method and Description |
---|---|
void |
collectKnownSequences(Consumer<String> nameConsumer)
Enumerates the names of all known sequences.
|
String |
getName() |
long |
peekNextValue(String sequence)
Peeks at the next value in the sequence without using it.
|
void |
setNextValue(String sequence,
long nextValue,
boolean force)
Specifies the next value to use for the given sequence.
|
Long |
tryGenerateId(String sequence)
Tries to generate the next id in the given sequence.
|
@Nonnull public String getName()
getName
in interface sirius.kernel.di.std.Named
public Long tryGenerateId(String sequence) throws Exception
SequenceStrategy
tryGenerateId
in interface SequenceStrategy
sequence
- the sequence to generate the next id forException
- in case of a severe errorpublic long peekNextValue(String sequence) throws Exception
SequenceStrategy
peekNextValue
in interface SequenceStrategy
sequence
- the sequence to determine the next value forException
- in case of a severe errorSequences.peekNextValue(String)
public void setNextValue(String sequence, long nextValue, boolean force) throws Exception
SequenceStrategy
Unless force is set to true, the value has to be higher than the current counter value to prevent non unique numbers from being generated.
setNextValue
in interface SequenceStrategy
sequence
- the sequence to updatenextValue
- the next value that will be returned when calling SequenceStrategy.tryGenerateId(String)
for this
sequence.force
- if true, no sanity checks are performed and the sequence can be reset to ANY
value. This is rather dangerous, as it might lead to the generation of duplicate ids. If
set to false, the given nextValue has to be higher than the current sequence
value.Exception
- in case or a severe errorpublic void collectKnownSequences(Consumer<String> nameConsumer) throws Exception
SequenceStrategy
collectKnownSequences
in interface SequenceStrategy
nameConsumer
- the consumer to be supplied with the namesException
- in case or a severe errorCopyright © 2018. All rights reserved.