Package org.apache.cayenne.map
Class Entity
java.lang.Object
org.apache.cayenne.map.Entity
- All Implemented Interfaces:
Serializable
,CayenneMapEntry
,XMLSerializable
public abstract class Entity
extends Object
implements CayenneMapEntry, XMLSerializable, Serializable
An Entity is an abstract descriptor for an entity mapping concept. Entity can represent
either a descriptor of database table or a persistent object.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(Attribute attribute) Adds new attribute to the entity, setting its parent entity to be this object.void
addRelationship
(Relationship relationship) Adds new relationship to the entity.void
void
getAnyRelationship
(Entity targetEntity) Returns a relationship that has a specified entity as a target.getAttribute
(String attributeName) Returns attribute with nameattributeName
or null if no attribute with this name exists.Returns an unmodifiable sorted map of entity attributes.Collection
<? extends Attribute> Returns an unmodifiable collection of entity attributes.getName()
Returns entity name.Returns the parent map.getRelationship
(String relName) Returns relationship with namerelName
.Map
<String, ? extends Relationship> Returns an unmodifiable map of relationships sorted by name.Collection
<? extends Relationship> Returns an unmodifiable collection of Relationships that exist in this entity.<T extends Attribute,
U extends Relationship>
PathComponent<T, U> lastPathComponent
(Expression path, Map aliasMap) Convenience method returning the last component in the path iterator.void
removeAttribute
(String attrName) Removes an attribute namedattrName
.void
removeRelationship
(String relName) Removes a relationship namedattrName
.abstract <T extends Attribute,
U extends Relationship>
Iterable<PathComponent<T, U>> resolvePath
(Expression pathExp, Map aliasMap) Returns an Iterable over the path components with elements represented asPathComponent
instances, encapsulating a relationship, an attribute or a subpath alias.resolvePathComponents
(String path) Returns an Iterator over the path components that contains a sequence of Attributes and Relationships.abstract Iterator
<CayenneMapEntry> resolvePathComponents
(Expression pathExp) Processes expressionpathExp
and returns an Iterator of path components that contains a sequence of Attributes and Relationships.void
setDataMap
(DataMap dataMap) Sets parent DataMap of this entity.void
void
Stores the parent map.toString()
abstract Expression
translateToRelatedEntity
(Expression expression, String relationshipPath) Translates Expression rooted in this entity to an analogous expression rooted in related entity.void
updateAttribute
(Attribute attribute) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.cayenne.util.XMLSerializable
encodeAsXML
-
Field Details
-
PATH_SEPARATOR
- See Also:
-
OUTER_JOIN_INDICATOR
A prefix or a suffix that can be used in a path component to indicate that an OUTER JOIN should be used when resolving the expression.- Since:
- 3.0
- See Also:
-
name
-
dataMap
-
attributes
-
relationships
-
-
Constructor Details
-
Entity
public Entity()Creates an unnamed Entity. -
Entity
Creates a named Entity.
-
-
Method Details
-
toString
-
getName
Returns entity name. Name is a unique identifier of the entity within its DataMap.- Specified by:
getName
in interfaceCayenneMapEntry
- Returns:
- name of this entry.
-
setName
-
getParent
Description copied from interface:CayenneMapEntry
Returns the parent map.- Specified by:
getParent
in interfaceCayenneMapEntry
-
setParent
Description copied from interface:CayenneMapEntry
Stores the parent map.- Specified by:
setParent
in interfaceCayenneMapEntry
-
getDataMap
- Returns:
- parent DataMap of this entity.
-
setDataMap
Sets parent DataMap of this entity. -
getAttribute
Returns attribute with nameattributeName
or null if no attribute with this name exists. -
addAttribute
Adds new attribute to the entity, setting its parent entity to be this object. If attribute has no name, IllegalArgumentException is thrown. -
removeAttribute
Removes an attribute namedattrName
. -
updateAttribute
- Since:
- 4.0
-
clearAttributes
public void clearAttributes() -
getRelationship
Returns relationship with namerelName
. Will return null if no relationship with this name exists in the entity. -
addRelationship
Adds new relationship to the entity. -
removeRelationship
Removes a relationship namedattrName
. -
clearRelationships
public void clearRelationships() -
getRelationshipMap
Returns an unmodifiable map of relationships sorted by name. -
getAnyRelationship
Returns a relationship that has a specified entity as a target. If there is more than one relationship for the same target, it is unpredictable which one will be returned.- Since:
- 1.1
-
getRelationships
Returns an unmodifiable collection of Relationships that exist in this entity. -
getAttributeMap
Returns an unmodifiable sorted map of entity attributes. -
getAttributes
Returns an unmodifiable collection of entity attributes. -
translateToRelatedEntity
Translates Expression rooted in this entity to an analogous expression rooted in related entity.- Since:
- 1.1
-
lastPathComponent
public <T extends Attribute,U extends Relationship> PathComponent<T,U> lastPathComponent(Expression path, Map aliasMap) Convenience method returning the last component in the path iterator. If the last component is an alias, it is fully resolved down to the last ObjRelationship.- Since:
- 3.0
-
resolvePath
public abstract <T extends Attribute,U extends Relationship> Iterable<PathComponent<T,U>> resolvePath(Expression pathExp, Map aliasMap) Returns an Iterable over the path components with elements represented asPathComponent
instances, encapsulating a relationship, an attribute or a subpath alias. An optional "aliasMap" parameter is used to resolve subpaths from aliases.This method is lazy: if path is invalid and can not be resolved from this entity, this method will still return an Iterator, but an attempt to read the first invalid path component will result in ExpressionException.
- Since:
- 3.0
-
resolvePathComponents
public abstract Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp) throws ExpressionException Processes expressionpathExp
and returns an Iterator of path components that contains a sequence of Attributes and Relationships. Note that if path is invalid and can not be resolved from this entity, this method will still return an Iterator, but an attempt to read the first invalid path component will result in ExpressionException.- Throws:
ExpressionException
-
resolvePathComponents
Returns an Iterator over the path components that contains a sequence of Attributes and Relationships. Note that if path is invalid and can not be resolved from this entity, this method will still return an Iterator, but an attempt to read the first invalid path component will result in ExpressionException.- Throws:
ExpressionException
-