Klasse EntityDefinition<E extends Entity>

java.lang.Object
org.obrel.core.RelatedObject
de.esoco.storage.mapping.AbstractStorageMapping<E,org.obrel.core.RelationType<?>,EntityDefinition<?>>
de.esoco.entity.EntityDefinition<E>
Alle implementierten Schnittstellen:
de.esoco.lib.event.EventHandler<org.obrel.core.RelationEvent<?>>, de.esoco.lib.event.EventListener, de.esoco.storage.StorageMapping<E,org.obrel.core.RelationType<?>,EntityDefinition<?>>, Serializable, org.obrel.core.Relatable
Bekannte direkte Unterklassen:
DbEntityDefinition, ExtraAttribute.Definition, XmlEntityDefinition

public class EntityDefinition<E extends Entity> extends de.esoco.storage.mapping.AbstractStorageMapping<E,org.obrel.core.RelationType<?>,EntityDefinition<?>> implements de.esoco.lib.event.EventHandler<org.obrel.core.RelationEvent<?>>, Serializable
The base class for the definition of entities. The easiest way to define an entity is to subclass this class, add relation type constants for all attributes (including children), and invoke one of the constructors with arguments, preferably in conjunction with an assignment to a constant. The default implementation will then collect all static fields and initialize the definition accordingly. Subclasses that need to create entity definitions from other informations (like databases or XML files) should invoke the constructor without parameter and one of the init() methods.
Siehe auch:
  • Verschachtelte Klassen - Übersicht

    Verschachtelte Klassen
    Modifizierer und Typ
    Klasse
    Beschreibung
    static enum 
    Enumeration of entity display modes
  • Feldübersicht

    Felder
    Modifizierer und Typ
    Feld
    Beschreibung
    static final String
    The name of the optional public static final field in an entity class that contains a mapping from attribute relation types to additional display properties for that field.
    static final String
    The name of the optional static entity field that contains a boolean value to disable the generation of child count columns in SQL storages.
    static final String
    The prefix for the names of the optional fields that contain an array with the display attribute relation types for an entity class.
    static final String
    The name of the optional static field in an entity class that contains a collection of the entity attribute relation types.
    static final String
    The name of the optional static entity field that contains a string constant with the ID prefix for the global IDs of an entity class
    static final String
    The name of the optional static entity field that contains a string constant with the storage name for an entity class
  • Konstruktorübersicht

    Konstruktoren
    Modifizierer
    Konstruktor
    Beschreibung
    protected
    Creates a new instance without initializing it.
    protected
    EntityDefinition(Class<E> entityClass)
    Creates a new instance from a certain entity class.
    protected
    EntityDefinition(Class<E> entityClass, String idPrefix)
    Creates a new definition from a certain entity class which contains the attribute relation type definitions.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    checkAttributeValue(org.obrel.core.RelationType<?> attribute, Object value)
    protected E
    createEntityInstance(List<?> attributeValues)
    Creates a new instance of the entity class.
    createObject(List<?> attributeValues, boolean asChild)
    final org.obrel.core.RelationType<?>
    getAttribute(String attributeName)
    Returns the attribute relation type that corresponds to a particular attribute name.
    getAttributeDatatype(org.obrel.core.RelationType<?> attribute)
    protected final int
    getAttributeIndex(org.obrel.core.RelationType<?> attr)
    A method for subclasses to query the index of a particular attribute.
    Collection<org.obrel.core.RelationType<?>>
    getAttributeValue(E entity, org.obrel.core.RelationType<?> attribute)
    Collection<org.obrel.core.RelationType<List<Entity>>>
    Returns the relation types of the child attributes of this definition.
    getChildren(E parent, EntityDefinition<?> childMapping)
    de.esoco.lib.expression.Predicate<E>
    getDefaultCriteria(Class<? extends E> type)
    Overridden to return a prediate for a type attribute value if a specific sub-class of the entity type exists.
    List<org.obrel.core.RelationType<?>>
    Returns the attributes for a certain display mode.
    de.esoco.lib.property.MutableProperties
    getDisplayProperties(org.obrel.core.RelationType<?> attribute)
    Returns the display properties for a certain attribute.
    final String
    Returns the descriptive entity name.
    final org.obrel.core.RelationType<List<Entity>>
    Returns the child attribute for a hierarchy of entities of the same type as the entity type described by this definition.
    org.obrel.core.RelationType<Number>
    Returns the relation type of the numeric ID attribute in this definition.
    final String
    Returns the prefix that will be added to global entity IDs.
     
    org.obrel.core.RelationType<? extends Entity>
    Returns the master attribute if such exists.
    org.obrel.core.RelationType<String>
    Returns the relation type of an attribute in this definition that refers to the name of an entity.
    org.obrel.core.RelationType<? extends Entity>
    Returns the parent attribute if such exists.
    org.obrel.core.RelationType<? extends Entity>
    getParentAttribute(de.esoco.storage.StorageMapping<?,?,?> parentDefinition)
     
    org.obrel.core.RelationType<? extends Entity>
    Returns the root parent attribute if such exists.
    org.obrel.core.RelationType<List<Entity>>
    Returns the hierarchy attribute of this definition that references entities of the same type.
    org.obrel.core.RelationType<Enum<?>>
    Returns the relation type of an attribute in this definition that defines the type of an entity.
    void
    handleEvent(org.obrel.core.RelationEvent<?> event)
    Event handler implementation that will be registered as a relation listener on entities to perform the modification tracking for entity attributes.
    protected final void
    init(String entityName, String idPrefix, Class<E> entityClass, List<org.obrel.core.RelationType<?>> attr)
    Internal initialization method that builds the map of attribute relation types.
    void
    initChildren(E parent, List<?> children, EntityDefinition<?> childDef)
     
    void
    initChildren(E parent, List<?> children, EntityDefinition<?> childDef, boolean initializing)
    Initializes the child entities of a parent by setting the parent attributes accordingly.
    protected void
    initEntityReference(E entity, org.obrel.core.RelationType<Entity> entityRefAttr, Object referenceId)
    Initializes an entity reference attribute with an intermediate relation.
    protected void
    initRelationTypeAttribute(E entity, org.obrel.core.RelationType<org.obrel.core.RelationType<?>> relationTypeAttr, String typeName)
    Initializes an attribute that refers to a relation type.
    boolean
    boolean
    isHierarchyAttribute(org.obrel.core.RelationType<?> attribute)
    mapValue(org.obrel.core.RelationType<?> attribute, Object value)
    Overridden to map entity references to entity IDs.
    protected final Object
    Implemented to return the singleton entity definition instance for the entity class that has been read by the deserialization.
    void
    setAttributeValue(E entity, org.obrel.core.RelationType<?> attribute, Object value)
     
    void
    setChildren(E parent, List<?> children, EntityDefinition<?> childDef)
     
    void
    storeReference(org.obrel.core.Relatable sourceObject, E referencedEntity)
    Overridden to store the referenced entity with EntityManager.storeEntity(Entity, Entity).
    Returns a string representation of this entity for debugging purpose, which includes a list of it's attribute types.
    final String
    Returns a string representation of this definition.

    Von Klasse geerbte Methoden org.obrel.core.RelatedObject

    deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Von Schnittstelle geerbte Methoden org.obrel.core.Relatable

    deleteRelation, deleteRelation, deleteRelations, get, getAll, getOption, getRelation, getRelationCount, getRelations, getRelations, hasFlag, hasRelation, hasRelations, init, set, set, set, set, set, setOption, streamRelations, transform
  • Felddetails

    • ENTITY_ATTRIBUTES_FIELD

      public static final String ENTITY_ATTRIBUTES_FIELD
      The name of the optional static field in an entity class that contains a collection of the entity attribute relation types.
      Siehe auch:
    • ID_PREFIX_FIELD

      public static final String ID_PREFIX_FIELD
      The name of the optional static entity field that contains a string constant with the ID prefix for the global IDs of an entity class
      Siehe auch:
    • STORAGE_NAME_FIELD

      public static final String STORAGE_NAME_FIELD
      The name of the optional static entity field that contains a string constant with the storage name for an entity class
      Siehe auch:
    • DISABLE_SQL_CHILD_COUNT_FIELD

      public static final String DISABLE_SQL_CHILD_COUNT_FIELD
      The name of the optional static entity field that contains a boolean value to disable the generation of child count columns in SQL storages. See the relation type JdbcRelationTypes.SQL_DISABLE_CHILD_COUNTS for more information. The boolean value of this field should normally always be TRUE or the field shouldn't exist at all.
      Siehe auch:
    • DISPLAY_ATTRIBUTES_FIELD_PREFIX

      public static final String DISPLAY_ATTRIBUTES_FIELD_PREFIX
      The prefix for the names of the optional fields that contain an array with the display attribute relation types for an entity class. The possible suffixes are defined by the EntityDefinition.DisplayMode enum.
      Siehe auch:
    • ATTRIBUTE_DISPLAY_PROPERTIES_FIELD

      public static final String ATTRIBUTE_DISPLAY_PROPERTIES_FIELD
      The name of the optional public static final field in an entity class that contains a mapping from attribute relation types to additional display properties for that field. Because attributes can be shared between different entity classes this field provides a way to define different display attributes for the same field. The datatype of this field must be Map<RelationType<?>, MutableProperties>.
      Siehe auch:
  • Konstruktordetails

    • EntityDefinition

      protected EntityDefinition()
      Creates a new instance without initializing it. Subclasses that use this constructor must invoke the init method or else this instance will be in an unusable state.
    • EntityDefinition

      protected EntityDefinition(Class<E> entityClass)
      Creates a new instance from a certain entity class. Internally the method init(String, String, Class, List) will be invoked which will then evaluate the relation type declarations in the given entity class to define the entity structure.
      Parameter:
      entityClass - The entity class to create the definition for
    • EntityDefinition

      protected EntityDefinition(Class<E> entityClass, String idPrefix)
      Creates a new definition from a certain entity class which contains the attribute relation type definitions.
      Parameter:
      entityClass - The entity class to create the definition for
      idPrefix - The prefix for global entity IDs
  • Methodendetails

    • checkAttributeValue

      public Object checkAttributeValue(org.obrel.core.RelationType<?> attribute, Object value)
      Angegeben von:
      checkAttributeValue in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Setzt außer Kraft:
      checkAttributeValue in Klasse de.esoco.storage.mapping.AbstractStorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • createObject

      public E createObject(List<?> attributeValues, boolean asChild)
      Angegeben von:
      createObject in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • getAttribute

      public final org.obrel.core.RelationType<?> getAttribute(String attributeName)
      Returns the attribute relation type that corresponds to a particular attribute name. This method is mainly intended to support the implementation of attribute mappings that are defined with strings.
      Parameter:
      attributeName - The attribute name to return the type for
      Gibt zurück:
      The matching attribute type or NULL if no such instance exists
    • getAttributeDatatype

      public Class<?> getAttributeDatatype(org.obrel.core.RelationType<?> attribute)
      Angegeben von:
      getAttributeDatatype in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • getAttributeValue

      public Object getAttributeValue(E entity, org.obrel.core.RelationType<?> attribute)
      Angegeben von:
      getAttributeValue in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • getAttributes

      public Collection<org.obrel.core.RelationType<?>> getAttributes()
      Angegeben von:
      getAttributes in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • getChildAttributes

      public Collection<org.obrel.core.RelationType<List<Entity>>> getChildAttributes()
      Returns the relation types of the child attributes of this definition.
      Gibt zurück:
      A collection of the child attribute relation types
    • getChildMappings

      public Collection<EntityDefinition<?>> getChildMappings()
      Angegeben von:
      getChildMappings in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • getChildren

      public Collection<Entity> getChildren(E parent, EntityDefinition<?> childMapping)
      Angegeben von:
      getChildren in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • getDefaultCriteria

      public de.esoco.lib.expression.Predicate<E> getDefaultCriteria(Class<? extends E> type)
      Overridden to return a prediate for a type attribute value if a specific sub-class of the entity type exists.
      Angegeben von:
      getDefaultCriteria in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.getDefaultCriteria(Class)
    • getDisplayAttributes

      public List<org.obrel.core.RelationType<?>> getDisplayAttributes(EntityDefinition.DisplayMode displayMode)
      Returns the attributes for a certain display mode.
      Parameter:
      displayMode - The display mode
      Gibt zurück:
      A collection containing the attributes for the display mode
    • getDisplayProperties

      public de.esoco.lib.property.MutableProperties getDisplayProperties(org.obrel.core.RelationType<?> attribute)
      Returns the display properties for a certain attribute. Always returns a new properties object, even if empty, that can be modified freely by the receiver.
      Parameter:
      attribute - The attribute to return the display properties for
      Gibt zurück:
      The display properties for the given attribute
    • getEntityName

      public final String getEntityName()
      Returns the descriptive entity name.
      Gibt zurück:
      The entity name
    • getHierarchyChildAttribute

      public final org.obrel.core.RelationType<List<Entity>> getHierarchyChildAttribute()
      Returns the child attribute for a hierarchy of entities of the same type as the entity type described by this definition.
      Gibt zurück:
      The hierarchy child attribute or NULL for none
    • getIdAttribute

      public org.obrel.core.RelationType<Number> getIdAttribute()
      Returns the relation type of the numeric ID attribute in this definition. The exact datatype depends on the actual ID attribute relation type. Typically this will be either Integer or Long.

      If an entity does not define it's own ID attribute the default ID type EntityRelationTypes.ENTITY_ID will be returned.

      Angegeben von:
      getIdAttribute in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.getIdAttribute()
    • getIdPrefix

      public final String getIdPrefix()
      Returns the prefix that will be added to global entity IDs.
      Gibt zurück:
      The ID prefix
    • getMappedType

      public Class<E> getMappedType()
      Angegeben von:
      getMappedType in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.getMappedType()
    • getMasterAttribute

      public org.obrel.core.RelationType<? extends Entity> getMasterAttribute()
      Returns the master attribute if such exists.
      Gibt zurück:
      The master attribute or NULL for none
    • getNameAttribute

      public org.obrel.core.RelationType<String> getNameAttribute()
      Returns the relation type of an attribute in this definition that refers to the name of an entity. This will either be the attribute with the type StandardTypes.NAME or any other string attribute that has the meta relation type MetaTypes.OBJECT_NAME_ATTRIBUTE set.
      Gibt zurück:
      The name attribute of the entity or NULL for none
    • getParentAttribute

      public org.obrel.core.RelationType<? extends Entity> getParentAttribute()
      Returns the parent attribute if such exists.
      Gibt zurück:
      The parent attribute or NULL for none
    • getParentAttribute

      public org.obrel.core.RelationType<? extends Entity> getParentAttribute(de.esoco.storage.StorageMapping<?,?,?> parentDefinition)
      Angegeben von:
      getParentAttribute in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.getParentAttribute(StorageMapping)
    • getRootAttribute

      public org.obrel.core.RelationType<? extends Entity> getRootAttribute()
      Returns the root parent attribute if such exists.
      Gibt zurück:
      The root attribute or NULL for none
    • getSelfReferenceAttribute

      public org.obrel.core.RelationType<List<Entity>> getSelfReferenceAttribute()
      Returns the hierarchy attribute of this definition that references entities of the same type.
      Gibt zurück:
      The attribute or NULL for none
    • getTypeAttribute

      public org.obrel.core.RelationType<Enum<?>> getTypeAttribute()
      Returns the relation type of an attribute in this definition that defines the type of an entity. If a definition subclass does not define such a type attribute with an enum datatype and a meta-relation with the flag type MetaTypes.OBJECT_TYPE_ATTRIBUTE set to TRUE this method will return NULL.
      Gibt zurück:
      The type attribute of this definition or NULL for none
    • handleEvent

      public void handleEvent(org.obrel.core.RelationEvent<?> event)
      Event handler implementation that will be registered as a relation listener on entities to perform the modification tracking for entity attributes.
      Angegeben von:
      handleEvent in Schnittstelle de.esoco.lib.event.EventHandler<E extends Entity>
      Siehe auch:
      • EventHandler.handleEvent(de.esoco.lib.event.Event)
    • initChildren

      public void initChildren(E parent, List<?> children, EntityDefinition<?> childDef)
      Angegeben von:
      initChildren in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.initChildren(Object, List, StorageMapping)
    • initChildren

      public void initChildren(E parent, List<?> children, EntityDefinition<?> childDef, boolean initializing)
      Initializes the child entities of a parent by setting the parent attributes accordingly. This includes the root and master attributes if available.
      Parameter:
      parent - The parent entity of the children
      children - The list of child entities to initialize
      childDef - The entity definition of the children
      initializing - TRUE if this call occurs during the initialization of the object tree or FALSE for the manipulation of an existing object hierarchy
    • isDeleteAllowed

      public boolean isDeleteAllowed()
      Angegeben von:
      isDeleteAllowed in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.isDeleteAllowed()
    • isHierarchyAttribute

      public boolean isHierarchyAttribute(org.obrel.core.RelationType<?> attribute)
      Angegeben von:
      isHierarchyAttribute in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
    • mapValue

      public Object mapValue(org.obrel.core.RelationType<?> attribute, Object value)
      Overridden to map entity references to entity IDs.
      Angegeben von:
      mapValue in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Setzt außer Kraft:
      mapValue in Klasse de.esoco.storage.mapping.AbstractStorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • AbstractStorageMapping.mapValue(Relatable, Object)
    • setAttributeValue

      public void setAttributeValue(E entity, org.obrel.core.RelationType<?> attribute, Object value)
      Angegeben von:
      setAttributeValue in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.setAttributeValue(Object, Relatable, Object)
    • setChildren

      public void setChildren(E parent, List<?> children, EntityDefinition<?> childDef)
      Angegeben von:
      setChildren in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • StorageMapping.setChildren(Object, List, StorageMapping)
    • storeReference

      public void storeReference(org.obrel.core.Relatable sourceObject, E referencedEntity)
      Overridden to store the referenced entity with EntityManager.storeEntity(Entity, Entity).
      Angegeben von:
      storeReference in Schnittstelle de.esoco.storage.StorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Setzt außer Kraft:
      storeReference in Klasse de.esoco.storage.mapping.AbstractStorageMapping<E extends Entity,org.obrel.core.RelationType<?>,EntityDefinition<?>>
      Siehe auch:
      • AbstractStorageMapping.storeReference(Relatable, Object)
    • toDebugString

      public String toDebugString()
      Returns a string representation of this entity for debugging purpose, which includes a list of it's attribute types.
      Gibt zurück:
      The debug string representation of this definition
    • toString

      public final String toString()
      Returns a string representation of this definition.
      Setzt außer Kraft:
      toString in Klasse org.obrel.core.RelatedObject
      Siehe auch:
    • createEntityInstance

      protected E createEntityInstance(List<?> attributeValues)
      Creates a new instance of the entity class. If the entity has a type attribute and a subclass that has the same name as the type value in the attribute values (converted to camel case) a subclass of that type will be created instead.
      Parameter:
      attributeValues - The attribute values of the new instance
      Gibt zurück:
      The new entity
    • getAttributeIndex

      protected final int getAttributeIndex(org.obrel.core.RelationType<?> attr)
      A method for subclasses to query the index of a particular attribute.
      Parameter:
      attr - The attribute relation type
      Gibt zurück:
      The attribute index or -1 if not found
    • init

      protected final void init(String entityName, String idPrefix, Class<E> entityClass, List<org.obrel.core.RelationType<?>> attr)
      Internal initialization method that builds the map of attribute relation types.
      Parameter:
      entityName - The name of this entity definition
      idPrefix - The prefix for global entity IDs
      entityClass - The Entity class to be used for new instances
      attr - A list containing the attribute relation types
    • initEntityReference

      protected void initEntityReference(E entity, org.obrel.core.RelationType<Entity> entityRefAttr, Object referenceId)
      Initializes an entity reference attribute with an intermediate relation.
      Parameter:
      entity - The entity to init the relation on
      entityRefAttr - The entity reference attribute
      referenceId - The referenced entity's ID
    • initRelationTypeAttribute

      protected void initRelationTypeAttribute(E entity, org.obrel.core.RelationType<org.obrel.core.RelationType<?>> relationTypeAttr, String typeName)
      Initializes an attribute that refers to a relation type. If the relation type cannot be retrieved by it's name because it hasn't been initialized yet an intermediate relation will be created that tries to resolve the relation type on the first access.
    • readResolve

      protected final Object readResolve() throws ObjectStreamException
      Implemented to return the singleton entity definition instance for the entity class that has been read by the deserialization. Defined as protected and final so that it applies to all subclasses as well.
      Gibt zurück:
      The resolved entity definition instance
      Löst aus:
      ObjectStreamException - If no entity definition is available for the deserialized class