Class EntityProperty<E,T>

Type Parameters:
E - The type of the container entity
T - The type of the target entity

public class EntityProperty<E,T> extends SingularProperty<E,T>
Describes a property of an EntityClass that references exactly one other entity.
Author:
Tobias Liefke
  • Constructor Details

    • EntityProperty

      public EntityProperty(GeneratorContext context, GeneratorTable containerTable, AttributeAccessor attribute, jakarta.persistence.AssociationOverride override)
      Creates a new instance of EntityProperty.
      Parameters:
      context - the generator context.
      containerTable - the table that contains our column
      attribute - the accessor of the attribute
      override - optional AssociationOverride configuration
  • Method Details

    • isEntityProperty

      public static boolean isEntityProperty(AttributeAccessor attribute)
      Indicates that the given attribute references a single entity and may be used by an EntityProperty.
      Parameters:
      attribute - accessor of the attribute to check
      Returns:
      true if an EntityProperty may be created for the given attribute
    • addInsertExpression

      public void addInsertExpression(TableStatement statement, E entity)
      Description copied from class: Property
      Adds an expression according to the current value of the property for the given entity to an SQL insert statement.
      Overrides:
      addInsertExpression in class Property<E,T>
      Parameters:
      statement - the created statement
      entity - 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

      public Collection<?> findReferencedEntities(E entity)
      Description copied from class: Property
      Finds all entities in the current property, that are referenced.
      Overrides:
      findReferencedEntities in class Property<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: Property
      Generates the update statements for an entity that are required after another entity was generated. Only called, if EntityClass.markPendingUpdates(E, V, org.fastnate.generator.context.Property<V, ?>, java.lang.Object...) was called before for writtenEntity
      Overrides:
      generatePendingStatements in class Property<E,T>
      Parameters:
      writer - the target of the generated statements
      entity - the entity that needs to be updated
      writtenEntity - the entity that exists now in the database
      arguments - additional arguments that where given to markPendingUpdates
      Throws:
      IOException - if the writer throws one
    • getExpression

      public ColumnExpression getExpression(E entity, boolean whereExpression)
      Description copied from class: Property
      Creates the expression for the current value of the given entity in SQL.
      Overrides:
      getExpression in class Property<E,T>
      Parameters:
      entity - the entity
      whereExpression - indicates that the expression is used in a "where" statement
      Returns:
      the expression for the value of this property or null if no exists
    • getPredicate

      public String getPredicate(E entity)
      Description copied from class: Property
      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.
      Overrides:
      getPredicate in class Property<E,T>
      Parameters:
      entity - the entity
      Returns:
      the predicate for the value of that entity or null if no such expression is available
    • isTableColumn

      public boolean isTableColumn()
      Description copied from class: Property
      Indicates that this property maps to a column from the parent table.
      Overrides:
      isTableColumn in class SingularProperty<E,T>
      Returns:
      true if Property.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 statement
      value - the written value
      expression - the expression of the value
    • getContext

      public GeneratorContext getContext()
      The current context.
    • getTargetClass

      public EntityClass<T> getTargetClass()
      The description of the type of this property.
    • isRequired

      public boolean isRequired()
      Indicates, that this property needs a value.
      Overrides:
      isRequired in class Property<E,T>
      Returns:
      true if the field is required
    • isComposition

      public boolean isComposition()
      Indicates that, according to the CascadeType, we should remove the target entity when the current entity is removed.
    • getMappedBy

      public String getMappedBy()
      The optional name of a property in the target type, that owns the relationship.
      See Also:
      • OneToOne.mappedBy()
    • getInverseProperty

      public Property<T,?> getInverseProperty()
      The opposite property of a bidirectional mapping.
    • getColumn

      public GeneratorColumn getColumn()
      The description of the join column.
      Specified by:
      getColumn in class SingularProperty<E,T>
      Returns:
      the column name
    • getIdField

      public String getIdField()
      The name of the id for referencing an embedded id.