public class SQLSequenceStrategy extends Object implements SequenceStrategy
Sequences
Modifier and Type | Field and Description |
---|---|
static String |
TYPE
Contains the name of this strategy.
|
Constructor and Description |
---|
SQLSequenceStrategy() |
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.
|
public static final String TYPE
@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)
SequenceStrategy
peekNextValue
in interface SequenceStrategy
sequence
- the sequence to determine the next value forSequences.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.