Package org.fastnate.generator.context
Class EntityProperty<E,T>
java.lang.Object
org.fastnate.generator.context.Property<E,T>
org.fastnate.generator.context.SingularProperty<E,T>
org.fastnate.generator.context.EntityProperty<E,T>
- Type Parameters:
E- The type of the container entityT- The type of the target entity
Describes a property of an
EntityClass that references exactly one other entity.- Author:
- Tobias Liefke
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classHelper for evaluating correct mapping information from the annotations. -
Constructor Summary
ConstructorsConstructorDescriptionEntityProperty(GeneratorContext context, GeneratorTable containerTable, AttributeAccessor attribute, jakarta.persistence.AssociationOverride override) Creates a new instance ofEntityProperty. -
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.protected EntityProperty.MappingInformationfindEntityMappingInformation(AttributeAccessor attribute) Builds the mapping information for a reference to an entity.Collection<?> findReferencedEntities(E entity) Finds all entities in the current property, that are referenced.voidgeneratePendingStatements(StatementsWriter writer, E entity, Object writtenEntity, Object... arguments) Generates the update statements for an entity that are required after another entity was generated.The description of the join column.The current context.getExpression(E entity, boolean whereExpression) Creates the expression for the current value of the given entity in SQL.The name of the id for referencing an embedded id.The opposite property of a bidirectional mapping.The optional name of a property in the target type, that owns the relationship.getPredicate(E entity) Creates an SQL predicate that references all entities that have the same value as the given entity.The description of the type of this property.booleanIndicates that, according to theCascadeType, we should remove the target entity when the current entity is removed.static booleanisEntityProperty(AttributeAccessor attribute) Indicates that the given attribute references a single entity and may be used by anEntityProperty.booleanIndicates, that this property needs a value.booleanIndicates that this property maps to a column from the parent table.protected voidwriteColumnExpression(TableStatement statement, T value, ColumnExpression expression) Writes the column expression to the statement.Methods inherited from class org.fastnate.generator.context.Property
createPostInsertStatements, createPreInsertStatements, failIfRequired, getAttribute, getName, getType, getValue, isComposition, setValue, toString
-
Constructor Details
-
EntityProperty
public EntityProperty(GeneratorContext context, GeneratorTable containerTable, AttributeAccessor attribute, jakarta.persistence.AssociationOverride override) Creates a new instance ofEntityProperty.- Parameters:
context- the generator context.containerTable- the table that contains our columnattribute- the accessor of the attributeoverride- optionalAssociationOverrideconfiguration
-
-
Method Details
-
isEntityProperty
Indicates that the given attribute references a single entity and may be used by anEntityProperty.- Parameters:
attribute- accessor of the attribute to check- Returns:
trueif anEntityPropertymay be created for the given attribute
-
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 classProperty<E,T> - Parameters:
statement- the created statemententity- the inspected entity
-
findEntityMappingInformation
protected EntityProperty.MappingInformation findEntityMappingInformation(AttributeAccessor attribute) Builds the mapping information for a reference to an entity.- Parameters:
attribute- accessor to the represented attribute- Returns:
- the mapping information
-
findReferencedEntities
Description copied from class:PropertyFinds all entities in the current property, that are referenced.- Overrides:
findReferencedEntitiesin classProperty<E,T> - Parameters:
entity- the inspected entity- Returns:
- all referenced entities
-
generatePendingStatements
public void generatePendingStatements(StatementsWriter writer, E entity, Object writtenEntity, Object... arguments) throws IOException Description copied from class:PropertyGenerates the update statements for an entity that are required after another entity was generated. Only called, ifEntityClass.markPendingUpdates(E, V, org.fastnate.generator.context.Property<V, ?>, java.lang.Object...)was called before forwrittenEntity- Overrides:
generatePendingStatementsin classProperty<E,T> - Parameters:
writer- the target of the generated statementsentity- the entity that needs to be updatedwrittenEntity- the entity that exists now in the databasearguments- additional arguments that where given to markPendingUpdates- Throws:
IOException- if the writer throws one
-
getExpression
Description copied from class:PropertyCreates the expression for the current value of the given entity in SQL.- Overrides:
getExpressionin classProperty<E,T> - Parameters:
entity- the entitywhereExpression- indicates that the expression is used in a "where" statement- Returns:
- the expression for the value of this property or
nullif no exists
-
getPredicate
Description copied from class:PropertyCreates an SQL predicate that references all entities that have the same value as the given entity. Used to reference entites by their (unique) properties or ids.- Overrides:
getPredicatein classProperty<E,T> - Parameters:
entity- the entity- Returns:
- the predicate for the value of that entity or
nullif no such expression is available
-
isTableColumn
public boolean isTableColumn()Description copied from class:PropertyIndicates that this property maps to a column from the parent table.- Overrides:
isTableColumnin classSingularProperty<E,T> - Returns:
trueifProperty.addInsertExpression(org.fastnate.generator.statements.TableStatement, E)will add the corresponding value to the given statement
-
writeColumnExpression
protected void writeColumnExpression(TableStatement statement, T value, ColumnExpression expression) Writes the column expression to the statement.- Parameters:
statement- the current statementvalue- the written valueexpression- the expression of the value
-
getContext
The current context. -
getTargetClass
The description of the type of this property. -
isRequired
public boolean isRequired()Indicates, that this property needs a value.- Overrides:
isRequiredin classProperty<E,T> - Returns:
trueif the field is required
-
isComposition
public boolean isComposition()Indicates that, according to theCascadeType, we should remove the target entity when the current entity is removed. -
getMappedBy
The optional name of a property in the target type, that owns the relationship.- See Also:
-
getInverseProperty
The opposite property of a bidirectional mapping. -
getColumn
The description of the join column.- Specified by:
getColumnin classSingularProperty<E,T> - Returns:
- the column name
-
getIdField
The name of the id for referencing an embedded id.
-