Package org.fastnate.generator.context
Class PluralProperty<E,C,T>
java.lang.Object
org.fastnate.generator.context.Property<E,C>
org.fastnate.generator.context.PluralProperty<E,C,T>
- Type Parameters:
E- The type of the container classC- The type of the collection or mapT- The type of the elements in the collection
- Direct Known Subclasses:
CollectionProperty,MapProperty
Base class for
MapProperty and CollectionProperty.- Author:
- Tobias Liefke
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classHelper for evaluating correct mapping information from the annotations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPluralProperty(EntityClass<?> sourceClass, AttributeAccessor attribute, jakarta.persistence.AssociationOverride associationOverride, jakarta.persistence.AttributeOverride attributeOverride, int valueClassParamIndex) Creates a new property. -
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 voidbuildEmbeddedProperties(EntityClass<?> sourceClass, Class<?> targetType) Builds the embedded properties of this property.protected static StringbuildIdColumn(AttributeAccessor attribute, jakarta.persistence.AssociationOverride override, jakarta.persistence.CollectionTable collectionMetadata, String defaultIdColumn) Builds the name of the column that contains the ID of the entity for the given attribute.protected voidcreateDirectValueStatement(StatementsWriter writer, E entity, ColumnExpression sourceId, ColumnExpression key, T value) Creates the statements for a (not embeddable) value from the collection.protected ColumnExpressioncreateValueExpression(E entity, ColumnExpression sourceId, T value, ColumnExpression key) Creates a SQL expression for a value of the collection, as long as it is not embedded.protected voidcreateValueStatement(StatementsWriter writer, E entity, ColumnExpression sourceId, ColumnExpression key, T value) Adds a value statement to the list of collection statements.protected PluralProperty.EntityMappingInformationfindEntityMappingInformation(AttributeAccessor attribute, jakarta.persistence.AssociationOverride associationOverride, int valueClassParamIndex) Builds the mapping information for a entity collection.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 current context.The current database dialect, as defined in the context.Contains all properties of an embedded element collection.Contains all properties of an embedded element collection by their name.The column that contains the id of the entity.The opposite property of a bidirectional mapping.protected abstract GeneratorColumnAn optional column that contains the index / key of the values.Indicates that this property is defined by another property on the target type.The property to use, if an id is embedded.protected static <T> Class<T> getPropertyArgument(AttributeAccessor attribute, Class<T> explicitClass, int argumentIndex) Inspects the given attribute and searches for a generic type argument.List<EntityProperty<T, ?>> Contains all properties of an embedded element collection which reference a required entity.getTable()The modified table.The class of the value of the collection.The column that contains the value (or the id of the value).The noargs constructor for the values of the collection.The converter for the value of the collection,nullif not a primitive value.The description of thevalueClass,nullif not an entity (or something provider specific).protected static booleanhasPluralAnnotation(AttributeAccessor attribute) Indicates, that the given attribute has an annotation that indicates a plural property.booleanIndicates that, according to theCascadeType, we should remove the target entities when the current entity is removed.booleanIndicates that this propery is aElementCollectionthat referencesEmbeddables.booleanIndicates that entities are referenced by the collection.booleanIndicates if this property is an required field in the database (needs to exist when the insert statement is written).booleanIndicates that this property maps to a column from the parent table.booleanIndicates to use a column of the target table.Tries to create a new instance of an element using the parameter-less constructor.protected voidwriteValueExpression(TableStatement statement, T value, ColumnExpression expression) Writes the value expression to the statement.Methods inherited from class org.fastnate.generator.context.Property
createPostInsertStatements, createPreInsertStatements, failIfRequired, findReferencedEntities, getAttribute, getExpression, getName, getPredicate, getType, getValue, isComposition, setValue, toString
-
Constructor Details
-
PluralProperty
protected PluralProperty(EntityClass<?> sourceClass, AttributeAccessor attribute, jakarta.persistence.AssociationOverride associationOverride, jakarta.persistence.AttributeOverride attributeOverride, int valueClassParamIndex) Creates a new property.- Parameters:
sourceClass- the description of the current inspected class that contains this propertyattribute- accessor to the represented attributeassociationOverride- the configured assocation overrideattributeOverride- the configured attribute override, if we reference anElementCollectionvalueClassParamIndex- the index of the value argument in the collection class (0 forCollection, 1 forMap}
-
-
Method Details
-
buildIdColumn
protected static String buildIdColumn(AttributeAccessor attribute, jakarta.persistence.AssociationOverride override, jakarta.persistence.CollectionTable collectionMetadata, String defaultIdColumn) Builds the name of the column that contains the ID of the entity for the given attribute.- Parameters:
attribute- the accessor for the inspected attributeoverride- contains optional override optionscollectionMetadata- the default join columndefaultIdColumn- the default name for the column, ifjoinColumnis empty ornull- Returns:
- the column name
-
getPropertyArgument
protected static <T> Class<T> getPropertyArgument(AttributeAccessor attribute, Class<T> explicitClass, int argumentIndex) Inspects the given attribute and searches for a generic type argument.- Parameters:
attribute- the attribute to inspectexplicitClass- an explicit class to use, if the metadata specified oneargumentIndex- the index of the argument, for maps there are two: the key and the value- Returns:
- the found class
-
hasPluralAnnotation
Indicates, that the given attribute has an annotation that indicates a plural property.- Parameters:
attribute- the attribute to check- Returns:
trueif one of the plural annotations is defined for the 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,C> - Parameters:
statement- the created statemententity- the inspected entity
-
buildEmbeddedProperties
Builds the embedded properties of this property.- Parameters:
sourceClass- the class that contains our propertytargetType- the target type
-
createDirectValueStatement
protected void createDirectValueStatement(StatementsWriter writer, E entity, ColumnExpression sourceId, ColumnExpression key, T value) throws IOException Creates the statements for a (not embeddable) value from the collection.- Parameters:
writer- the target of created statementsentity- the entity that contains the collection resp. map.sourceId- the ID of the current entitykey- the value of thegetKeyColumn()- either the index or the map keyvalue- the current value in the collection- Throws:
IOException- if the writer throws one
-
createValueExpression
protected ColumnExpression createValueExpression(E entity, ColumnExpression sourceId, T value, ColumnExpression key) Creates a SQL expression for a value of the collection, as long as it is not embedded.- Parameters:
entity- the entity that contains the collectionsourceId- the id of the entity as SQL expressionvalue- the value that is writtenkey- the key/index of the entity in the collection as SQL expression- Returns:
- the expression or
nullif the insert is still pending
-
createValueStatement
protected void createValueStatement(StatementsWriter writer, E entity, ColumnExpression sourceId, ColumnExpression key, T value) throws IOException Adds a value statement to the list of collection statements.- Parameters:
writer- the target of the created statementsentity- the entity that contains the collectionsourceId- the id of the entity as SQL expressionkey- the key/index of the entity in the collection as SQL expressionvalue- the value that is written- Throws:
IOException- if the writer throws one
-
findEntityMappingInformation
protected PluralProperty.EntityMappingInformation findEntityMappingInformation(AttributeAccessor attribute, jakarta.persistence.AssociationOverride associationOverride, int valueClassParamIndex) Builds the mapping information for a entity collection.- Parameters:
attribute- accessor to the represented attributeassociationOverride- the configured assocation overridevalueClassParamIndex- the index of the value argument in the collection class (0 forCollection, 1 forMap}- Returns:
- the mapping information
-
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,C> - 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
-
getKeyColumn
An optional column that contains the index / key of the values.- Returns:
- the key column for map properties resp. the index column for list properties
-
isEmbedded
public boolean isEmbedded()Indicates that this propery is aElementCollectionthat referencesEmbeddables.- Returns:
- true if
getEmbeddedProperties()returns a list of properties
-
isRequired
public boolean isRequired()Description copied from class:PropertyIndicates if this property is an required field in the database (needs to exist when the insert statement is written).- Overrides:
isRequiredin classProperty<E,C> - Returns:
trueif the field is required
-
isTableColumn
public boolean isTableColumn()Description copied from class:PropertyIndicates that this property maps to a column from the parent table.- Specified by:
isTableColumnin classProperty<E,C> - Returns:
trueifProperty.addInsertExpression(org.fastnate.generator.statements.TableStatement, E)will add the corresponding value to the given statement
-
newElement
Tries to create a new instance of an element using the parameter-less constructor.- Returns:
- the new element
-
writeValueExpression
Writes the value expression to the statement.- Parameters:
statement- the current statementvalue- the written valueexpression- the expression of the value
-
getContext
The current context. -
getDialect
The current database dialect, as defined in the context. -
getEmbeddedProperties
Contains all properties of an embedded element collection. -
getEmbeddedPropertiesByName
Contains all properties of an embedded element collection by their name. -
getRequiredEmbeddedProperties
Contains all properties of an embedded element collection which reference a required entity. -
getMappedId
The property to use, if an id is embedded. -
getTable
The modified table. -
getIdColumn
The column that contains the id of the entity. -
isComposition
public boolean isComposition()Indicates that, according to theCascadeType, we should remove the target entities when the current entity is removed. AlwaystrueforElementCollections. -
getMappedBy
Indicates that this property is defined by another property on the target type. -
getInverseProperty
The opposite property of a bidirectional mapping. Can either be anotherPluralProperty(it the relationship is aManyToMany) or anEntityProperty(if the relationship is aOneToMany. -
isUseTargetTable
public boolean isUseTargetTable()Indicates to use a column of the target table. -
getValueColumn
The column that contains the value (or the id of the value). -
getValueClass
The class of the value of the collection. -
getValueConstructor
The noargs constructor for the values of the collection. -
isEntityReference
public boolean isEntityReference()Indicates that entities are referenced by the collection. -
getValueEntityClass
The description of thevalueClass,nullif not an entity (or something provider specific). -
getValueConverter
The converter for the value of the collection,nullif not a primitive value.
-