Interface Entity

All Superinterfaces:
ModelElement
All Known Implementing Classes:
EntityImpl

public interface Entity extends ModelElement
The entity.

This is the top-level model element.

Author:
harald
  • Method Details

    • getClassId

      int getClassId()
      Gets the unique id of this entity.
      A sort of class-ID that is used to map from a small number to a class or classname.
      Returns:
      the entity class id
    • getTableName

      String getTableName()
      Gets the database table name.
      An optional schema may be prepended separated by a dot.

      Important: similar to the entity name, the table name must be unique among the whole model and all schemas. This restriction avoids unnecessary confusion and reduces the potential for errors in SQL statements.

      Returns:
      the tablename (always in lowercase), null if entity doesn't map to its own table
    • getSchemaName

      String getSchemaName()
      Gets the schema name.
      Returns:
      the schema (always in lowercase), null if default
    • getTableNameWithoutSchema

      String getTableNameWithoutSchema()
      Gets the tablename without the leading schema.

      Important: similar to the entity name, the table name must be unique among the whole model and all schemas. This restriction avoids unnecessary confusion and reduces the potential for errors in SQL statements.

      Returns:
      the tablename relative to its schema (always in lowercase), null if entity doesn't map to its own table
    • getTableAlias

      String getTableAlias()
      Gets the table alias for joined selects.
      The alias is unique among all tables. If the model does not provide an alias, a unique alias will be generated.
      Returns:
      the table alias
    • getDefinedTableAlias

      String getDefinedTableAlias()
      Gets the table alias originally configured in the model.
      Returns:
      the fixed alias, null if automatic
    • getIntegrity

      Integrity getIntegrity()
      Gets the referential integrity mode.
      Returns:
      the integrity mode
    • getOptions

      EntityOptions getOptions()
      Gets the options.
      Returns:
      the options
    • getAttributes

      List<Attribute> getAttributes()
      Gets the attributes.
      Returns:
      the attributes
    • getInheritedAttributes

      List<Attribute> getInheritedAttributes() throws ModelException
      Gets the inherited attributes.
      Returns:
      the attributes
      Throws:
      ModelException
    • getEmbeddedAttributes

      List<Attribute> getEmbeddedAttributes() throws ModelException
      Gets the attributes of embedded entities.
      Returns:
      the embedded attributes
      Throws:
      ModelException
    • getEmbeddedRelations

      List<Relation> getEmbeddedRelations(Entity embeddingEntity) throws ModelException
      Gets the relations of all embedded entities.
      Due to the restriction of embedded entities, these relations are all non-composite object relations.
      Parameters:
      embeddingEntity - the effectively embedding entity
      Returns:
      the list of embedded relations
      Throws:
      ModelException - if failed
    • getSubEntityAttributes

      List<Attribute> getSubEntityAttributes()
      Gets the attributes from the sub entities.
      Returns:
      the attributes
    • getAttributesIncludingInherited

      List<Attribute> getAttributesIncludingInherited() throws ModelException
      Gets the attributes including the inherited ones.
      Returns:
      the attributes
      Throws:
      ModelException
    • getAttributesIncludingSubEntities

      List<Attribute> getAttributesIncludingSubEntities()
      Gets the attributes including the ones from the sub entities.
      Returns:
      the attributes
    • getAllAttributes

      List<Attribute> getAllAttributes() throws ModelException
      Gets all attributes including inherited and from sub entities.
      Returns:
      the attributes
      Throws:
      ModelException
    • getTableAttributes

      List<Attribute> getTableAttributes() throws ModelException
      Gets the attributes of the table mapped by this entity.
      Returns:
      the attributes, empty if entity does not map to a table or does not provide attributes
      Throws:
      ModelException
    • getMappedAttributes

      List<Attribute> getMappedAttributes() throws ModelException
      Gets the attributes mapped by the persistence layer for this entity.
      Returns:
      the attributes
      Throws:
      ModelException
    • getAttributeByJavaName

      Attribute getAttributeByJavaName(String javaName, boolean all)
      Gets an attribute by its java name.
      Parameters:
      javaName - the java name
      all - true if include inherited attributes
      Returns:
      the attribute, null if no such attribute
    • getAttributeByColumnName

      Attribute getAttributeByColumnName(String columnName, boolean all)
      Gets an attribute by its database column name.

      Notice that upper/lowercase doesn't matter.

      Parameters:
      columnName - the database column name
      all - true if include inherited attributes
      Returns:
      the attribute, null if no such attribute
    • getContextIdAttribute

      Attribute getContextIdAttribute()
      Gets the attribute that holds the context id.
      Returns:
      the context attribute, null if none
    • getUniqueDomainKey

      List<Attribute> getUniqueDomainKey() throws ModelException
      Gets the attributes describing the unique domain key.
      Returns:
      the udk attributes, empty if no udk
      Throws:
      ModelException
    • getSorting

      List<AttributeSorting> getSorting()
      Gets the default sorting for this entity.
      Returns:
      the sorting, null if unsorted by default
    • getRelations

      List<Relation> getRelations()
      Gets the relations.
      Returns:
      the relations
    • getInheritedRelations

      List<Relation> getInheritedRelations() throws ModelException
      Gets the inherited relations.
      Returns:
      the relations
      Throws:
      ModelException
    • getSubEntityRelations

      List<Relation> getSubEntityRelations()
      Gets the relations from the sub entities.
      Returns:
      the relations
    • getRelationsIncludingInherited

      List<Relation> getRelationsIncludingInherited() throws ModelException
      Gets all including inherited relations.
      Returns:
      the relations
      Throws:
      ModelException
    • getRelationsIncludingSubEntities

      List<Relation> getRelationsIncludingSubEntities()
      Gets all relations including the ones from the sub entities.
      Returns:
      the relations
    • getAllRelations

      List<Relation> getAllRelations() throws ModelException
      Gets all relations including the inherited and the ones from the sub entities.
      Returns:
      the relations
      Throws:
      ModelException
    • getTableRelations

      List<Relation> getTableRelations() throws ModelException
      Gets the relations of the table mapped by this entity.
      Will also contain the relations from embedded entities.
      Returns:
      the relations, empty if entity does not map to a table or provides no relations
      Throws:
      ModelException
    • getRelation

      Relation getRelation(String name, boolean all)
      Gets a relation by its name.
      Parameters:
      name - the relation's name
      all - true if include inherited relations
      Returns:
      the relation, null if no such relation
    • getRelations

      List<Relation> getRelations(Entity entity, boolean all)
      Gets all relations for a given entity type.
      Parameters:
      entity - the entity
      all - true if include inherited relations
      Returns:
      the relations, empty if no such relation
    • getReferencingRelations

      List<Relation> getReferencingRelations()
      Gets the relations from other entities directly referencing this entity.
      Returns:
      the relations
    • getInheritedReferencingRelations

      List<Relation> getInheritedReferencingRelations()
      Gets the relations from other entities referencing any super-entity.
      Returns:
      the relations
    • getSubEntityReferencingRelations

      List<Relation> getSubEntityReferencingRelations()
      Gets the relations from other entities referencing any sub-entity.
      Returns:
      the relations
    • getReferencingRelationsIncludingInherited

      List<Relation> getReferencingRelationsIncludingInherited()
      Gets the relations from other entities referencing this entity or any super-entity.
      Returns:
      the relations
    • getReferencingRelationsIncludingSubEntities

      List<Relation> getReferencingRelationsIncludingSubEntities()
      Gets the relations from other entities referencing this entity or any sub-entity.
      Returns:
      the relations
    • getAllReferencingRelations

      List<Relation> getAllReferencingRelations()
      Gets the relations from other entities referencing this entity or any sub-entity or super entity.
      Returns:
      the relations
    • getIndexes

      List<Index> getIndexes()
      Gets the indexes.
      Returns:
      the indexes
    • getInheritedIndexes

      List<Index> getInheritedIndexes()
      Gets inherited indexes.
      Returns:
      the indexes
    • getSubEntityIndexes

      List<Index> getSubEntityIndexes()
      Gets indexes from sub entities.
      Returns:
      the indexes
    • getIndexesIncludingInherited

      List<Index> getIndexesIncludingInherited()
      Gets all including inherited indexes.
      Returns:
      the indexes
    • getIndexesIncludingSubEntities

      List<Index> getIndexesIncludingSubEntities()
      Gets all including indexes from sub entities.
      Returns:
      the indexes
    • getAllIndexes

      List<Index> getAllIndexes()
      Gets all including inherited and indexes from sub entities.
      Returns:
      the indexes
    • getTableIndexes

      List<Index> getTableIndexes()
      Gets the indexes of the table mapped by this entity.
      Returns:
      the indexes, empty if entity does not map to a table or provides no indexes
    • getIndex

      Index getIndex(String name, boolean all)
      Gets an index by its name.
      Parameters:
      name - the index name
      all - true if include inherited indexes
      Returns:
      the index, null if no such index
    • sqlCreateTable

      String sqlCreateTable(Backend backend) throws ModelException
      Creates the table creation sql code.
      Parameters:
      backend - the backend to create sql code for
      Returns:
      the SQL code
      Throws:
      ModelException - if model inconsistent
    • isComposite

      boolean isComposite()
      Returns whether entity has composite relations.
      Returns:
      true if composite entity
    • isEffectivelyComposite

      boolean isEffectivelyComposite()
      Returns whether entity has composite non-embedded relations.
      Returns:
      true if not only embedded composite relations
    • isAbstract

      boolean isAbstract()
      Returns whether class may be instantiated.
      Returns:
      true if class is abstract
    • isEmbedded

      boolean isEmbedded()
      Returns whether this is an embedded entity.
      Such entities are embedded via embedding relations. Embedded entities are mapped to their embedding entity, which is always a regular non-embedded entity. Embedded entities can embed other embedded entities, but cannot have regular components. However, embedded entities can have non-composite object relations (1:1).
      Returns:
      true if embedded
      See Also:
    • isTracked

      boolean isTracked()
      Returns whether entity is tracked.
      Returns:
      true if tracked
    • isDeletionCascaded

      Boolean isDeletionCascaded()
      Returns the cascade-flag if it is the same for all composite relations.
      If there are no composite relations at all, false is returned.
      Returns:
      the cascade flag, null if mixed composite relations
    • getRootAttributes

      Set<Attribute> getRootAttributes()
      Returns the attributes that corresponds to the root id.
      Returns:
      the attributes, empty list if root id is provided separately or no root id at all
    • getRootAttribute

      Attribute getRootAttribute()
      Returns the single root attribute if there is exactly one.
      Returns:
      the attribute, null if none or more than one
    • getRootEntities

      Set<Entity> getRootEntities()
      Returns the root entities.
      Returns all roots, even abstract ones.
      Returns:
      the root entities, empty list if rootclassid is provided separately or no rootclassid at all
    • getRootEntity

      Entity getRootEntity()
      Returns the single root entity, if there is exactly one, and it is not abstract.
      Returns:
      the root entity, null if none or abstract or more than one
    • isRootEntity

      boolean isRootEntity()
      Returns whether this is a root entity.
      Inspects the super entities as well.
      Returns:
      true if root entity
    • isRootOfInheritanceHierarchy

      boolean isRootOfInheritanceHierarchy()
      Returns whether entity is the root of an inheritance hierarchy.
      Returns:
      true if root
    • getTableProvidingEntity

      Entity getTableProvidingEntity()
      Gets the entity that provides the database table.
      Returns:
      the table providing entity, null if entity is abstract and does not correspond to a single table
    • getInheritanceType

      InheritanceType getInheritanceType()
      Gets the inheritance type.
      Returns:
      the inheritance type
    • getHierarchyInheritanceType

      InheritanceType getHierarchyInheritanceType()
      Gets the inheritance type of the hierarchy.
      For leafs, which have InheritanceType.NONE, the type of the super entity is returned.
      Returns:
      the effective inheritance type
    • getSuperEntityName

      String getSuperEntityName()
      Gets the name of the super class entity.
      Returns:
      the super class name, null if not inherited
    • getSuperEntity

      Entity getSuperEntity()
      Gets the super class entity if inherited.
      Returns:
      the super entity, null if not inherited
    • getSuperEntities

      List<Entity> getSuperEntities()
      Gets all super entities.
      Returns:
      the path along up to the top super entity.
    • getTopSuperEntity

      Entity getTopSuperEntity()
      Gets the top most entity of the inheritance tree.
      Returns this entity if there is no inheritance.
      Returns:
      the root of the inheritance hierarchy
    • getInheritanceChain

      List<Entity> getInheritanceChain(Entity subEntity) throws ModelException
      Gets the inheritance chain from this entity down to given sub entity.
      Parameters:
      subEntity - the sub entity
      Returns:
      the chain starting with this entity end ending with the sub entity
      Throws:
      ModelException - if subEntity does not inherit this entity
    • getSubEntities

      List<Entity> getSubEntities()
      Gets the direct sub entities.
      Returns:
      the sub entities, empty list if no sub entities
    • getAllSubEntities

      List<Entity> getAllSubEntities()
      Gets all sub entities.
      Returns:
      the sub entities, empty list if no sub entities
    • getLeafEntities

      List<Entity> getLeafEntities()
      Gets the list of non-abstract leaf sub entities.
      If this entity is already non-abstract the list consists of this entity.
      Returns:
      the leafs
    • getAssociatedEntities

      Set<Entity> getAssociatedEntities()
      Gets a set of all entities that are associated to this entity.
      The kind of association can be a relation, a foreign relation or some hierarchy dependency or a combination of.
      Returns:
      the set of entities including me
    • getCompositePaths

      Set<List<Relation>> getCompositePaths()
      Gets the paths of composite relations to this entity.
      Notice that this includes paths to sub-entities as well.
      Returns:
      the paths, empty list if this is not a component of any other entity
    • getAllCompositePaths

      Set<List<Relation>> getAllCompositePaths()
      Gets the paths of composite relations to this entity.
      Notice that this includes paths to sub-entities and super-entities as well.
      Returns:
      the paths, empty list if this is not a component of any other entity
    • getEmbeddingPaths

      Set<List<Relation>> getEmbeddingPaths()
      Gets the paths of embedding relations to this entity.
      Returns:
      the paths, empty list if this is not an embedded entity
    • getEmbeddingEntities

      Set<Entity> getEmbeddingEntities()
      Gets the embedding entities for this embedded entity.
      Returns:
      the embedding entities, empty if this is not an embedded entity
    • getComponents

      Set<Entity> getComponents()
      Gets the direct components of this entity.
      Returns:
      the components
    • getComponentsIncludingInherited

      Set<Entity> getComponentsIncludingInherited() throws ModelException
      Gets the direct and inherited components of this entity.
      Returns:
      the components
      Throws:
      ModelException
    • getAllComponents

      Set<Entity> getAllComponents() throws ModelException
      Gets all direct and indirect components of this entity.
      Returns:
      the components
      Throws:
      ModelException
    • isProvidingRootClassIdAccordingToModel

      boolean isProvidingRootClassIdAccordingToModel()
      Returns whether this entity should provide a root class id according to model.
      Returns:
      true if should provide a root class id
    • isProvidingRootIdAccordingToModel

      boolean isProvidingRootIdAccordingToModel()
      Returns whether this entity should provide a root id according to model.
      Returns:
      true if the entity should provide a root id
    • isRootEntityAccordingToModel

      boolean isRootEntityAccordingToModel()
      Returns whether this entity is a root-entity according to model.
      Returns:
      true if root entity
    • getDeepReferences

      List<Relation> getDeepReferences()
      Gets the deep references to this entity.
      Returns:
      the deep references, empty if no deep references
    • isDeeplyReferenced

      boolean isDeeplyReferenced()
      Returns whether this entity or one of its components is deeply referenced.
      Returns:
      true if deeply referenced, false if not
    • getDeepReferencesToComponents

      List<Relation> getDeepReferencesToComponents()
      Gets the deep references to components of this root entity.
      Will contain all deep references to all components, not only the direct children.
      Returns:
      the deep references, empty if this is not a root entity or there are no deep references
    • getDeeplyReferencedComponents

      List<Relation> getDeeplyReferencedComponents()
      Gets the deeply referenced components.
      Will contain the relations to components where isDeeplyReferenced() is true.
      Returns:
      the composite relations deeply referenced