Package org.fastnate.generator.context
Class GeneratedIdProperty<E,T extends Number>
java.lang.Object
org.fastnate.generator.context.Property<E,T>
org.fastnate.generator.context.SingularProperty<E,T>
org.fastnate.generator.context.PrimitiveProperty<E,T>
org.fastnate.generator.context.GeneratedIdProperty<E,T>
- Type Parameters:
E- The type of the container classT- The type of the property
Describes an
Id property of an EntityClass.- Author:
- Tobias Liefke
-
Constructor Summary
ConstructorsConstructorDescriptionGeneratedIdProperty(EntityClass<E> entityClass, AttributeAccessor attribute, jakarta.persistence.Column column) Creates a new instance ofGeneratedIdProperty. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInsertExpression(TableStatement statement, E entity) Adds an expression according to the current value of the property for the given entity to an SQL insert statement.voidcreatePreInsertStatements(StatementsWriter writer, E entity) Creates SQL statements that are necessary before this property is written (e.g. for updating the table generator).The entity class that contains our property.getExpression(E entity, boolean whereExpression) Creates the reference of an entity in SQL using its (relative or absolute) id.The generator used for generating new values of this property.getType()The type of the numbers.Marker for the ID of an entity which needs to be referenced by its unique properties.booleanShortcut for the inverse ofGeneratorContext.isWriteRelativeIds().booleanIndicates that the given entity needs to be written.booleanIndicates that the ID is never "null", because we have a primitive ID value.booleanisReference(E entity) Indicates that the given entity was not written before, but exists already in the database.voidmarkReference(E entity) Marks an entity as reference, where we don't know the ID database.voidmarkReference(E entity, T id) Marks an entity as reference, where we know the id in the database.voidpostInsert(E entity) Called after the insert statement was written, to update any nessecary state in the context.Methods inherited from class org.fastnate.generator.context.PrimitiveProperty
getColumn, getContext, getConverter, getDefaultValue, getDefaultValue, getDialect, getPredicate, getTable, isRequiredMethods inherited from class org.fastnate.generator.context.SingularProperty
isTableColumnMethods inherited from class org.fastnate.generator.context.Property
createPostInsertStatements, failIfRequired, findReferencedEntities, generatePendingStatements, getAttribute, getName, getValue, isComposition, setValue, toString
-
Constructor Details
-
GeneratedIdProperty
public GeneratedIdProperty(EntityClass<E> entityClass, AttributeAccessor attribute, jakarta.persistence.Column column) Creates a new instance ofGeneratedIdProperty.- Parameters:
entityClass- the entity classattribute- the accessor of the id attributecolumn- the column annotation
-
-
Method Details
-
addInsertExpression
Description copied from class:PropertyAdds an expression according to the current value of the property for the given entity to an SQL insert statement.- Overrides:
addInsertExpressionin classPrimitiveProperty<E,T extends Number> - Parameters:
statement- the created statemententity- the inspected entity
-
createPreInsertStatements
Description copied from class:PropertyCreates SQL statements that are necessary before this property is written (e.g. for updating the table generator).- Overrides:
createPreInsertStatementsin classProperty<E,T extends Number> - Parameters:
writer- the target of the created statementsentity- the inspected entity- Throws:
IOException- if the writer throws an exception
-
getExpression
Creates the reference of an entity in SQL using its (relative or absolute) id.- Overrides:
getExpressionin classPrimitiveProperty<E,T extends Number> - Parameters:
entity- the entitywhereExpression- indicates that the reference is used in a "where" statement- Returns:
- the expression for the ID of that entity or
nullif the entity was not written up to now - Throws:
IllegalArgumentException- if the entity is areferencewithout any id
-
isNew
Indicates that the given entity needs to be written.- Parameters:
entity- the entity to check- Returns:
trueif the id of the given entity is not set up to now
-
isReference
Indicates that the given entity was not written before, but exists already in the database.- Parameters:
entity- the entity to check- Returns:
trueif the entity wasmarked as reference
-
markReference
Marks an entity as reference, where we don't know the ID database. A reference is not written during SQL generation, because it exists already in the database when the script is executed. As we don't know the ID during build time we have to reference it using some unique properties.- Parameters:
entity- the entity to mark
-
markReference
Marks an entity as reference, where we know the id in the database. A reference is not written during SQL generation, because it exists already in the database when the script is executed.- Parameters:
entity- the entity to markid- the id of the entity in the database
-
postInsert
Called after the insert statement was written, to update any nessecary state in the context.- Parameters:
entity- the current entity
-
isAbsoluteIds
public boolean isAbsoluteIds()Shortcut for the inverse ofGeneratorContext.isWriteRelativeIds(). -
isPrimitive
public boolean isPrimitive()Indicates that the ID is never "null", because we have a primitive ID value. -
getEntityClass
The entity class that contains our property. -
getType
The type of the numbers. -
getUnknownIdMarker
Marker for the ID of an entity which needs to be referenced by its unique properties. -
getGenerator
The generator used for generating new values of this property.
-