Package de.esoco.entity
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
Modifizierer und TypKlasseBeschreibungstatic enum
Enumeration of entity display modes -
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic 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 classstatic 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
ModifiziererKonstruktorBeschreibungprotected
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 TypMethodeBeschreibungcheckAttributeValue
(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.Class
<?> 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<?>> getDisplayAttributes
(EntityDefinition.DisplayMode displayMode) 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.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.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
Forwarded toEntityManager.isDeletionEnabledFor(Class)
.boolean
isHierarchyAttribute
(org.obrel.core.RelationType<?> attribute) 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 withEntityManager.storeEntity(Entity, Entity)
.Returns a string representation of this entity for debugging purpose, which includes a list of it's attribute types.final String
toString()
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
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
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
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
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 typeJdbcRelationTypes.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
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 theEntityDefinition.DisplayMode
enum.- Siehe auch:
-
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
Creates a new instance from a certain entity class. Internally the methodinit(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
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 foridPrefix
- The prefix for global entity IDs
-
-
Methodendetails
-
checkAttributeValue
- Angegeben von:
checkAttributeValue
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Setzt außer Kraft:
checkAttributeValue
in Klassede.esoco.storage.mapping.AbstractStorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
createObject
- Angegeben von:
createObject
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
getAttribute
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
- Angegeben von:
getAttributeDatatype
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
getAttributeValue
- Angegeben von:
getAttributeValue
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
getAttributes
- Angegeben von:
getAttributes
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
getChildAttributes
Returns the relation types of the child attributes of this definition.- Gibt zurück:
- A collection of the child attribute relation types
-
getChildMappings
- Angegeben von:
getChildMappings
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
getChildren
- Angegeben von:
getChildren
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
getDefaultCriteria
Overridden to return a prediate for a type attribute value if a specific sub-class of the entity type exists.- Angegeben von:
getDefaultCriteria
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
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
Returns the descriptive entity name.- Gibt zurück:
- The entity name
-
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
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 eitherInteger
orLong
.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 Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
getIdPrefix
Returns the prefix that will be added to global entity IDs.- Gibt zurück:
- The ID prefix
-
getMappedType
- Angegeben von:
getMappedType
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
getMasterAttribute
Returns the master attribute if such exists.- Gibt zurück:
- The master attribute or NULL for none
-
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 typeStandardTypes.NAME
or any other string attribute that has the meta relation typeMetaTypes.OBJECT_NAME_ATTRIBUTE
set.- Gibt zurück:
- The name attribute of the entity or NULL for none
-
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 Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
getRootAttribute
Returns the root parent attribute if such exists.- Gibt zurück:
- The root attribute or NULL for none
-
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
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 typeMetaTypes.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. -
initChildren
- Angegeben von:
initChildren
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
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 childrenchildren
- The list of child entities to initializechildDef
- The entity definition of the childreninitializing
- 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()Forwarded toEntityManager.isDeletionEnabledFor(Class)
.- Angegeben von:
isDeleteAllowed
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
isHierarchyAttribute
public boolean isHierarchyAttribute(org.obrel.core.RelationType<?> attribute) - Angegeben von:
isHierarchyAttribute
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>>
-
mapValue
Overridden to map entity references to entity IDs.- Angegeben von:
mapValue
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Setzt außer Kraft:
mapValue
in Klassede.esoco.storage.mapping.AbstractStorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
setAttributeValue
- Angegeben von:
setAttributeValue
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
setChildren
- Angegeben von:
setChildren
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
storeReference
Overridden to store the referenced entity withEntityManager.storeEntity(Entity, Entity)
.- Angegeben von:
storeReference
in Schnittstellede.esoco.storage.StorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Setzt außer Kraft:
storeReference
in Klassede.esoco.storage.mapping.AbstractStorageMapping<E extends Entity,
org.obrel.core.RelationType<?>, EntityDefinition<?>> - Siehe auch:
-
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
Returns a string representation of this definition.- Setzt außer Kraft:
toString
in Klasseorg.obrel.core.RelatedObject
- Siehe auch:
-
createEntityInstance
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 definitionidPrefix
- The prefix for global entity IDsentityClass
- The Entity class to be used for new instancesattr
- 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 onentityRefAttr
- The entity reference attributereferenceId
- 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
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
-