Package org.apache.cayenne.map
Class DbEntity
- java.lang.Object
-
- org.apache.cayenne.map.Entity
-
- org.apache.cayenne.map.DbEntity
-
- All Implemented Interfaces:
Serializable,EventListener,ConfigurationNode,DbAttributeListener,DbEntityListener,DbRelationshipListener,CayenneMapEntry,XMLSerializable
- Direct Known Subclasses:
DetectedDbEntity
public class DbEntity extends Entity implements ConfigurationNode, DbEntityListener, DbAttributeListener, DbRelationshipListener
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 Stringcatalogprotected Collection<DbAttribute>generatedAttributesprotected Collection<DbAttribute>primaryKeyprotected DbKeyGeneratorprimaryKeyGeneratorprotected ExpressionqualifierQualifier, that will be applied to all select queries and joins with this DbEntityprotected Stringschema-
Fields inherited from class org.apache.cayenne.map.Entity
attributes, dataMap, name, OUTER_JOIN_INDICATOR, PATH_SEPARATOR, relationships
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TacceptVisitor(ConfigurationNodeVisitor<T> visitor)voidaddAttribute(DbAttribute attr)Adds a new attribute to this entity.voidclearAttributes()voiddbAttributeAdded(AttributeEvent e)New attribute has been created/added.voiddbAttributeChanged(AttributeEvent e)Attribute property changed.voiddbAttributeRemoved(AttributeEvent e)Attribute has been removed.voiddbEntityAdded(EntityEvent e)New entity has been created/added.voiddbEntityChanged(EntityEvent e)DbEntity property changed event.voiddbEntityRemoved(EntityEvent e)Entity has been removed.voiddbRelationshipAdded(RelationshipEvent e)Relationship has been created/added.voiddbRelationshipChanged(RelationshipEvent e)Relationship property changed.voiddbRelationshipRemoved(RelationshipEvent e)Relationship has been removed.voidencodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)Prints itself as XML to the provided XMLEncoder.DbAttributegetAttribute(String attributeName)Returns attribute with nameattributeNameor null if no attribute with this name exists.Collection<DbAttribute>getAttributes()Returns a Collection of all attributes that either belong to this DbEntity or inherited.StringgetCatalog()Returns the catalog name of the table described by this DbEntity.StringgetFullyQualifiedName()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.DbKeyGeneratorgetPrimaryKeyGenerator()Return the primary key generator for this entity.Collection<DbAttribute>getPrimaryKeys()Returns an unmodifiable collection of DbAttributes representing the primary key of the table described by this DbEntity.ExpressiongetQualifier()DbRelationshipgetRelationship(String relName)Returns relationship with namerelName.Map<String,DbRelationship>getRelationshipMap()Returns an unmodifiable map of relationships sorted by name.Collection<DbRelationship>getRelationships()Returns a Collection of relationships from this entity or inherited.StringgetSchema()Returns database schema of this table.booleanisFullReplacementIdAttached(ObjectId id)Returns true if there is full replacement id is attached to an ObjectId.PathComponent<DbAttribute,DbRelationship>lastPathComponent(Expression path, Map aliasMap)Convenience method returning the last component in the path iterator.Collection<ObjEntity>mappedObjEntities()voidremoveAttribute(String attrName)Removes attribute from the entity, removes any relationship joins containing this attribute.Iterable<PathComponent<DbAttribute,DbRelationship>>resolvePath(Expression pathExp, Map aliasMap)Returns an Iterable instance over expression path components based on this entity.Iterator<CayenneMapEntry>resolvePathComponents(Expression pathExp)Processes expressionpathExpand returns an Iterator of path components that contains a sequence of Attributes and Relationships.voidsetCatalog(String catalog)Sets the catalog name of the table described by this DbEntity.voidsetPrimaryKeyGenerator(DbKeyGenerator primaryKeyGenerator)Set the primary key generator for this entity.voidsetQualifier(Expression qualifier)Sets qualifier for this entityvoidsetSchema(String schema)Sets the database schema name of the table described by this DbEntity.ExpressiontranslateToRelatedEntity(Expression expression, String relationshipPath)Transforms Expression rooted in this entity to an analogous expression rooted in related entity.-
Methods inherited from class org.apache.cayenne.map.Entity
addAttribute, addRelationship, clearRelationships, getAnyRelationship, getAttributeMap, getDataMap, getName, getParent, removeRelationship, resolvePathComponents, setDataMap, setName, setParent, toString, updateAttribute
-
-
-
-
Field Detail
-
catalog
protected String catalog
-
schema
protected String schema
-
primaryKey
protected Collection<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 Detail
-
DbEntity
public DbEntity()
Creates an unnamed DbEntity.
-
DbEntity
public DbEntity(String name)
Creates a named DbEntity.
-
-
Method Detail
-
getRelationship
public DbRelationship getRelationship(String relName)
Description copied from class:EntityReturns relationship with namerelName. Will return null if no relationship with this name exists in the entity.- Overrides:
getRelationshipin classEntity
-
getAttribute
public DbAttribute getAttribute(String attributeName)
Description copied from class:EntityReturns attribute with nameattributeNameor null if no attribute with this name exists.- Overrides:
getAttributein classEntity
-
acceptVisitor
public <T> T acceptVisitor(ConfigurationNodeVisitor<T> visitor)
- Specified by:
acceptVisitorin interfaceConfigurationNode- Since:
- 3.1
-
encodeAsXML
public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)
Prints itself as XML to the provided XMLEncoder.- Specified by:
encodeAsXMLin interfaceXMLSerializable- 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 Collection<DbAttribute> getPrimaryKeys()
Returns an unmodifiable collection of DbAttributes representing the primary key of the table described by this DbEntity.- Since:
- 3.0
-
getAttributes
public Collection<DbAttribute> getAttributes()
Returns a Collection of all attributes that either belong to this DbEntity or inherited.- Overrides:
getAttributesin classEntity
-
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.- Throws:
IllegalArgumentException- if Attribute has no name or there is an existing attribute with the same nameIllegalArgumentException- 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:
removeAttributein classEntity- See Also:
Entity.removeAttribute(String)
-
clearAttributes
public void clearAttributes()
- Overrides:
clearAttributesin classEntity
-
getRelationships
public Collection<DbRelationship> getRelationships()
Returns a Collection of relationships from this entity or inherited.- Overrides:
getRelationshipsin classEntity
-
getRelationshipMap
public Map<String,DbRelationship> getRelationshipMap()
Description copied from class:EntityReturns an unmodifiable map of relationships sorted by name.- Overrides:
getRelationshipMapin classEntity
-
lastPathComponent
public PathComponent<DbAttribute,DbRelationship> lastPathComponent(Expression path, Map aliasMap)
Description copied from class:EntityConvenience 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.- Overrides:
lastPathComponentin classEntity- Since:
- 3.0
-
resolvePath
public Iterable<PathComponent<DbAttribute,DbRelationship>> resolvePath(Expression pathExp, Map aliasMap)
Returns an Iterable instance over expression path components based on this entity.- Specified by:
resolvePathin classEntity- Since:
- 3.0
-
resolvePathComponents
public Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp) throws ExpressionException
Description copied from class:EntityProcesses 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.- Specified by:
resolvePathComponentsin classEntity- 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.
-
dbEntityChanged
public void dbEntityChanged(EntityEvent e)
DbEntity property changed event. May be name, attribute or relationship added or removed, etc. Attribute and relationship property changes are handled in respective listeners.- Specified by:
dbEntityChangedin interfaceDbEntityListener- Since:
- 1.2
-
dbEntityAdded
public void dbEntityAdded(EntityEvent e)
New entity has been created/added.- Specified by:
dbEntityAddedin interfaceDbEntityListener
-
dbEntityRemoved
public void dbEntityRemoved(EntityEvent e)
Entity has been removed.- Specified by:
dbEntityRemovedin interfaceDbEntityListener
-
dbAttributeAdded
public void dbAttributeAdded(AttributeEvent e)
Description copied from interface:DbAttributeListenerNew attribute has been created/added.- Specified by:
dbAttributeAddedin interfaceDbAttributeListener
-
dbAttributeChanged
public void dbAttributeChanged(AttributeEvent e)
Description copied from interface:DbAttributeListenerAttribute property changed.- Specified by:
dbAttributeChangedin interfaceDbAttributeListener
-
dbAttributeRemoved
public void dbAttributeRemoved(AttributeEvent e)
Description copied from interface:DbAttributeListenerAttribute has been removed.- Specified by:
dbAttributeRemovedin interfaceDbAttributeListener
-
dbRelationshipChanged
public void dbRelationshipChanged(RelationshipEvent e)
Relationship property changed.- Specified by:
dbRelationshipChangedin interfaceDbRelationshipListener
-
dbRelationshipAdded
public void dbRelationshipAdded(RelationshipEvent e)
Relationship has been created/added.- Specified by:
dbRelationshipAddedin interfaceDbRelationshipListener
-
dbRelationshipRemoved
public void dbRelationshipRemoved(RelationshipEvent e)
Relationship has been removed.- Specified by:
dbRelationshipRemovedin interfaceDbRelationshipListener
-
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, String relationshipPath)
Transforms Expression rooted in this entity to an analogous expression rooted in related entity.- Specified by:
translateToRelatedEntityin classEntity- Since:
- 1.1
-
-