E
- The type of the container classC
- The type of the collection or mapT
- The type of the elements in the collectionpublic abstract class PluralProperty<E,C,T> extends Property<E,C>
MapProperty
and CollectionProperty
.Modifier and Type | Class and Description |
---|---|
private static class |
PluralProperty.EntityMappingInformation
Helper for evaluating correct mapping information from the annotations.
|
Modifier and Type | Field and Description |
---|---|
private AnyMapping<T> |
anyMapping
Contains information about an addition class column, if
ManyToAny is used. |
private boolean |
composition
Indicates that, according to the
CascadeType , we should remove the target entities when the current
entity is removed. |
private GeneratorContext |
context
The current context.
|
private GeneratorDialect |
dialect
The current database dialect, as defined in the context.
|
private List<Property<T,?>> |
embeddedProperties
Contains all properties of an embedded element collection.
|
private Map<String,Property<T,?>> |
embeddedPropertiesByName
Contains all properties of an embedded element collection by their name.
|
private boolean |
entityReference
Indicates that entities are referenced by the collection.
|
private GeneratorColumn |
idColumn
The column that contains the id of the entity.
|
private Property<T,?> |
inverseProperty
The opposite property of a bidirectional mapping.
|
private String |
mappedBy
Indicates that this property is defined by another property on the target type.
|
private String |
mappedId
The property to use, if an id is embedded.
|
private List<EntityProperty<T,?>> |
requiredEmbeddedProperties
Contains all properties of an embedded element collection which reference a required entity.
|
private GeneratorTable |
table
The modified table.
|
private boolean |
useTargetTable
Indicates to use a column of the target table.
|
private Class<T> |
valueClass
The class of the value of the collection.
|
private GeneratorColumn |
valueColumn
The column that contains the value (or the id of the value).
|
private Constructor<T> |
valueConstructor
The noargs constructor for the values of the collection.
|
private ValueConverter<T> |
valueConverter
The converter for the value of the collection,
null if not a primitive value. |
private EntityClass<T> |
valueEntityClass
|
Constructor and Description |
---|
PluralProperty(EntityClass<?> sourceClass,
AttributeAccessor attribute,
javax.persistence.AssociationOverride associationOverride,
javax.persistence.AttributeOverride attributeOverride,
int valueClassParamIndex)
Creates a new property.
|
Modifier and Type | Method and Description |
---|---|
void |
addInsertExpression(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 void |
buildEmbeddedProperties(EntityClass<?> sourceClass,
Class<?> targetType)
Builds the embedded properties of this property.
|
protected static String |
buildIdColumn(AttributeAccessor attribute,
javax.persistence.AssociationOverride override,
javax.persistence.CollectionTable collectionMetadata,
String defaultIdColumn)
Builds the name of the column that contains the ID of the entity for the given attribute.
|
private static String |
buildIdColumn(AttributeAccessor attribute,
javax.persistence.AssociationOverride override,
javax.persistence.JoinColumn[] joinColumns,
String defaultIdColumn) |
private static String |
buildIdColumn(AttributeAccessor attribute,
javax.persistence.AssociationOverride override,
javax.persistence.JoinTable joinTable,
javax.persistence.CollectionTable tableMetadata,
String defaultIdColumn) |
private static GeneratorColumn |
buildValueColumn(GeneratorTable table,
javax.persistence.AssociationOverride asscoiationOverride,
javax.persistence.AttributeOverride attributeOverride,
AttributeAccessor attribute,
String defaultColumnName)
Builds the column that contains the value for the collection / map.
|
protected void |
createDirectValueStatement(StatementsWriter writer,
E entity,
ColumnExpression sourceId,
ColumnExpression key,
T value)
Creates the statements for a (not embeddable) value from the collection.
|
private void |
createEmbeddedValueStatement(StatementsWriter writer,
E entity,
ColumnExpression sourceId,
ColumnExpression key,
T value)
Writes all embedded properties of a value of a collection table.
|
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.
|
protected void |
createValueStatement(StatementsWriter writer,
E entity,
ColumnExpression sourceId,
ColumnExpression key,
T value)
Adds a value statement to the list of collection statements.
|
private static String |
findMappedId(AttributeAccessor attribute) |
private static <T> Constructor<T> |
findValueConstructor(Class<T> valueClass) |
void |
generatePendingStatements(StatementsWriter writer,
E entity,
Object writtenEntity,
Object... arguments)
Generates the update statements for an entity that are required after another entity was generated.
|
AnyMapping<T> |
getAnyMapping()
Contains information about an addition class column, if
ManyToAny is used. |
GeneratorContext |
getContext()
The current context.
|
GeneratorDialect |
getDialect()
The current database dialect, as defined in the context.
|
List<Property<T,?>> |
getEmbeddedProperties()
Contains all properties of an embedded element collection.
|
Map<String,Property<T,?>> |
getEmbeddedPropertiesByName()
Contains all properties of an embedded element collection by their name.
|
GeneratorColumn |
getIdColumn()
The column that contains the id of the entity.
|
Property<T,?> |
getInverseProperty()
The opposite property of a bidirectional mapping.
|
private static String |
getJoinColumnName(javax.persistence.JoinColumn[] joinColumns) |
protected abstract GeneratorColumn |
getKeyColumn()
An optional column that contains the index / key of the values.
|
String |
getMappedBy()
Indicates that this property is defined by another property on the target type.
|
String |
getMappedId()
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,?>> |
getRequiredEmbeddedProperties()
Contains all properties of an embedded element collection which reference a required entity.
|
GeneratorTable |
getTable()
The modified table.
|
Class<T> |
getValueClass()
The class of the value of the collection.
|
GeneratorColumn |
getValueColumn()
The column that contains the value (or the id of the value).
|
Constructor<T> |
getValueConstructor()
The noargs constructor for the values of the collection.
|
ValueConverter<T> |
getValueConverter()
The converter for the value of the collection,
null if not a primitive value. |
EntityClass<T> |
getValueEntityClass()
|
protected static boolean |
hasPluralAnnotation(AttributeAccessor attribute)
Indicates, that the given attribute has an annotation that indicates a plural property.
|
private void |
initializeIdColumnForMappingTable(EntityClass<?> sourceClass,
AttributeAccessor attribute,
javax.persistence.AssociationOverride override,
javax.persistence.JoinTable joinTable,
javax.persistence.CollectionTable collectionTable) |
private void |
initializeInverseProperty() |
boolean |
isComposition()
Indicates that, according to the
CascadeType , we should remove the target entities when the current
entity is removed. |
boolean |
isEmbedded()
Indicates that this propery is a
ElementCollection that references Embeddable s. |
boolean |
isEntityReference()
Indicates that entities are referenced by the collection.
|
boolean |
isRequired()
Indicates if this property is an required field in the database (needs to exist when the insert statement is
written).
|
boolean |
isTableColumn()
Indicates that this property maps to a column from the parent table.
|
boolean |
isUseTargetTable()
Indicates to use a column of the target table.
|
T |
newElement()
Tries to create a new instance of an element using the parameter-less constructor.
|
private static String |
resolveAnnotationAttribute(javax.persistence.AssociationOverride override,
javax.persistence.JoinTable joinTable,
javax.persistence.CollectionTable collectionTable,
Function<javax.persistence.JoinTable,String> joinTableAttribute,
Function<javax.persistence.CollectionTable,String> collectionTableAttribute,
String defaultAttribute) |
private static GeneratorTable |
resolveTable(GeneratorContext context,
javax.persistence.AssociationOverride override,
javax.persistence.JoinTable joinTable,
javax.persistence.CollectionTable collectionTable,
GeneratorTable sourceEntityTable,
String targetEntityTable) |
createPostInsertStatements, createPreInsertStatements, failIfRequired, findReferencedEntities, getAttribute, getExpression, getName, getPredicate, getType, getValue, isComposition, setValue, toString
private final GeneratorContext context
private final GeneratorDialect dialect
private List<Property<T,?>> embeddedProperties
private Map<String,Property<T,?>> embeddedPropertiesByName
private List<EntityProperty<T,?>> requiredEmbeddedProperties
private final String mappedId
private final GeneratorTable table
private GeneratorColumn idColumn
private final boolean composition
CascadeType
, we should remove the target entities when the current
entity is removed.
Always true
for ElementCollection
s.private final String mappedBy
private Property<T,?> inverseProperty
PluralProperty
(it the relationship is a ManyToMany
) or an
EntityProperty
(if the relationship is a OneToMany
.private final boolean useTargetTable
private final GeneratorColumn valueColumn
private final Constructor<T> valueConstructor
private final boolean entityReference
private final EntityClass<T> valueEntityClass
private final ValueConverter<T> valueConverter
null
if not a primitive value.private final AnyMapping<T> anyMapping
ManyToAny
is used.public PluralProperty(EntityClass<?> sourceClass, AttributeAccessor attribute, javax.persistence.AssociationOverride associationOverride, javax.persistence.AttributeOverride attributeOverride, int valueClassParamIndex)
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 an ElementCollection
valueClassParamIndex
- the index of the value argument in the collection class (0 for collection, 1 for map)protected static String buildIdColumn(AttributeAccessor attribute, javax.persistence.AssociationOverride override, javax.persistence.CollectionTable collectionMetadata, String defaultIdColumn)
attribute
- the accessor for the inspected attributeoverride
- contains optional override optionscollectionMetadata
- the default join columndefaultIdColumn
- the default name for the column, if joinColumn
is empty or null
private static String buildIdColumn(AttributeAccessor attribute, javax.persistence.AssociationOverride override, javax.persistence.JoinColumn[] joinColumns, String defaultIdColumn)
private static String buildIdColumn(AttributeAccessor attribute, javax.persistence.AssociationOverride override, javax.persistence.JoinTable joinTable, javax.persistence.CollectionTable tableMetadata, String defaultIdColumn)
private static GeneratorColumn buildValueColumn(GeneratorTable table, javax.persistence.AssociationOverride asscoiationOverride, javax.persistence.AttributeOverride attributeOverride, AttributeAccessor attribute, String defaultColumnName)
table
- the collection tableasscoiationOverride
- contains optional override options for associationattributeOverride
- contains optional override options for element collectionsattribute
- the inspected attributedefaultColumnName
- the default column nameprivate static String findMappedId(AttributeAccessor attribute)
private static <T> Constructor<T> findValueConstructor(Class<T> valueClass)
private static String getJoinColumnName(javax.persistence.JoinColumn[] joinColumns)
protected static <T> Class<T> getPropertyArgument(AttributeAccessor attribute, Class<T> explicitClass, int argumentIndex)
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 valueprotected static boolean hasPluralAnnotation(AttributeAccessor attribute)
attribute
- the attribute to checktrue
if one of the plural annotations is defined for the attributeprivate static String resolveAnnotationAttribute(javax.persistence.AssociationOverride override, javax.persistence.JoinTable joinTable, javax.persistence.CollectionTable collectionTable, Function<javax.persistence.JoinTable,String> joinTableAttribute, Function<javax.persistence.CollectionTable,String> collectionTableAttribute, String defaultAttribute)
private static GeneratorTable resolveTable(GeneratorContext context, javax.persistence.AssociationOverride override, javax.persistence.JoinTable joinTable, javax.persistence.CollectionTable collectionTable, GeneratorTable sourceEntityTable, String targetEntityTable)
public void addInsertExpression(TableStatement statement, E entity)
Property
addInsertExpression
in class Property<E,C>
statement
- the created statemententity
- the inspected entityprotected void buildEmbeddedProperties(EntityClass<?> sourceClass, Class<?> targetType)
sourceClass
- the class that contains our propertytargetType
- the target typeprotected void createDirectValueStatement(StatementsWriter writer, E entity, ColumnExpression sourceId, ColumnExpression key, T value) throws IOException
writer
- the target of created statementsentity
- the entity that contains the collection resp. map.sourceId
- the ID of the current entitykey
- the value of the getKeyColumn()
- either the index or the map keyvalue
- the current value in the collectionIOException
- if the writer throws oneprivate void createEmbeddedValueStatement(StatementsWriter writer, E entity, ColumnExpression sourceId, ColumnExpression key, T value) throws IOException
writer
- the target of the created statemententity
- the entity that contains the collection resp. map.sourceId
- the ID of the current entitykey
- the value of the getKeyColumn()
- either the index or the map keyvalue
- the current value in the collectionIOException
- if the writer throws oneprotected ColumnExpression createValueExpression(E entity, ColumnExpression sourceId, T value, ColumnExpression key)
entity
- 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 writtennull
if the insert is still pendingprotected void createValueStatement(StatementsWriter writer, E entity, ColumnExpression sourceId, ColumnExpression key, T value) throws IOException
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 writtenIOException
- if the writer throws onepublic void generatePendingStatements(StatementsWriter writer, E entity, Object writtenEntity, Object... arguments) throws IOException
Property
EntityClass.markPendingUpdates(E, V, org.fastnate.generator.context.Property<V, ?>, java.lang.Object...)
was called before for writtenEntity
generatePendingStatements
in class Property<E,C>
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 markPendingUpdatesIOException
- if the writer throws oneprotected abstract GeneratorColumn getKeyColumn()
private void initializeIdColumnForMappingTable(EntityClass<?> sourceClass, AttributeAccessor attribute, javax.persistence.AssociationOverride override, javax.persistence.JoinTable joinTable, javax.persistence.CollectionTable collectionTable)
private void initializeInverseProperty()
public boolean isEmbedded()
ElementCollection
that references Embeddable
s.getEmbeddedProperties()
returns a list of propertiespublic boolean isRequired()
Property
isRequired
in class Property<E,C>
true
if the field is requiredpublic boolean isTableColumn()
Property
isTableColumn
in class Property<E,C>
true
if Property.addInsertExpression(org.fastnate.generator.statements.TableStatement, E)
will add the corresponding value to the given statementpublic T newElement()
@Generated(value="lombok") public GeneratorContext getContext()
@Generated(value="lombok") public GeneratorDialect getDialect()
@Generated(value="lombok") public List<Property<T,?>> getEmbeddedProperties()
@Generated(value="lombok") public Map<String,Property<T,?>> getEmbeddedPropertiesByName()
@Generated(value="lombok") public List<EntityProperty<T,?>> getRequiredEmbeddedProperties()
@Generated(value="lombok") public String getMappedId()
@Generated(value="lombok") public GeneratorTable getTable()
@Generated(value="lombok") public GeneratorColumn getIdColumn()
@Generated(value="lombok") public boolean isComposition()
CascadeType
, we should remove the target entities when the current
entity is removed.
Always true
for ElementCollection
s.@Generated(value="lombok") public String getMappedBy()
@Generated(value="lombok") public Property<T,?> getInverseProperty()
PluralProperty
(it the relationship is a ManyToMany
) or an
EntityProperty
(if the relationship is a OneToMany
.@Generated(value="lombok") public boolean isUseTargetTable()
@Generated(value="lombok") public GeneratorColumn getValueColumn()
@Generated(value="lombok") public Class<T> getValueClass()
@Generated(value="lombok") public Constructor<T> getValueConstructor()
@Generated(value="lombok") public boolean isEntityReference()
@Generated(value="lombok") public EntityClass<T> getValueEntityClass()
@Generated(value="lombok") public ValueConverter<T> getValueConverter()
null
if not a primitive value.@Generated(value="lombok") public AnyMapping<T> getAnyMapping()
ManyToAny
is used.Copyright © 2022 fastnate.org. All rights reserved.