Class GeneratedIdProperty<E,T extends Number>

Type Parameters:
E - The type of the container class
T - The type of the property

public class GeneratedIdProperty<E,T extends Number> extends PrimitiveProperty<E,T>
Describes an Id property of an EntityClass.
Author:
Tobias Liefke
  • Constructor Details

    • GeneratedIdProperty

      public GeneratedIdProperty(EntityClass<E> entityClass, AttributeAccessor attribute, jakarta.persistence.Column column)
      Creates a new instance of GeneratedIdProperty.
      Parameters:
      entityClass - the entity class
      attribute - the accessor of the id attribute
      column - the column annotation
  • Method Details

    • 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 PrimitiveProperty<E,T extends Number>
      Parameters:
      statement - the created statement
      entity - the inspected entity
    • createPreInsertStatements

      public void createPreInsertStatements(StatementsWriter writer, E entity) throws IOException
      Description copied from class: Property
      Creates SQL statements that are necessary before this property is written (e.g. for updating the table generator).
      Overrides:
      createPreInsertStatements in class Property<E,T extends Number>
      Parameters:
      writer - the target of the created statements
      entity - the inspected entity
      Throws:
      IOException - if the writer throws an exception
    • getExpression

      public ColumnExpression getExpression(E entity, boolean whereExpression)
      Creates the reference of an entity in SQL using its (relative or absolute) id.
      Overrides:
      getExpression in class PrimitiveProperty<E,T extends Number>
      Parameters:
      entity - the entity
      whereExpression - indicates that the reference is used in a "where" statement
      Returns:
      the expression for the ID of that entity or null if the entity was not written up to now
      Throws:
      IllegalArgumentException - if the entity is a reference without any id
    • isNew

      public boolean isNew(E entity)
      Indicates that the given entity needs to be written.
      Parameters:
      entity - the entity to check
      Returns:
      true if the id of the given entity is not set up to now
    • isReference

      public boolean isReference(E entity)
      Indicates that the given entity was not written before, but exists already in the database.
      Parameters:
      entity - the entity to check
      Returns:
      true if the entity was marked as reference
    • markReference

      public void markReference(E entity)
      Marks an entity as reference, where we don't know the ID database. A reference is not written during SQL generation, because it exists already in the database when the script is executed. As we don't know the ID during build time we have to reference it using some unique properties.
      Parameters:
      entity - the entity to mark
    • markReference

      public void markReference(E entity, T id)
      Marks an entity as reference, where we know the id in the database. A reference is not written during SQL generation, because it exists already in the database when the script is executed.
      Parameters:
      entity - the entity to mark
      id - the id of the entity in the database
    • postInsert

      public void postInsert(E entity)
      Called after the insert statement was written, to update any nessecary state in the context.
      Parameters:
      entity - the current entity
    • isAbsoluteIds

      public boolean isAbsoluteIds()
      Shortcut for the inverse of GeneratorContext.isWriteRelativeIds().
    • isPrimitive

      public boolean isPrimitive()
      Indicates that the ID is never "null", because we have a primitive ID value.
    • getEntityClass

      public EntityClass<E> getEntityClass()
      The entity class that contains our property.
    • getType

      public Class<T> getType()
      The type of the numbers.
      Overrides:
      getType in class Property<E,T extends Number>
      Returns:
      the type of the attribute
    • getUnknownIdMarker

      public T getUnknownIdMarker()
      Marker for the ID of an entity which needs to be referenced by its unique properties.
    • getGenerator

      public IdGenerator getGenerator()
      The generator used for generating new values of this property.