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
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected Collection
<DbAttribute> protected List
<DbAttribute> protected DbKeyGenerator
protected Expression
Qualifier, that will be applied to all select queries and joins with this DbEntityprotected String
Fields inherited from class org.apache.cayenne.map.Entity
attributes, dataMap, name, OUTER_JOIN_INDICATOR, PATH_SEPARATOR, relationships
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
acceptVisitor
(ConfigurationNodeVisitor<T> visitor) void
addAttribute
(DbAttribute attr) Adds a new attribute to this entity.void
void
New attribute has been created/added.void
Attribute property changed.void
Attribute has been removed.void
New entity has been created/added.void
DbEntity property changed event.void
Entity has been removed.void
Relationship has been created/added.void
Relationship property changed.void
Relationship has been removed.void
encodeAsXML
(XMLEncoder encoder, ConfigurationNodeVisitor delegate) Prints itself as XML to the provided XMLEncoder.getAttribute
(String attributeName) Returns attribute with nameattributeName
or null if no attribute with this name exists.Returns a Collection of all attributes that either belong to this DbEntity or inherited.Returns the catalog name of the table described by this DbEntity.Returns table name including catalog and schema, if any of those are present.Returns an unmodifiable collection of DbAttributes that are generated by the database.Return the primary key generator for this entity.Returns an unmodifiable collection of DbAttributes representing the primary key of the table described by this DbEntity.getRelationship
(String relName) Returns relationship with namerelName
.Returns an unmodifiable map of relationships sorted by name.Returns a Collection of relationships from this entity or inherited.Returns database schema of this table.boolean
Returns true if there is full replacement id is attached to an ObjectId.lastPathComponent
(Expression path, Map aliasMap) Convenience method returning the last component in the path iterator.void
removeAttribute
(String attrName) Removes attribute from the entity, removes any relationship joins containing this attribute.resolvePath
(Expression pathExp, Map aliasMap) Returns an Iterable instance over expression path components based on this entity.resolvePathComponents
(Expression pathExp) Processes expressionpathExp
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 entityvoid
Sets the database schema name of the table described by this DbEntity.translateToRelatedEntity
(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 Details
-
catalog
-
schema
-
-
generatedAttributes
- Since:
- 1.2
-
primaryKeyGenerator
-
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
Creates a named DbEntity.
-
-
Method Details
-
getRelationship
Description copied from class:Entity
Returns relationship with namerelName
. Will return null if no relationship with this name exists in the entity.- Overrides:
getRelationship
in classEntity
-
getAttribute
Description copied from class:Entity
Returns attribute with nameattributeName
or null if no attribute with this name exists.- Overrides:
getAttribute
in classEntity
-
acceptVisitor
- Specified by:
acceptVisitor
in interfaceConfigurationNode
- Since:
- 3.1
-
encodeAsXML
Prints itself as XML to the provided XMLEncoder.- Specified by:
encodeAsXML
in interfaceXMLSerializable
- Since:
- 1.1
-
getFullyQualifiedName
Returns table name including catalog and schema, if any of those are present. -
getSchema
Returns database schema of this table.- Returns:
- table's schema, null if not set.
-
setSchema
Sets the database schema name of the table described by this DbEntity. -
getCatalog
Returns the catalog name of the table described by this DbEntity. -
setCatalog
Sets the catalog name of the table described by this DbEntity. -
getPrimaryKeys
Returns an unmodifiable collection of DbAttributes representing the primary key of the table described by this DbEntity.- Since:
- 3.0
-
getAttributes
Returns a Collection of all attributes that either belong to this DbEntity or inherited.- Overrides:
getAttributes
in classEntity
-
getGeneratedAttributes
Returns an unmodifiable collection of DbAttributes that are generated by the database.- Since:
- 1.2
-
addAttribute
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
Removes attribute from the entity, removes any relationship joins containing this attribute. Does nothing if the attribute name is not found.- Overrides:
removeAttribute
in classEntity
- See Also:
-
clearAttributes
public void clearAttributes()- Overrides:
clearAttributes
in classEntity
-
getRelationships
Returns a Collection of relationships from this entity or inherited.- Overrides:
getRelationships
in classEntity
-
getRelationshipMap
Description copied from class:Entity
Returns an unmodifiable map of relationships sorted by name.- Overrides:
getRelationshipMap
in classEntity
-
lastPathComponent
Description copied from class:Entity
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.- Overrides:
lastPathComponent
in 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:
resolvePath
in classEntity
- Since:
- 3.0
-
resolvePathComponents
public Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp) throws ExpressionException Description copied from class:Entity
Processes expressionpathExp
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 classEntity
- Throws:
ExpressionException
-
setPrimaryKeyGenerator
Set the primary key generator for this entity. If null is passed, nothing is changed. -
getPrimaryKeyGenerator
Return the primary key generator for this entity. -
dbEntityChanged
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:
dbEntityChanged
in interfaceDbEntityListener
- Since:
- 1.2
-
dbEntityAdded
New entity has been created/added.- Specified by:
dbEntityAdded
in interfaceDbEntityListener
-
dbEntityRemoved
Entity has been removed.- Specified by:
dbEntityRemoved
in interfaceDbEntityListener
-
dbAttributeAdded
Description copied from interface:DbAttributeListener
New attribute has been created/added.- Specified by:
dbAttributeAdded
in interfaceDbAttributeListener
-
dbAttributeChanged
Description copied from interface:DbAttributeListener
Attribute property changed.- Specified by:
dbAttributeChanged
in interfaceDbAttributeListener
-
dbAttributeRemoved
Description copied from interface:DbAttributeListener
Attribute has been removed.- Specified by:
dbAttributeRemoved
in interfaceDbAttributeListener
-
dbRelationshipChanged
Relationship property changed.- Specified by:
dbRelationshipChanged
in interfaceDbRelationshipListener
-
dbRelationshipAdded
Relationship has been created/added.- Specified by:
dbRelationshipAdded
in interfaceDbRelationshipListener
-
dbRelationshipRemoved
Relationship has been removed.- Specified by:
dbRelationshipRemoved
in interfaceDbRelationshipListener
-
getQualifier
- Returns:
- qualifier that will be ANDed to all select queries with this entity
-
setQualifier
Sets qualifier for this entity -
isFullReplacementIdAttached
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
-
translateToRelatedEntity
Transforms Expression rooted in this entity to an analogous expression rooted in related entity.- Specified by:
translateToRelatedEntity
in classEntity
- Since:
- 1.1
-