Class Entity<E extends Entity<E,A,R>, A extends Attribute<E,A,R>, R extends Relationship<E,A,R>>

java.lang.Object
org.apache.cayenne.map.Entity<E,A,R>
All Implemented Interfaces:
XMLSerializable
Direct Known Subclasses:
DbEntity, ObjEntity

public abstract class Entity<E extends Entity<E,A,R>, A extends Attribute<E,A,R>, R extends Relationship<E,A,R>> extends Object implements XMLSerializable
An abstract descriptor for an entity mapping concept. Entity can represent either a descriptor of database table or a persistent object.
  • Field Details

  • Constructor Details

    • Entity

      public Entity()
      Creates an unnamed Entity.
    • Entity

      public Entity(String name)
      Creates a named Entity.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getName

      public String getName()
      Returns entity name. Name is a unique identifier of the entity within its DataMap.
    • setName

      public void setName(String name)
    • getDataMap

      public DataMap getDataMap()
      Returns:
      parent DataMap of this entity.
    • setDataMap

      public void setDataMap(DataMap dataMap)
      Sets parent DataMap of this entity.
    • getAttribute

      public A getAttribute(String attributeName)
      Returns attribute with name attributeName or null if no attribute with this name exists.
    • addAttribute

      public void addAttribute(A attribute)
      Adds new attribute to the entity, setting its parent entity to be this object. If attribute has no name, IllegalArgumentException is thrown.
    • removeAttribute

      public void removeAttribute(String attrName)
      Removes an attribute named attrName.
    • updateAttribute

      public void updateAttribute(A attribute)
      Since:
      4.0
    • clearAttributes

      public void clearAttributes()
    • getRelationship

      public R getRelationship(String relName)
      Returns relationship with name relName. Will return null if no relationship with this name exists in the entity.
    • addRelationship

      public void addRelationship(R relationship)
      Adds new relationship to the entity.
    • removeRelationship

      public void removeRelationship(String relName)
      Removes a relationship named attrName.
    • clearRelationships

      public void clearRelationships()
    • getRelationshipMap

      public Map<String,R> getRelationshipMap()
      Returns an unmodifiable map of relationships sorted by name.
    • getAnyRelationship

      public R getAnyRelationship(E targetEntity)
      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

      public Collection<R> getRelationships()
      Returns an unmodifiable collection of Relationships that exist in this entity.
    • getAttributeMap

      public Map<String,A> getAttributeMap()
      Returns an unmodifiable sorted map of entity attributes.
    • getAttributes

      public Collection<A> getAttributes()
      Returns an unmodifiable collection of entity attributes.
    • translateToRelatedEntity

      public Expression translateToRelatedEntity(Expression expression, String relationshipPath)
      Translates Expression rooted in this entity to an analogous expression rooted in related entity.
      Since:
      1.1
    • translateToRelatedEntity

      public abstract Expression translateToRelatedEntity(Expression expression, CayennePath relationshipPath)
      Transforms Expression rooted in this entity to an analogous expression rooted in related entity.
      Since:
      5.0
    • resolvePath

      public List<Object> resolvePath(String path) throws ExpressionException
      Resolves the path against this entity into a list of Attributes and Relationships, one per path segment. An invalid path results in an ExpressionException.
      Throws:
      ExpressionException
      Since:
      5.0
    • resolvePath

      public List<Object> resolvePath(CayennePath path) throws ExpressionException
      Resolves the path against this entity into a list of Attributes and Relationships, one per path segment. Aliases are not resolved here: expand them first with CayennePath.expandAliases(Map). An invalid path results in an ExpressionException.
      Throws:
      ExpressionException
      Since:
      5.0