Package org.fastnate.generator.context
Class Property<E,T>
java.lang.Object
org.fastnate.generator.context.Property<E,T>
- Type Parameters:
E- The type of the container classT- The type of the value of the property
- Direct Known Subclasses:
EmbeddedProperty,PluralProperty,SingularProperty
Base class for the description of properties of an
EntityClass.- Author:
- Tobias Liefke
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AttributeAccessorUsed to access the value of the property. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProperty(AttributeAccessor attribute) Creates a new instance of a 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.voidcreatePostInsertStatements(StatementsWriter writer, E entity) Creates additional SQL statements that are necessary after this property is written (e.g. for mapping tables).voidcreatePreInsertStatements(StatementsWriter writer, E entity) Creates SQL statements that are necessary before this property is written (e.g. for updating the table generator).protected voidfailIfRequired(E entity) Throws an IllegalArgumentException if the field was not filled.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.Used to access the value of the property.getExpression(E entity, boolean whereExpression) Creates the expression for the current value of the given entity in SQL.getName()The name of this property.getPredicate(E entity) Creates an SQL predicate that references all entities that have the same value as the given entity.getType()The type of the property.Resolves the current value for this property on the given entity.protected static booleanisComposition(jakarta.persistence.CascadeType[] cascades) Indicates that the property is a composition according to the given cascade types.booleanIndicates if this property is an required field in the database (needs to exist when the insert statement is written).abstract booleanIndicates that this property maps to a column from the parent table.voidSets a new value for this property on the given entity.toString()
-
Field Details
-
attribute
Used to access the value of the property.
-
-
Constructor Details
-
Property
Creates a new instance of a property.- Parameters:
attribute- the accessor of the target attribute
-
-
Method Details
-
isComposition
protected static boolean isComposition(jakarta.persistence.CascadeType[] cascades) Indicates that the property is a composition according to the given cascade types. A composition removes the target entity, if the owning entity is removed.- Parameters:
cascades- the "cascade" attribute of the mapping annotation.- Returns:
trueif we are on the owning side of a composition relationship,falseif we are on the child side or if this is an association
-
addInsertExpression
Adds an expression according to the current value of the property for the given entity to an SQL insert statement.- Parameters:
statement- the created statemententity- the inspected entity
-
createPostInsertStatements
Creates additional SQL statements that are necessary after this property is written (e.g. for mapping tables).- Parameters:
writer- the target of the created statementsentity- the inspected entity- Throws:
IOException- if the writer throws one
-
createPreInsertStatements
Creates SQL statements that are necessary before this property is written (e.g. for updating the table generator).- Parameters:
writer- the target of the created statementsentity- the inspected entity- Throws:
IOException- if the writer throws an exception
-
failIfRequired
Throws an IllegalArgumentException if the field was not filled.- Parameters:
entity- the entity that does not contain a value for this property
-
findReferencedEntities
Finds all entities in the current property, that are referenced.- Parameters:
entity- the inspected entity- Returns:
- all referenced entities
-
generatePendingStatements
public void generatePendingStatements(StatementsWriter writer, E entity, Object writtenEntity, Object... arguments) throws IOException Generates 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- 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
Creates the expression for the current value of the given entity in SQL.- 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
-
getName
The name of this property.- Returns:
- the name
-
getPredicate
Creates 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.- Parameters:
entity- the entity- Returns:
- the predicate for the value of that entity or
nullif no such expression is available
-
getType
The type of the property.- Returns:
- the
type of the attribute
-
getValue
Resolves the current value for this property on the given entity.- Parameters:
entity- the entity to inspect- Returns:
- the value,
nullif entity isnull
-
isRequired
public boolean isRequired()Indicates if this property is an required field in the database (needs to exist when the insert statement is written).- Returns:
trueif the field is required
-
isTableColumn
public abstract boolean isTableColumn()Indicates that this property maps to a column from the parent table.- Returns:
trueifaddInsertExpression(org.fastnate.generator.statements.TableStatement, E)will add the corresponding value to the given statement
-
setValue
Sets a new value for this property on the given entity.- Parameters:
entity- the entity to inspectvalue- the new value
-
toString
-
getAttribute
Used to access the value of the property.
-