public class SequenceIdGenerator extends IdGenerator
SequenceGenerator
.Modifier and Type | Field and Description |
---|---|
private int |
allocationSize
The amount to increment by when allocating sequence numbers from the sequence.
|
private String |
catalog
The (optional) catalog that contains the schema of the sequence.
|
private long |
currentSequenceValue |
private GeneratorDialect |
dialect
The current database dialect.
|
private long |
initialValue
The value from which the sequence object is to start generating.
|
private long |
nextValue |
private String |
qualifiedName
The fully qualfied name of the sequence, including the optional catalog and schema name.
|
private boolean |
relativeIds
Indicates that the sequence is used when referencing existing IDs, instead of absolute IDs.
|
private String |
schema
The (optional) schema that contains the sequence.
|
private String |
sequenceName
The name of the sequence.
|
Constructor and Description |
---|
SequenceIdGenerator(javax.persistence.SequenceGenerator generator,
GeneratorDialect dialect,
boolean relativeIds)
Creates a new instance of
SequenceIdGenerator . |
Modifier and Type | Method and Description |
---|---|
void |
addNextValue(TableStatement statement,
GeneratorColumn column,
Number value)
Adds the generated value to the given statement.
|
void |
alignNextValue(StatementsWriter writer)
Creates all statements that are necessary to set the next value created from the database is
currentValue + 1 . |
long |
createNextValue()
Resolves the next value of this generator.
|
void |
createPreInsertStatements(StatementsWriter writer)
Creates the statements that are needed in the output before
IdGenerator.addNextValue(TableStatement, GeneratorColumn, Number) . |
int |
getAllocationSize()
The amount to increment by when allocating sequence numbers from the sequence.
|
String |
getCatalog()
The (optional) catalog that contains the schema of the sequence.
|
long |
getCurrentValue()
The last value returned by
IdGenerator.createNextValue(Class) . |
GeneratorDialect |
getDialect()
The current database dialect.
|
ColumnExpression |
getExpression(GeneratorTable entityTable,
GeneratorColumn column,
Number targetId,
boolean whereExpression)
Builds the reference to another entity that has the given ID.
|
long |
getInitialValue()
The value from which the sequence object is to start generating.
|
String |
getQualifiedName()
The fully qualfied name of the sequence, including the optional catalog and schema name.
|
String |
getSchema()
The (optional) schema that contains the sequence.
|
String |
getSequenceName()
The name of the sequence.
|
boolean |
isPostIncrement()
Indicates that
IdGenerator.createNextValue(Class) should be called after the entity was written - as the value is
not available before. |
boolean |
isRelativeIds()
Indicates that the sequence is used when referencing existing IDs, instead of absolute IDs.
|
void |
setCurrentValue(long currentValue)
Sets a new start value.
|
createNextValue, derive
private final GeneratorDialect dialect
private final String catalog
private final String schema
private final String sequenceName
private final String qualifiedName
private final boolean relativeIds
private final int allocationSize
private long initialValue
private long nextValue
private long currentSequenceValue
public SequenceIdGenerator(javax.persistence.SequenceGenerator generator, GeneratorDialect dialect, boolean relativeIds)
SequenceIdGenerator
.generator
- the annotation that contains our settingsdialect
- the current database dialectrelativeIds
- indicates that the sequence is always used, instead of absolute IDspublic void addNextValue(TableStatement statement, GeneratorColumn column, Number value)
IdGenerator
addNextValue
in class IdGenerator
statement
- the current insert statementcolumn
- the ID column of the current tablevalue
- the current value of the column, previously generated with IdGenerator.createNextValue()
public void alignNextValue(StatementsWriter writer) throws IOException
IdGenerator
currentValue + 1
.alignNextValue
in class IdGenerator
writer
- the target of the created statementsIOException
- if the writer throws onepublic long createNextValue()
IdGenerator
createNextValue
in class IdGenerator
public void createPreInsertStatements(StatementsWriter writer) throws IOException
IdGenerator
IdGenerator.addNextValue(TableStatement, GeneratorColumn, Number)
.createPreInsertStatements
in class IdGenerator
writer
- target for the created statementsIOException
- if the writer throws onepublic long getCurrentValue()
IdGenerator
IdGenerator.createNextValue(Class)
.getCurrentValue
in class IdGenerator
public ColumnExpression getExpression(GeneratorTable entityTable, GeneratorColumn column, Number targetId, boolean whereExpression)
IdGenerator
getExpression
in class IdGenerator
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 situationpublic boolean isPostIncrement()
IdGenerator
IdGenerator.createNextValue(Class)
should be called after the entity was written - as the value is
not available before.isPostIncrement
in class IdGenerator
true
if the database increments the value _after_ the insert statement was executed, true
if it is incremented before or during the executionpublic void setCurrentValue(long currentValue)
IdGenerator
setCurrentValue
in class IdGenerator
currentValue
- the current value - most likely as extracted from the target database@Generated(value="lombok") public GeneratorDialect getDialect()
@Generated(value="lombok") public String getCatalog()
@Generated(value="lombok") public String getSchema()
@Generated(value="lombok") public String getSequenceName()
@Generated(value="lombok") public String getQualifiedName()
@Generated(value="lombok") public boolean isRelativeIds()
@Generated(value="lombok") public int getAllocationSize()
@Generated(value="lombok") public long getInitialValue()
Copyright © 2022 fastnate.org. All rights reserved.