Package org.fastnate.generator.context
Class SequenceIdGenerator
java.lang.Object
org.fastnate.generator.context.IdGenerator
org.fastnate.generator.context.SequenceIdGenerator
Stores the current value for a
SequenceGenerator.- Author:
- Tobias Liefke
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe amount to increment by when allocating sequence numbers from the sequence.private final StringThe (optional) catalog that contains the schema of the sequence.private longprivate final GeneratorDialectThe current database dialect.private longThe value from which the sequence object is to start generating.private longprivate final StringThe fully qualfied name of the sequence, including the optional catalog and schema name.private final booleanIndicates that the sequence is used when referencing existing IDs, instead of absolute IDs.private final StringThe (optional) schema that contains the sequence.private final StringThe name of the sequence. -
Constructor Summary
ConstructorsConstructorDescriptionSequenceIdGenerator(jakarta.persistence.SequenceGenerator generator, GeneratorContext context) Creates a new instance ofSequenceIdGenerator. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNextValue(TableStatement statement, GeneratorColumn column, Number value) Adds the generated value to the given statement.voidalignNextValue(StatementsWriter writer) Creates all statements that are necessary to set the next value created from the database iscurrentValue + 1.longResolves the next value of this generator.voidCreates the statements that are needed in the output beforeIdGenerator.addNextValue(TableStatement, GeneratorColumn, Number).intThe amount to increment by when allocating sequence numbers from the sequence.The (optional) catalog that contains the schema of the sequence.longThe last value returned byIdGenerator.createNextValue(Class).The current database dialect.getExpression(GeneratorTable entityTable, GeneratorColumn column, Number targetId, boolean whereExpression) Builds the reference to another entity that has the given ID.longThe value from which the sequence object is to start generating.The fully qualfied name of the sequence, including the optional catalog and schema name.The (optional) schema that contains the sequence.The name of the sequence.booleanIndicates thatIdGenerator.createNextValue(Class)should be called after the entity was written - as the value is not available before.booleanIndicates that the sequence is used when referencing existing IDs, instead of absolute IDs.voidsetCurrentValue(long currentValue) Sets a new start value.Methods inherited from class org.fastnate.generator.context.IdGenerator
createNextValue, derive
-
Field Details
-
dialect
The current database dialect. -
catalog
The (optional) catalog that contains the schema of the sequence. -
schema
The (optional) schema that contains the sequence. -
sequenceName
The name of the sequence. -
qualifiedName
The fully qualfied name of the sequence, including the optional catalog and schema name. -
relativeIds
private final boolean relativeIdsIndicates that the sequence is used when referencing existing IDs, instead of absolute IDs. -
allocationSize
private final int allocationSizeThe amount to increment by when allocating sequence numbers from the sequence. -
initialValue
private long initialValueThe value from which the sequence object is to start generating. -
nextValue
private long nextValue -
currentSequenceValue
private long currentSequenceValue
-
-
Constructor Details
-
SequenceIdGenerator
public SequenceIdGenerator(jakarta.persistence.SequenceGenerator generator, GeneratorContext context) Creates a new instance ofSequenceIdGenerator.- Parameters:
generator- the annotation that contains our settingscontext- the current context
-
-
Method Details
-
addNextValue
Description copied from class:IdGeneratorAdds the generated value to the given statement. Depending on the generator this may add the value itself or a reference to the value.- Specified by:
addNextValuein classIdGenerator- Parameters:
statement- the current insert statementcolumn- the ID column of the current tablevalue- the current value of the column, previously generated withIdGenerator.createNextValue()
-
alignNextValue
Description copied from class:IdGeneratorCreates all statements that are necessary to set the next value created from the database iscurrentValue + 1.- Specified by:
alignNextValuein classIdGenerator- Parameters:
writer- the target of the created statements- Throws:
IOException- if the writer throws one
-
createNextValue
public long createNextValue()Description copied from class:IdGeneratorResolves the next value of this generator.- Specified by:
createNextValuein classIdGenerator- Returns:
- the generated value
-
createPreInsertStatements
Description copied from class:IdGeneratorCreates the statements that are needed in the output beforeIdGenerator.addNextValue(TableStatement, GeneratorColumn, Number).- Overrides:
createPreInsertStatementsin classIdGenerator- Parameters:
writer- target for the created statements- Throws:
IOException- if the writer throws one
-
getCurrentValue
public long getCurrentValue()Description copied from class:IdGeneratorThe last value returned byIdGenerator.createNextValue(Class).- Specified by:
getCurrentValuein classIdGenerator- Returns:
- the current value
-
getExpression
public ColumnExpression getExpression(GeneratorTable entityTable, GeneratorColumn column, Number targetId, boolean whereExpression) Description copied from class:IdGeneratorBuilds the reference to another entity that has the given ID.- Specified by:
getExpressionin classIdGenerator- Parameters:
entityTable- the main table of the entitycolumn- the name of the column of the IDtargetId- the current value of the IDwhereExpression- indicates if this expression is needed for a "SELECT ... WHERE ..." - some dialects behave differently in this situation- Returns:
- the expression for selecting the ID
-
isPostIncrement
public boolean isPostIncrement()Description copied from class:IdGeneratorIndicates thatIdGenerator.createNextValue(Class)should be called after the entity was written - as the value is not available before.- Specified by:
isPostIncrementin classIdGenerator- Returns:
trueif the database increments the value _after_ the insert statement was executed,trueif it is incremented before or during the execution
-
setCurrentValue
public void setCurrentValue(long currentValue) Description copied from class:IdGeneratorSets a new start value.- Specified by:
setCurrentValuein classIdGenerator- Parameters:
currentValue- the current value - most likely as extracted from the target database
-
getDialect
The current database dialect. -
getCatalog
The (optional) catalog that contains the schema of the sequence. -
getSchema
The (optional) schema that contains the sequence. -
getSequenceName
The name of the sequence. -
getQualifiedName
The fully qualfied name of the sequence, including the optional catalog and schema name. -
isRelativeIds
public boolean isRelativeIds()Indicates that the sequence is used when referencing existing IDs, instead of absolute IDs. -
getAllocationSize
public int getAllocationSize()The amount to increment by when allocating sequence numbers from the sequence. -
getInitialValue
public long getInitialValue()The value from which the sequence object is to start generating.
-