Package org.apache.cayenne.map

# Class ObjEntity

java.lang.Object
org.apache.cayenne.map.Entity<ObjEntity,ObjAttribute,ObjRelationship>
org.apache.cayenne.map.ObjEntity

All Implemented Interfaces:
  `Serializable`, `EventListener`, `ConfigurationNode`, `ObjEntityListener`, `CayenneMapEntry`, `XMLSerializable`

public class ObjEntity extends Entity<ObjEntity,ObjAttribute,ObjRelationship> implements ObjEntityListener, ConfigurationNode
ObjEntity is a mapping descriptor for a Persistent Java class. It contains the information about the Java class itself, as well as its mapping to the DbEntity layer.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected boolean`
  `_abstract`
  `protected Map<String,CayennePath>`
  `attributeOverrides`
  `protected CallbackMap`
  `callbacks`
  `protected String`
  `className`
  `protected String`
  `dbEntityName`
  `protected static final Collection<String>`
  `DEFAULT_GENERIC_CLASSES`
  A collection of default "generic" entity classes excluded from class generation.
  `static final int`
  `LOCK_TYPE_NONE`
  `static final int`
  `LOCK_TYPE_OPTIMISTIC`
  `protected int`
  `lockType`
  `protected Expression`
  `qualifier`
  `protected boolean`
  `readOnly`
  `protected String`
  `superClassName`
  `protected String`
  `superEntityName`

  ### Fields inherited from class org.apache.cayenne.map.Entity

  `attributes, dataMap, name, OUTER_JOIN_INDICATOR, PATH_SEPARATOR, relationships`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ObjEntity()`
  `ObjEntity(String name)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T> T`
  `acceptVisitor(ConfigurationNodeVisitor<T> visitor)`
  `void`
  `addAttributeOverride(String attributeName, String dbPath)`
  `void`
  `addAttributeOverride(String attributeName, CayennePath dbPath)`
  `void`
  `clearDbMapping()`
  Clears all the mapping between this obj entity and its current db entity.
  `void`
  `encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)`
  Prints itself as XML to the provided XMLEncoder.
  `ObjAttribute`
  `getAttribute(String name)`
  Returns a named attribute that is either declared in this ObjEntity or is inherited.
  `ObjAttribute`
  `getAttributeForDbAttribute(DbAttribute dbAttribute)`
  Returns ObjAttribute of this entity that maps to `dbAttribute` parameter.
  `Map<String,ObjAttribute>`
  `getAttributeMap()`
  Returns a Map of all attributes that either belong to this ObjEntity or inherited.
  `Collection<ObjAttribute>`
  `getAttributes()`
  Returns a Collection of all attributes that either belong to this ObjEntity or inherited.
  `CallbackMap`
  `getCallbackMap()`
  Returns an object that stores callback methods of this entity.
  `Set<String>`
  `getCallbackMethods()`
  `String`
  `getClassName()`
  Returns the name of Persistent class described by this entity.
  `DbEntity`
  `getDbEntity()`
  Returns a DbEntity associated with this ObjEntity.
  `String`
  `getDbEntityName()`
  Returns the name of the underlying DbEntity.
  `ObjAttribute`
  `getDeclaredAttribute(String name)`
  Finds attribute declared by this ObjEntity, excluding inherited attributes.
  `Map<String,CayennePath>`
  `getDeclaredAttributeOverrides()`
  `Collection<ObjAttribute>`
  `getDeclaredAttributes()`
  Returns a Collection of all attributes that belong to this ObjEntity, excluding inherited attributes.
  `int`
  `getDeclaredLockType()`
  Returns the type of lock used by this ObjEntity, regardless of what locking type is used by super entities.
  `Expression`
  `getDeclaredQualifier()`
  Returns a qualifier that imposes a restriction on what objects belong to this entity.
  `Collection<ObjRelationship>`
  `getDeclaredRelationships()`
  Returns a Collection of all relationships that belong to this ObjEntity, excluding inherited attributes.
  `String`
  `getJavaClassName()`
  Returns a non-null class name.
  `int`
  `getLockType()`
  Returns the type of lock used by this ObjEntity.
  `Collection<String>`
  `getPrimaryKeyNames()`
  Returns the names of DbAtributes that comprise the primary key of the parent DbEntity.
  `Collection<ObjAttribute>`
  `getPrimaryKeys()`
  Returns an unmodifiable collection of ObjAttributes representing the primary key of the table described by this DbEntity.
  `ObjRelationship`
  `getRelationship(String name)`
  Returns a named Relationship that either belongs to this ObjEntity or is inherited.
  `ObjRelationship`
  `getRelationshipForDbRelationship(DbRelationship dbRelationship)`
  Returns ObjRelationship of this entity that maps to `dbRelationship` parameter.
  `Map<String,ObjRelationship>`
  `getRelationshipMap()`
  Returns an unmodifiable map of relationships sorted by name.
  `Collection<ObjRelationship>`
  `getRelationships()`
  Returns an unmodifiable collection of Relationships that exist in this entity.
  `String`
  `getSuperClassName()`
  Returns a fully-qualified name of the super class of the Persistent class.
  `ObjEntity`
  `getSuperEntity()`
  Returns a "super" entity in the entity inheritance hierarchy.
  `String`
  `getSuperEntityName()`
  Returns an entity name for a parent entity in the inheritance hierarchy.
  `boolean`
  `isAbstract()`
  `boolean`
  `isGeneric()`
  Returns whether this entity is "generic", meaning it is not mapped to a unique Java class.
  `boolean`
  `isReadOnly()`
  Returns `true` if this ObjEntity represents a set of read-only objects.
  `boolean`
  `isSubentityOf(ObjEntity entity)`
  Returns true if this entity directly or indirectly inherits from a given entity, false otherwise.
  `void`
  `objEntityAdded(EntityEvent e)`
  New entity has been created/added.
  `void`
  `objEntityChanged(EntityEvent e)`
  ObjEntity property changed.
  `void`
  `objEntityRemoved(EntityEvent e)`
  Entity has been removed.
  `void`
  `removeAttributeOverride(String attributeName)`
  `Iterable<PathComponent<ObjAttribute,ObjRelationship>>`
  `resolvePath(Expression pathExp, Map<String,String> aliasMap)`
  Returns an Iterable instance over expression path components based on this entity.
  `Iterator<CayenneMapEntry>`
  `resolvePathComponents(Expression pathExp)`
  Processes expression `pathExp` and returns an Iterator of path components that contains a sequence of Attributes and Relationships.
  `void`
  `setAbstract(boolean isAbstract)`
  Sets whether this entity is abstract only.
  `void`
  `setClassName(String className)`
  Sets the name of the Persistent class described by this entity.
  `void`
  `setDbEntity(DbEntity dbEntity)`
  Sets the DbEntity used by this ObjEntity.
  `void`
  `setDbEntityName(String string)`
  Sets the name of underlying DbEntity.
  `void`
  `setDeclaredLockType(int i)`
  Sets the type of lock used by this ObjEntity.
  `void`
  `setDeclaredQualifier(Expression qualifier)`
  Sets a qualifier that imposes a limit on what objects belong to this entity.
  `void`
  `setReadOnly(boolean readOnly)`
  `void`
  `setSuperClassName(String superClassName)`
  Sets a fully-qualified name of the super class of the Persistent class.
  `void`
  `setSuperEntityName(String superEntityName)`
  Sets an entity name for a parent entity in the inheritance hierarchy.
  `Expression`
  `translateToDbPath(Expression expression)`
  Transforms an Expression to an analogous expression in terms of the underlying DbEntity.
  `Expression`
  `translateToRelatedEntity(Expression expression, String relationshipPath)`
  Transforms an Expression rooted in this entity to an analogous expression rooted in related entity.
  `Expression`
  `translateToRelatedEntity(Expression expression, CayennePath relationshipPath)`
  Transforms an Expression rooted in this entity to an analogous expression rooted in related entity.

  ### Methods inherited from class org.apache.cayenne.map.Entity

  `addAttribute, addRelationship, clearAttributes, clearRelationships, getAnyRelationship, getDataMap, getName, getParent, lastPathComponent, removeAttribute, removeRelationship, resolvePathComponents, resolvePathComponents, setDataMap, setName, setParent, toString, updateAttribute`

  ### Methods inherited from class java.lang.Object

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

