Class EntityClass<E>

java.lang.Object
org.fastnate.generator.context.EntityClass<E>
Type Parameters:
E - The described class

public class EntityClass<E> extends Object
Describes the DB relevant metadata of an entity class.
Author:
Tobias Liefke
  • Method Details

    • createPostInsertStatements

      public void createPostInsertStatements(E entity, StatementsWriter writer) throws IOException
      Marks an entity as written and creates any pending update / insert statements.
      Parameters:
      entity - the entity that exists now in the database
      writer - the target of the new statements
      Throws:
      IOException - if the writer throws one
    • getEntityReference

      public ColumnExpression getEntityReference(E entity, String idField, boolean whereExpression)
      Creates an expression that references the id of an entity of this class.
      Parameters:
      entity - the entity
      idField - the field that contains the id, only interesting if the id is an EmbeddedProperty
      whereExpression - indicates that the reference is used in a "where" statement
      Returns:
      the expression - either by using the unique properties or the id of the entity
    • 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 entity was neither written, nor exists in the database
    • markExistingEntity

      public void markExistingEntity(E entity)
      Marks a entity reference, where we don't know the ID in the database.
      Parameters:
      entity - the entity to mark
    • markPendingUpdates

      public <V> void markPendingUpdates(E pendingEntity, V entityToUpdate, Property<V,?> propertyToUpdate, Object... arguments)
      Marks an update that is necessary when an entity is written (in the future).
      Parameters:
      pendingEntity - the entity that needs to be written, before the update can take place
      entityToUpdate - the entity to update
      propertyToUpdate - the property of the entity to update
      arguments - additional arguments
    • newInstance

      public E newInstance()
      Creates a new entity of the represented class.
      Returns:
      the new entity
    • onPropertiesAvailable

      public void onPropertiesAvailable(Consumer<EntityClass<E>> listener)
      Registers a listener that is called as soon as all properties of this class are built. If the properties are already build, the listener is called immediately.
      Parameters:
      listener - called as soon as all properties are available
    • toString

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

      public GeneratorContext getContext()
      The current context.
    • getEntityClass

      public Class<E> getEntityClass()
      The represented class.
    • getEntityName

      public String getEntityName()
      The entity name.
    • getTable

      public GeneratorTable getTable()
      The main table of the entity.
    • getAccessStyle

      public AccessStyle getAccessStyle()
      The type of access that is used for the properties (field access or bean property access).
    • getInheritanceType

      public jakarta.persistence.InheritanceType getInheritanceType()
      The inheritance type of this class. null if no subclass is known and no inhertance is indicated (using one of the inheritance annotations).
    • getParentEntityClass

      public Class<? super E> getParentEntityClass()
      Only used during build() to find the joinedParentClass even if that one references our class.
    • getJoinedParentClass

      public EntityClass<? super E> getJoinedParentClass()
      The description of the next entity class that has InheritanceType.JOINED, if any.
    • getHierarchyRoot

      public EntityClass<? super E> getHierarchyRoot()
      The description of the entity class that is the root of the current inheritance hierarchy.
    • getDiscriminator

      public ColumnExpression getDiscriminator()
      The SQL expression that is used for the disciminator column of this class. null if no discriminator is used
    • getDiscriminatorColumn

      public GeneratorColumn getDiscriminatorColumn()
      The column for discriminator. null if this class does not belong to a table that contains a discriminator column
    • getPrimaryKeyJoinColumn

      public GeneratorColumn getPrimaryKeyJoinColumn()
      The column that contains the id of this entity if joinedParentClass is not null.
    • getIdProperty

      public Property<? super E,?> getIdProperty()
      The property that contains the id for the entity. If a joinedParentClass exists, this property is the id property of the parent class.
    • getUniqueProperties

      public List<SingularProperty<E,?>> getUniqueProperties()
      The properties that make up an additional unique identifier for the entity. Depending on GeneratorContext.getUniquePropertyQuality() and GeneratorContext.getMaxUniqueProperties() this might be null, even if there is a set of available unique properties, if the quality is not enough.
    • getUniquePropertiesQuality

      public UniquePropertyQuality getUniquePropertiesQuality()
      Indicates the quality of uniqueProperties.
    • getAllUniqueProperties

      public List<List<SingularProperty<E,?>>> getAllUniqueProperties()
      All available sets of properties that make up an additional unique identifier for the entities.
    • getProperties

      public Map<String,Property<? super E,?>> getProperties()
      Mapping from the name of all persistent properties to their description.
    • getAllProperties

      public List<Property<? super E,?>> getAllProperties()
      All properties of this entity, including idProperty and properties from joinedParentClass.
    • getAdditionalProperties

      public List<Property<? super E,?>> getAdditionalProperties()
      Properties of this entity, excluding the idProperty or properties from joinedParentClass.
    • getEntityStates

      public Map<Object,GenerationState> getEntityStates()
      The states of written entities. Only interesting for pending updates and if the ID is not generated.
    • getAttributeOverrides

      public Map<String,jakarta.persistence.AttributeOverride> getAttributeOverrides()
      All attribute overriddes of this class and the parent classes.
    • getAssociationOverrides

      public Map<String,jakarta.persistence.AssociationOverride> getAssociationOverrides()
      All association overriddes of this class and the parent classes.