Class Property<E,T>

java.lang.Object
org.fastnate.generator.context.Property<E,T>
Type Parameters:
E - The type of the container class
T - The type of the value of the property
Direct Known Subclasses:
EmbeddedProperty, PluralProperty, SingularProperty

public abstract class Property<E,T> extends Object
Base class for the description of properties of an EntityClass.
Author:
Tobias Liefke
  • Field Details

    • attribute

      private final AttributeAccessor attribute
      Used to access the value of the property.
  • Constructor Details

    • Property

      protected Property(AttributeAccessor attribute)
      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:
      true if we are on the owning side of a composition relationship, false if we are on the child side or if this is an association
    • addInsertExpression

      public 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.
      Parameters:
      statement - the created statement
      entity - the inspected entity
    • createPostInsertStatements

      public void createPostInsertStatements(StatementsWriter writer, E entity) throws IOException
      Creates additional SQL statements that are necessary after this property is written (e.g. for mapping tables).
      Parameters:
      writer - the target of the created statements
      entity - the inspected entity
      Throws:
      IOException - if the writer throws one
    • createPreInsertStatements

      public void createPreInsertStatements(StatementsWriter writer, E entity) throws IOException
      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 statements
      entity - the inspected entity
      Throws:
      IOException - if the writer throws an exception
    • failIfRequired

      protected void failIfRequired(E entity)
      Throws an IllegalArgumentException if the field was not filled.
      Parameters:
      entity - the entity that does not contain a value for this property
    • findReferencedEntities

      public Collection<?> findReferencedEntities(E entity)
      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, if EntityClass.markPendingUpdates(E, V, org.fastnate.generator.context.Property<V, ?>, java.lang.Object...) was called before for writtenEntity
      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)
      Creates the expression for the current value of the given entity in SQL.
      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
    • getName

      public String getName()
      The name of this property.
      Returns:
      the name
    • getPredicate

      public String getPredicate(E entity)
      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 null if no such expression is available
    • getType

      public Class<T> getType()
      The type of the property.
      Returns:
      the type of the attribute
    • getValue

      public T getValue(E entity)
      Resolves the current value for this property on the given entity.
      Parameters:
      entity - the entity to inspect
      Returns:
      the value, null if entity is null
    • 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:
      true if the field is required
    • isTableColumn

      public abstract boolean isTableColumn()
      Indicates that this property maps to a column from the parent table.
      Returns:
      true if addInsertExpression(org.fastnate.generator.statements.TableStatement, E) will add the corresponding value to the given statement
    • setValue

      public void setValue(E entity, T value)
      Sets a new value for this property on the given entity.
      Parameters:
      entity - the entity to inspect
      value - the new value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAttribute

      public AttributeAccessor getAttribute()
      Used to access the value of the property.