Package org.fastnate.generator.context
Class IdGenerator
java.lang.Object
org.fastnate.generator.context.IdGenerator
- Direct Known Subclasses:
IdentityValue,SequenceIdGenerator,TableIdGenerator
Saves the current value and increments the value for a
GeneratedIdProperty.- Author:
- Tobias Liefke
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddNextValue(TableStatement statement, GeneratorColumn column, Number nextValue) Adds the generated value to the given statement.abstract voidalignNextValue(StatementsWriter writer) Creates all statements that are necessary to set the next value created from the database iscurrentValue + 1.protected abstract longResolves the next value of this generator.<N extends Number>
NcreateNextValue(Class<N> propertyClass) Resolves the next value of this generator.voidCreates the statements that are needed in the output beforeaddNextValue(TableStatement, GeneratorColumn, Number).derive(GeneratorTable entityTable) Some implementations (like the Hibernate table generator) create a different generator, depending on the table name.abstract longThe last value returned bycreateNextValue(Class).abstract ColumnExpressiongetExpression(GeneratorTable table, GeneratorColumn column, Number id, boolean whereExpression) Builds the reference to another entity that has the given ID.abstract booleanIndicates thatcreateNextValue(Class)should be called after the entity was written - as the value is not available before.abstract voidsetCurrentValue(long currentValue) Sets a new start value.
-
Constructor Details
-
IdGenerator
public IdGenerator()
-
-
Method Details
-
addNextValue
public abstract void addNextValue(TableStatement statement, GeneratorColumn column, Number nextValue) Adds the generated value to the given statement. Depending on the generator this may add the value itself or a reference to the value.- Parameters:
statement- the current insert statementcolumn- the ID column of the current tablenextValue- the current value of the column, previously generated withcreateNextValue()
-
alignNextValue
Creates all statements that are necessary to set the next value created from the database iscurrentValue + 1.- Parameters:
writer- the target of the created statements- Throws:
IOException- if the writer throws one
-
createNextValue
protected abstract long createNextValue()Resolves the next value of this generator.- Returns:
- the generated value
-
createNextValue
Resolves the next value of this generator.- Parameters:
propertyClass- the type of the generated value- Returns:
- the generated value
-
createPreInsertStatements
Creates the statements that are needed in the output beforeaddNextValue(TableStatement, GeneratorColumn, Number).- Parameters:
writer- target for the created statements- Throws:
IOException- if the writer throws one
-
derive
Some implementations (like the Hibernate table generator) create a different generator, depending on the table name.- Parameters:
entityTable- the current entity table- Returns:
- the generator
-
getCurrentValue
public abstract long getCurrentValue()The last value returned bycreateNextValue(Class).- Returns:
- the current value
-
getExpression
public abstract ColumnExpression getExpression(GeneratorTable table, GeneratorColumn column, Number id, boolean whereExpression) Builds the reference to another entity that has the given ID.- Parameters:
table- the main table of the entitycolumn- the name of the column of the IDid- 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 abstract boolean isPostIncrement()Indicates thatcreateNextValue(Class)should be called after the entity was written - as the value is not available before.- Returns:
trueif the database increments the value _after_ the insert statement was executed,trueif it is incremented before or during the execution
-
setCurrentValue
public abstract void setCurrentValue(long currentValue) Sets a new start value.- Parameters:
currentValue- the current value - most likely as extracted from the target database
-