- ## Field Details

  - ### LOCK_TYPE_NONE

    public static final int LOCK_TYPE_NONE
    See Also:
      - Constant Field Values

  - ### LOCK_TYPE_OPTIMISTIC

    public static final int LOCK_TYPE_OPTIMISTIC
    See Also:
      - Constant Field Values

  - ### DEFAULT_GENERIC_CLASSES

    protected static final Collection<String> DEFAULT_GENERIC_CLASSES
    A collection of default "generic" entity classes excluded from class generation.
    Since:
      1.2

  - ### superClassName

    protected String superClassName

  - ### className

    protected String className

  - ### dbEntityName

    protected String dbEntityName

  - ### superEntityName

    protected String superEntityName

  - ### qualifier

    protected Expression qualifier

  - ### readOnly

    protected boolean readOnly

  - ### lockType

    protected int lockType

  - ### _abstract

    protected boolean _abstract

  - ### callbacks

    protected CallbackMap callbacks

  - ### attributeOverrides

    protected Map<String,CayennePath> attributeOverrides

- ## Constructor Details

  - ### ObjEntity

    public ObjEntity()

  - ### ObjEntity

    public ObjEntity(String name)

- ## Method Details

  - ### acceptVisitor

    public <T> T acceptVisitor(ConfigurationNodeVisitor<T> visitor)
    Specified by:
      `acceptVisitor` in interface `ConfigurationNode`
    Since:
      3.1

  - ### encodeAsXML

    public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)
    Prints itself as XML to the provided XMLEncoder.
    Specified by:
      `encodeAsXML` in interface `XMLSerializable`
    Since:
      1.1

  - ### getJavaClassName

    public String getJavaClassName()
    Returns a non-null class name. For generic entities with no class specified explicitly, default DataMap superclass is used, and if it is not set - GenericPersistentObject is used.
    Since:
      4.0

  - ### getCallbackMap

    public CallbackMap getCallbackMap()
    Returns an object that stores callback methods of this entity.
    Since:
      3.0

  - ### getLockType

    public int getLockType()
    Returns the type of lock used by this ObjEntity. If this entity is not locked, this method would look in a super entity recursively, until it finds a lock somewhere in the inheritance hierarchy.
    Since:
      1.1

  - ### getDeclaredLockType

    public int getDeclaredLockType()
    Returns the type of lock used by this ObjEntity, regardless of what locking type is used by super entities.
    Since:
      1.1

  - ### setDeclaredLockType

    public void setDeclaredLockType(int i)
    Sets the type of lock used by this ObjEntity.
    Since:
      1.1

  - ### isGeneric

    public boolean isGeneric()
    Returns whether this entity is "generic", meaning it is not mapped to a unique Java class. Criterion for generic entities is that it either has no Java class mapped or its class is the same as DataMap's default superclass, or it is GenericPersistentObject.
    Since:
      1.2

  - ### isAbstract

    public boolean isAbstract()

  - ### setAbstract

    public void setAbstract(boolean isAbstract)
    Sets whether this entity is abstract only.

  - ### getDeclaredQualifier

    public Expression getDeclaredQualifier()
    Returns a qualifier that imposes a restriction on what objects belong to this entity. Returned qualifier is the one declared in this entity, and does not include qualifiers declared in super entities.
    Since:
      1.1

  - ### getSuperEntityName

    public String getSuperEntityName()
    Returns an entity name for a parent entity in the inheritance hierarchy.
    Since:
      1.1

  - ### setDeclaredQualifier

    public void setDeclaredQualifier(Expression qualifier)
    Sets a qualifier that imposes a limit on what objects belong to this entity.
    Since:
      1.1

  - ### setSuperEntityName

    public void setSuperEntityName(String superEntityName)
    Sets an entity name for a parent entity in the inheritance hierarchy.
    Since:
      1.1

  - ### getClassName

    public String getClassName()
    Returns the name of Persistent class described by this entity.

  - ### setClassName

    public void setClassName(String className)
    Sets the name of the Persistent class described by this entity.

  - ### getSuperClassName

    public String getSuperClassName()
    Returns a fully-qualified name of the super class of the Persistent class. This value is used as a hint for class generation. If the entity inherits from another entity, a superclass is the class of that entity.

  - ### setSuperClassName

    public void setSuperClassName(String superClassName)
    Sets a fully-qualified name of the super class of the Persistent class. This value is used as a hint for class generation.

    An attempt to set superclass on an inherited entity has no effect, since a class of the super entity is always used as a superclass.

  - ### getSuperEntity

    public ObjEntity getSuperEntity()
    Returns a "super" entity in the entity inheritance hierarchy.
    Since:
      1.1

  - ### getDbEntity

    public DbEntity getDbEntity()
    Returns a DbEntity associated with this ObjEntity.

  - ### setDbEntity

    public void setDbEntity(DbEntity dbEntity)
    Sets the DbEntity used by this ObjEntity.

    Setting DbEntity on an inherited entity has no effect, since a class of the super entity is always used as a superclass.

  - ### getPrimaryKeys

    public Collection<ObjAttribute> getPrimaryKeys()
    Returns an unmodifiable collection of ObjAttributes representing the primary key of the table described by this DbEntity. Note that since PK is very often not an object property, the returned collection may contain "synthetic" ObjAttributes that are created on the fly and are not a part of ObjEntity and will not be a part of entity.getAttributes().
    Since:
      3.0

  - ### getAttribute

    public ObjAttribute getAttribute(String name)
    Returns a named attribute that is either declared in this ObjEntity or is inherited. In any case returned attribute 'getEntity' method will return this entity. Returns null if no matching attribute is found.
    Overrides:
      `getAttribute` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`

  - ### getAttributeMap

    public Map<String,ObjAttribute> getAttributeMap()
    Returns a Map of all attributes that either belong to this ObjEntity or inherited.
    Overrides:
      `getAttributeMap` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`

  - ### addAttributeOverride

    public void addAttributeOverride(String attributeName, String dbPath)
    Since:
      3.0
    See Also:
      - `addAttributeOverride(String, CayennePath)`

  - ### addAttributeOverride

    public void addAttributeOverride(String attributeName, CayennePath dbPath)
    Since:
      5.0

  - ### removeAttributeOverride

    public void removeAttributeOverride(String attributeName)
    Since:
      4.0

  - ### getDeclaredAttributeOverrides

    public Map<String,CayennePath> getDeclaredAttributeOverrides()
    Since:
      3.0, 5.0 result map uses `CayennePath` instead of String as values

  - ### getAttributes

    public Collection<ObjAttribute> getAttributes()
    Returns a Collection of all attributes that either belong to this ObjEntity or inherited.
    Overrides:
      `getAttributes` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`

  - ### getDeclaredAttributes

    public Collection<ObjAttribute> getDeclaredAttributes()
    Returns a Collection of all attributes that belong to this ObjEntity, excluding inherited attributes.
    Since:
      1.1

  - ### getDeclaredAttribute

    public ObjAttribute getDeclaredAttribute(String name)
    Finds attribute declared by this ObjEntity, excluding inherited attributes.
    Parameters:
      `name` - of the attribute
    Returns:
      declared attribute or null if no attribute is found
    Since:
      4.0
    See Also:
      - `getAttribute(String)`

  - ### getRelationship

    public ObjRelationship getRelationship(String name)
    Returns a named Relationship that either belongs to this ObjEntity or is inherited. Returns null if no matching attribute is found.
    Overrides:
      `getRelationship` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`

  - ### getRelationshipMap

    public Map<String,ObjRelationship> getRelationshipMap()
    Description copied from class: `Entity`
    Returns an unmodifiable map of relationships sorted by name.
    Overrides:
      `getRelationshipMap` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`

  - ### getRelationships

    public Collection<ObjRelationship> getRelationships()
    Description copied from class: `Entity`
    Returns an unmodifiable collection of Relationships that exist in this entity.
    Overrides:
      `getRelationships` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`

  - ### getDeclaredRelationships

    public Collection<ObjRelationship> getDeclaredRelationships()
    Returns a Collection of all relationships that belong to this ObjEntity, excluding inherited attributes.
    Since:
      1.1

  - ### getAttributeForDbAttribute

    public ObjAttribute getAttributeForDbAttribute(DbAttribute dbAttribute)
    Returns ObjAttribute of this entity that maps to `dbAttribute` parameter. Returns null if no such attribute is found.

  - ### getPrimaryKeyNames

    public Collection<String> getPrimaryKeyNames()
    Returns the names of DbAtributes that comprise the primary key of the parent DbEntity.
    Since:
      3.0

  - ### getRelationshipForDbRelationship

    public ObjRelationship getRelationshipForDbRelationship(DbRelationship dbRelationship)
    Returns ObjRelationship of this entity that maps to `dbRelationship` parameter. Returns null if no such relationship is found.

  - ### clearDbMapping

    public void clearDbMapping()
    Clears all the mapping between this obj entity and its current db entity. Clears mapping between entities, attributes and relationships.

  - ### isReadOnly

    public boolean isReadOnly()
    Returns `true` if this ObjEntity represents a set of read-only objects.
    Returns:
      boolean

  - ### setReadOnly

    public void setReadOnly(boolean readOnly)

  - ### isSubentityOf

    public boolean isSubentityOf(ObjEntity entity)
    Returns true if this entity directly or indirectly inherits from a given entity, false otherwise.
    Since:
      1.1

  - ### resolvePath

    public Iterable<PathComponent<ObjAttribute,ObjRelationship>> resolvePath(Expression pathExp, Map<String,String> aliasMap)
    Returns an Iterable instance over expression path components based on this entity.
    Specified by:
      `resolvePath` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`
    Since:
      3.0

  - ### resolvePathComponents

    public Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp) throws ExpressionException
    Description copied from class: `Entity`
    Processes expression `pathExp` 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.
    Specified by:
      `resolvePathComponents` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`
    Throws:
      `ExpressionException`

  - ### translateToDbPath

    public Expression translateToDbPath(Expression expression)
    Transforms an Expression to an analogous expression in terms of the underlying DbEntity.
    Since:
      1.1

  - ### translateToRelatedEntity

    public Expression translateToRelatedEntity(Expression expression, String relationshipPath)
    Transforms an Expression rooted in this entity to an analogous expression rooted in related entity.
    Overrides:
      `translateToRelatedEntity` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`
    Since:
      1.1
    See Also:
      - `translateToRelatedEntity(Expression, CayennePath)`

  - ### translateToRelatedEntity

    public Expression translateToRelatedEntity(Expression expression, CayennePath relationshipPath)
    Transforms an Expression rooted in this entity to an analogous expression rooted in related entity.
    Specified by:
      `translateToRelatedEntity` in class `Entity<ObjEntity,ObjAttribute,ObjRelationship>`
    Parameters:
      `expression` - expression to translate
      `relationshipPath` - path to the related entity
    Returns:
      transformed expression
    Since:
      5.0

  - ### getCallbackMethods

    public Set<String> getCallbackMethods()
    Since:
      4.0

  - ### getDbEntityName

    public String getDbEntityName()
    Returns the name of the underlying DbEntity.
    Since:
      1.1

  - ### setDbEntityName

    public void setDbEntityName(String string)
    Sets the name of underlying DbEntity.
    Since:
      1.1

  - ### objEntityChanged

    public void objEntityChanged(EntityEvent e)
    ObjEntity property changed. May be name, attribute or relationship added or removed, etc. Attribute and relationship property changes are handled in respective listeners.
    Specified by:
      `objEntityChanged` in interface `ObjEntityListener`
    Since:
      1.2

  - ### objEntityAdded

    public void objEntityAdded(EntityEvent e)
    New entity has been created/added.
    Specified by:
      `objEntityAdded` in interface `ObjEntityListener`

  - ### objEntityRemoved

    public void objEntityRemoved(EntityEvent e)
    Entity has been removed.
    Specified by:
      `objEntityRemoved` in interface `ObjEntityListener`