DbEntity (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.map, class: DbEntity

# Class DbEntity

java.lang.Object
org.apache.cayenne.map.Entity<DbEntity, DbAttribute, DbRelationship>
org.apache.cayenne.map.DbEntity

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

public class DbEntity extends Entity<DbEntity, DbAttribute, DbRelationship> implements ConfigurationNode
A DbEntity is a mapping descriptor that defines a structure of a database table.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected String`
  `catalog`
  `protected Collection<DbAttribute>`
  `generatedAttributes`
  `protected List<DbAttribute>`
  `primaryKey`
  `protected DbKeyGenerator`
  `primaryKeyGenerator`
  `protected Expression`
  `qualifier`
  Qualifier, that will be applied to all select queries and joins with this DbEntity
  `protected String`
  `schema`

  ### Fields inherited from class Entity

  `attributes, dataMap, name, OUTER_JOIN_INDICATOR, PATH_SEPARATOR, relationships`
  Modifier and Type
  Field
  Description
  `protected final Map<String, DbAttribute>`
  `attributes`
  `protected DataMap`
  `dataMap`
  `protected String`
  `name`
  `static final String`
  `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.
  `static final String`
  `PATH_SEPARATOR`
  `protected final Map<String, DbRelationship>`
  `relationships`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DbEntity()`
  Creates an unnamed DbEntity.
  `DbEntity(String name)`
  Creates a named DbEntity.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T> T`
  `acceptVisitor(ConfigurationNodeVisitor<T> visitor)`
  `void`
  `addAttribute(DbAttribute attr)`
  Adds a new attribute to this entity.
  `void`
  `clearAttributes()`
  `void`
  `encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)`
  Prints itself as XML to the provided XMLEncoder.
  `String`
  `getCatalog()`
  Returns the catalog name of the table described by this DbEntity.
  `String`
  `getFullyQualifiedName()`
  Returns table name including catalog and schema, if any of those are present.
  `Collection<DbAttribute>`
  `getGeneratedAttributes()`
  Returns an unmodifiable collection of DbAttributes that are generated by the database.
  `DbKeyGenerator`
  `getPrimaryKeyGenerator()`
  Return the primary key generator for this entity.
  `List<DbAttribute>`
  `getPrimaryKeys()`
  Returns an unmodifiable collection of DbAttributes representing the primary key of the table described by this DbEntity.
  `Expression`
  `getQualifier()`
  `String`
  `getSchema()`
  Returns database schema of this table.
  `boolean`
  `isFullReplacementIdAttached(ObjectId id)`
  Returns true if there is full replacement id is attached to an ObjectId.
  `Collection<ObjEntity>`
  `mappedObjEntities()`
  `void`
  `removeAttribute(String attrName)`
  Removes attribute from the entity, removes any relationship joins containing this attribute.
  `void`
  `renameAttribute(DbAttribute attr, String newName)`
  Renames an attribute owned by this entity, re-keying the attribute map and updating all dependent references across the parent `DataMap`: ObjAttribute paths and DbJoin source/target names.
  `void`
  `renameRelationship(DbRelationship rel, String newName)`
  Renames a relationship owned by this entity, re-keying the relationship map and refreshing dependent ObjAttribute db-paths across the parent `DataMap`.
  `Iterable<PathComponent<DbAttribute, DbRelationship>>`
  `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`
  `setCatalog(String catalog)`
  Sets the catalog name of the table described by this DbEntity.
  `void`
  `setPrimaryKeyGenerator(DbKeyGenerator primaryKeyGenerator)`
  Set the primary key generator for this entity.
  `void`
  `setQualifier(Expression qualifier)`
  Sets qualifier for this entity
  `void`
  `setSchema(String schema)`
  Sets the database schema name of the table described by this DbEntity.
  `Expression`
  `translateToRelatedEntity(Expression expression, CayennePath relationshipPath)`
  Transforms Expression rooted in this entity to an analogous expression rooted in related entity.

  ### Methods inherited from class Entity

  `addRelationship, clearRelationships, getAnyRelationship, getAttribute, getAttributeMap, getAttributes, getDataMap, getName, getParent, getRelationship, getRelationshipMap, getRelationships, lastPathComponent, removeRelationship, resolvePathComponents, resolvePathComponents, setDataMap, setName, setParent, toString, translateToRelatedEntity, updateAttribute`
  Modifier and Type
  Method
  Description
  `void`
  `addRelationship(DbRelationship relationship)`
  Adds new relationship to the entity.
  `void`
  `clearRelationships()`
  `DbRelationship`
  `getAnyRelationship(DbEntity targetEntity)`
  Returns a relationship that has a specified entity as a target.
  `DbAttribute`
  `getAttribute(String attributeName)`
  Returns attribute with name `attributeName` or null if no attribute with this name exists.
  `Map<String, DbAttribute>`
  `getAttributeMap()`
  Returns an unmodifiable sorted map of entity attributes.
  `Collection<DbAttribute>`
  `getAttributes()`
  Returns an unmodifiable collection of entity attributes.
  `DataMap`
  `getDataMap()`
  `String`
  `getName()`
  Returns entity name.
  `Object`
  `getParent()`
  Returns the parent map.
  `DbRelationship`
  `getRelationship(String relName)`
  Returns relationship with name `relName`.
  `Map<String, DbRelationship>`
  `getRelationshipMap()`
  Returns an unmodifiable map of relationships sorted by name.
  `Collection<DbRelationship>`
  `getRelationships()`
  Returns an unmodifiable collection of Relationships that exist in this entity.
  `PathComponent<DbAttribute, DbRelationship>`
  `lastPathComponent(Expression path, Map<String,String> aliasMap)`
  Convenience method returning the last component in the path iterator.
  `void`
  `removeRelationship(String relName)`
  Removes a relationship named `attrName`.
  `Iterator<CayenneMapEntry>`
  `resolvePathComponents(String path)`
  Returns an Iterator over the path components that contains a sequence of Attributes and Relationships.
  `Iterator<CayenneMapEntry>`
  `resolvePathComponents(CayennePath path)`
  `void`
  `setDataMap(DataMap dataMap)`
  Sets parent DataMap of this entity.
  `void`
  `setName(String name)`
  `void`
  `setParent(Object parent)`
  Stores the parent map.
  `String`
  `toString()`
  `Expression`
  `translateToRelatedEntity(Expression expression, String relationshipPath)`
  Translates Expression rooted in this entity to an analogous expression rooted in related entity.
  `void`
  `updateAttribute(DbAttribute attribute)`

  ### Methods inherited from class Object

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

- ## Field Details

  - ### catalog

    protected String catalog

  - ### schema

    protected String schema

  - ### primaryKey

    protected List<DbAttribute> primaryKey

  - ### generatedAttributes

    protected Collection<DbAttribute> generatedAttributes
    Since:
      1.2

  - ### primaryKeyGenerator

    protected DbKeyGenerator primaryKeyGenerator

  - ### qualifier

    protected Expression qualifier
    Qualifier, that will be applied to all select queries and joins with this DbEntity

- ## Constructor Details

  - ### DbEntity

    public DbEntity()
    Creates an unnamed DbEntity.

  - ### DbEntity

    public DbEntity(String name)
    Creates a named DbEntity.

- ## 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

  - ### getFullyQualifiedName

    public String getFullyQualifiedName()
    Returns table name including catalog and schema, if any of those are present.

  - ### getSchema

    public String getSchema()
    Returns database schema of this table.
    Returns:
      table's schema, null if not set.

  - ### setSchema

    public void setSchema(String schema)
    Sets the database schema name of the table described by this DbEntity.

  - ### getCatalog

    public String getCatalog()
    Returns the catalog name of the table described by this DbEntity.

  - ### setCatalog

    public void setCatalog(String catalog)
    Sets the catalog name of the table described by this DbEntity.

  - ### getPrimaryKeys

    public List<DbAttribute> getPrimaryKeys()
    Returns an unmodifiable collection of DbAttributes representing the primary key of the table described by this DbEntity.
    Since:
      3.0

  - ### getGeneratedAttributes

    public Collection<DbAttribute> getGeneratedAttributes()
    Returns an unmodifiable collection of DbAttributes that are generated by the database.
    Since:
      1.2

  - ### addAttribute

    public void addAttribute(DbAttribute attr)
    Adds a new attribute to this entity.
    Overrides:
      `addAttribute` in class `Entity<DbEntity, DbAttribute, DbRelationship>`
    Throws:
      `IllegalArgumentException` - if Attribute has no name or there is an existing attribute with the same name
      `IllegalArgumentException` - if a relationship has the same name as this attribute
    Since:
      3.0

  - ### removeAttribute

    public void removeAttribute(String attrName)
    Removes attribute from the entity, removes any relationship joins containing this attribute. Does nothing if the attribute name is not found.
    Overrides:
      `removeAttribute` in class `Entity<DbEntity, DbAttribute, DbRelationship>`
    See Also:
      - `Entity.removeAttribute(String)`

  - ### clearAttributes

    public void clearAttributes()
    Overrides:
      `clearAttributes` in class `Entity<DbEntity, DbAttribute, DbRelationship>`

  - ### renameAttribute

    public void renameAttribute(DbAttribute attr, String newName)
    Renames an attribute owned by this entity, re-keying the attribute map and updating all dependent references across the parent `DataMap`: ObjAttribute paths and DbJoin source/target names.
    Since:
      5.0

  - ### renameRelationship

    public void renameRelationship(DbRelationship rel, String newName)
    Renames a relationship owned by this entity, re-keying the relationship map and refreshing dependent ObjAttribute db-paths across the parent `DataMap`.
    Since:
      5.0

  - ### resolvePath

    public Iterable<PathComponent<DbAttribute, DbRelationship>> 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<DbEntity, DbAttribute, DbRelationship>`
    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<DbEntity, DbAttribute, DbRelationship>`
    Throws:
      `ExpressionException`

  - ### setPrimaryKeyGenerator

    public void setPrimaryKeyGenerator(DbKeyGenerator primaryKeyGenerator)
    Set the primary key generator for this entity. If null is passed, nothing is changed.

  - ### getPrimaryKeyGenerator

    public DbKeyGenerator getPrimaryKeyGenerator()
    Return the primary key generator for this entity.

  - ### getQualifier

    public Expression getQualifier()
    Returns:
      qualifier that will be ANDed to all select queries with this entity

  - ### setQualifier

    public void setQualifier(Expression qualifier)
    Sets qualifier for this entity

  - ### isFullReplacementIdAttached

    public boolean isFullReplacementIdAttached(ObjectId id)
    Returns true if there is full replacement id is attached to an ObjectId. "Full" means that all PK columns are present and only PK columns are present.
    Since:
      1.2

  - ### mappedObjEntities

    public Collection<ObjEntity> mappedObjEntities()

  - ### translateToRelatedEntity

    public Expression translateToRelatedEntity(Expression expression, CayennePath relationshipPath)
    Transforms Expression rooted in this entity to an analogous expression rooted in related entity.
    Specified by:
      `translateToRelatedEntity` in class `Entity<DbEntity, DbAttribute, DbRelationship>`
    Since:
      5.0