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:
- Serialized Form
- 
Field SummaryFields Modifier and Type Field Description protected Map<String,Attribute>attributesprotected DataMapdataMapprotected Stringnamestatic StringOUTER_JOIN_INDICATORA 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.static StringPATH_SEPARATORprotected Map<String,Relationship>relationships
- 
Constructor Summary
- 
Method SummaryModifier and Type Method Description voidaddAttribute(Attribute attribute)Adds new attribute to the entity, setting its parent entity to be this object.voidaddRelationship(Relationship relationship)Adds new relationship to the entity.voidclearAttributes()voidclearRelationships()RelationshipgetAnyRelationship(Entity targetEntity)Returns a relationship that has a specified entity as a target.AttributegetAttribute(String attributeName)Returns attribute with nameattributeNameor null if no attribute with this name exists.Map<String,? extends Attribute>getAttributeMap()Returns an unmodifiable sorted map of entity attributes.Collection<? extends Attribute>getAttributes()Returns an unmodifiable collection of entity attributes.DataMapgetDataMap()StringgetName()Returns entity name.ObjectgetParent()Returns the parent map.RelationshipgetRelationship(String relName)Returns relationship with namerelName.Map<String,? extends Relationship>getRelationshipMap()Returns an unmodifiable map of relationships sorted by name.Collection<? extends Relationship>getRelationships()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.voidremoveAttribute(String attrName)Removes an attribute namedattrName.voidremoveRelationship(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 asPathComponentinstances, encapsulating a relationship, an attribute or a subpath alias.Iterator<CayenneMapEntry>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 expressionpathExpand returns an Iterator of path components that contains a sequence of Attributes and Relationships.voidsetDataMap(DataMap dataMap)Sets parent DataMap of this entity.voidsetName(String name)voidsetParent(Object parent)Stores the parent map.StringtoString()abstract ExpressiontranslateToRelatedEntity(Expression expression, String relationshipPath)Translates Expression rooted in this entity to an analogous expression rooted in related entity.voidupdateAttribute(Attribute attribute)Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.cayenne.util.XMLSerializableencodeAsXML
- 
Field Details- 
PATH_SEPARATOR- See Also:
- Constant Field Values
 
- 
OUTER_JOIN_INDICATORA 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:
- Constant Field Values
 
- 
name
- 
dataMap
- 
attributes
- 
relationships
 
- 
- 
Constructor Details- 
Entitypublic Entity()Creates an unnamed Entity.
- 
EntityCreates a named Entity.
 
- 
- 
Method Details- 
toString
- 
getNameReturns entity name. Name is a unique identifier of the entity within its DataMap.- Specified by:
- getNamein interface- CayenneMapEntry
- Returns:
- name of this entry.
 
- 
setName
- 
getParentDescription copied from interface:CayenneMapEntryReturns the parent map.- Specified by:
- getParentin interface- CayenneMapEntry
 
- 
setParentDescription copied from interface:CayenneMapEntryStores the parent map.- Specified by:
- setParentin interface- CayenneMapEntry
 
- 
getDataMap- Returns:
- parent DataMap of this entity.
 
- 
setDataMapSets parent DataMap of this entity.
- 
getAttributeReturns attribute with nameattributeNameor null if no attribute with this name exists.
- 
addAttributeAdds new attribute to the entity, setting its parent entity to be this object. If attribute has no name, IllegalArgumentException is thrown.
- 
removeAttributeRemoves an attribute namedattrName.
- 
updateAttribute- Since:
- 4.0
 
- 
clearAttributespublic void clearAttributes()
- 
getRelationshipReturns relationship with namerelName. Will return null if no relationship with this name exists in the entity.
- 
addRelationshipAdds new relationship to the entity.
- 
removeRelationshipRemoves a relationship namedattrName.
- 
clearRelationshipspublic void clearRelationships()
- 
getRelationshipMapReturns an unmodifiable map of relationships sorted by name.
- 
getAnyRelationshipReturns 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
 
- 
getRelationshipsReturns an unmodifiable collection of Relationships that exist in this entity.
- 
getAttributeMapReturns an unmodifiable sorted map of entity attributes.
- 
getAttributesReturns an unmodifiable collection of entity attributes.
- 
translateToRelatedEntitypublic abstract Expression translateToRelatedEntity(Expression expression, String relationshipPath)Translates Expression rooted in this entity to an analogous expression rooted in related entity.- Since:
- 1.1
 
- 
lastPathComponentpublic <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
 
- 
resolvePathpublic 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 asPathComponentinstances, 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
 
- 
resolvePathComponentspublic abstract Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp) throws ExpressionExceptionProcesses expressionpathExpand 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
 
- 
resolvePathComponentsReturns 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
 
 
-