Package org.apache.cayenne.map
Class ObjEntity
java.lang.Object
org.apache.cayenne.map.Entity
org.apache.cayenne.map.ObjEntity
- All Implemented Interfaces:
Serializable,EventListener,ConfigurationNode,ObjEntityListener,CayenneMapEntry,XMLSerializable
public class ObjEntity extends Entity implements ObjEntityListener, ConfigurationNode
ObjEntity is a mapping descriptor for a DataObject 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_abstractprotected Map<String,String>attributeOverridesprotected CallbackMapcallbacksprotected StringclassNameprotected StringclientClassNameprotected StringclientSuperClassNameprotected StringdbEntityNameprotected static Collection<String>DEFAULT_GENERIC_CLASSESA collection of default "generic" entity classes excluded from class generation.static intLOCK_TYPE_NONEstatic intLOCK_TYPE_OPTIMISTICprotected intlockTypeprotected Expressionqualifierprotected booleanreadOnlyprotected booleanserverOnlyprotected StringsuperClassNameprotected StringsuperEntityNameFields inherited from class org.apache.cayenne.map.Entity
attributes, dataMap, name, OUTER_JOIN_INDICATOR, PATH_SEPARATOR, relationships -
Constructor Summary
-
Method Summary
Modifier and Type Method Description <T> TacceptVisitor(ConfigurationNodeVisitor<T> visitor)voidaddAttributeOverride(String attributeName, String dbPath)voidclearDbMapping()Clears all the mapping between this obj entity and its current db entity.voidencodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)Prints itself as XML to the provided XMLEncoder.ObjAttributegetAttribute(String name)Returns a named attribute that is either declared in this ObjEntity or is inherited.ObjAttributegetAttributeForDbAttribute(DbAttribute dbAttribute)Returns ObjAttribute of this entity that maps todbAttributeparameter.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.CallbackMapgetCallbackMap()Returns an object that stores callback methods of this entity.Set<String>getCallbackMethods()StringgetClassName()Returns the name of DataObject class described by this entity.StringgetClientClassName()Returns the name of ClientDataObject class described by this entity.ObjEntitygetClientEntity()Returns an ObjEntity stripped of any server-side information, such as DbEntity mapping.StringgetClientSuperClassName()Returns a fully-qualified name of the client-side super class of the DataObject class.DbEntitygetDbEntity()Returns a DbEntity associated with this ObjEntity.StringgetDbEntityName()Returns the name of the underlying DbEntity.ObjAttributegetDeclaredAttribute(String name)Finds attribute declared by this ObjEntity, excluding inherited attributes.Map<String,String>getDeclaredAttributeOverrides()Collection<ObjAttribute>getDeclaredAttributes()Returns a Collection of all attributes that belong to this ObjEntity, excluding inherited attributes.intgetDeclaredLockType()Returns the type of lock used by this ObjEntity, regardless of what locking type is used by super entities.ExpressiongetDeclaredQualifier()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.Class<?>getJavaClass()Deprecated.since 4.0 this method based on statically defined class loading algorithm is not going to work in environments like OSGi.StringgetJavaClassName()Returns a non-null class name.intgetLockType()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.ObjRelationshipgetRelationship(String name)Returns a named Relationship that either belongs to this ObjEntity or is inherited.ObjRelationshipgetRelationshipForDbRelationship(DbRelationship dbRelationship)Returns ObjRelationship of this entity that maps todbRelationshipparameter.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.StringgetSuperClassName()Returns a fully-qualified name of the super class of the DataObject class.ObjEntitygetSuperEntity()Returns a "super" entity in the entity inheritance hierarchy.StringgetSuperEntityName()Returns an entity name for a parent entity in the inheritance hierarchy.booleanisAbstract()booleanisClientAllowed()Returns true if this entity is allowed to be used on the client.booleanisGeneric()Returns whether this entity is "generic", meaning it is not mapped to a unique Java class.booleanisReadOnly()Returnstrueif this ObjEntity represents a set of read-only objects.booleanisServerOnly()Returns true if this entity is not available on the client.booleanisSubentityOf(ObjEntity entity)Returns true if this entity directly or indirectly inherits from a given entity, false otherwise.PathComponent<ObjAttribute,ObjRelationship>lastPathComponent(Expression path, Map aliasMap)Convenience method returning the last component in the path iterator.voidobjEntityAdded(EntityEvent e)New entity has been created/added.voidobjEntityChanged(EntityEvent e)ObjEntity property changed.voidobjEntityRemoved(EntityEvent e)Entity has been removed.voidremoveAttributeOverride(String attributeName)Iterable<PathComponent<ObjAttribute,ObjRelationship>>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.voidsetAbstract(boolean isAbstract)Sets whether this entity is abstract only.voidsetClassName(String className)Sets the name of the DataObject class described by this entity.voidsetClientClassName(String clientClassName)Sets the name of the ClientDataObject class described by this entity.voidsetClientSuperClassName(String clientSuperClassName)Sets a fully-qualified name of the client-side super class of the ClientDataObject class.voidsetDbEntity(DbEntity dbEntity)Sets the DbEntity used by this ObjEntity.voidsetDbEntityName(String string)Sets the name of underlying DbEntity.voidsetDeclaredLockType(int i)Sets the type of lock used by this ObjEntity.voidsetDeclaredQualifier(Expression qualifier)Sets a qualifier that imposes a limit on what objects belong to this entity.voidsetReadOnly(boolean readOnly)voidsetServerOnly(boolean serverOnly)Sets whether this entity is available on the client.voidsetSuperClassName(String superClassName)Sets a fully-qualified name of the super class of the DataObject class.voidsetSuperEntityName(String superEntityName)Sets an entity name for a parent entity in the inheritance hierarchy.ExpressiontranslateToDbPath(Expression expression)Transforms an Expression to an analogous expression in terms of the underlying DbEntity.ExpressiontranslateToRelatedEntity(Expression expression, String 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, removeAttribute, removeRelationship, resolvePathComponents, setDataMap, setName, setParent, toString, updateAttribute
-
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
A collection of default "generic" entity classes excluded from class generation.- Since:
- 1.2
-
superClassName
-
className
-
dbEntityName
-
superEntityName
-
qualifier
-
readOnly
protected boolean readOnly -
lockType
protected int lockType -
_abstract
protected boolean _abstract -
serverOnly
protected boolean serverOnly -
clientClassName
-
clientSuperClassName
-
callbacks
-
attributeOverrides
-
-
Constructor Details
-
ObjEntity
public ObjEntity() -
ObjEntity
-
-
Method Details
-
acceptVisitor
- Specified by:
acceptVisitorin interfaceConfigurationNode- Since:
- 3.1
-
encodeAsXML
Prints itself as XML to the provided XMLEncoder.- Specified by:
encodeAsXMLin interfaceXMLSerializable- Since:
- 1.1
-
getClientEntity
Returns an ObjEntity stripped of any server-side information, such as DbEntity mapping. "clientClassName" property of this entity is used to initialize "className" property of returned entity.- Since:
- 1.2
-
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 - CayenneDataObject is used.- Since:
- 4.0
-
getJavaClass
Deprecated.since 4.0 this method based on statically defined class loading algorithm is not going to work in environments like OSGi.AdhocObjectFactoryshould be used as it can provide the environment-specific class loading policy.Returns Java class of persistent objects described by this entity. For generic entities with no class specified explicitly, default DataMap superclass is used, and if it is not set - CayenneDataObject is used. Casts any thrown exceptions into CayenneRuntimeException.- Since:
- 1.2
-
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 CayenneDataObject.- Since:
- 1.2
-
isClientAllowed
public boolean isClientAllowed()Returns true if this entity is allowed to be used on the client. Checks that parent DataMap allows client entities and also that this entity is not explicitly disabled for the client use.- Since:
- 1.2
-
isAbstract
public boolean isAbstract() -
setAbstract
public void setAbstract(boolean isAbstract)Sets whether this entity is abstract only. -
isServerOnly
public boolean isServerOnly()Returns true if this entity is not available on the client.- Since:
- 1.2
-
setServerOnly
public void setServerOnly(boolean serverOnly)Sets whether this entity is available on the client.- Since:
- 1.2
-
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
Returns an entity name for a parent entity in the inheritance hierarchy.- Since:
- 1.1
-
setDeclaredQualifier
Sets a qualifier that imposes a limit on what objects belong to this entity.- Since:
- 1.1
-
setSuperEntityName
Sets an entity name for a parent entity in the inheritance hierarchy.- Since:
- 1.1
-
getClassName
Returns the name of DataObject class described by this entity. -
setClassName
Sets the name of the DataObject class described by this entity. -
getClientClassName
Returns the name of ClientDataObject class described by this entity.- Since:
- 1.2
-
setClientClassName
Sets the name of the ClientDataObject class described by this entity.- Since:
- 1.2
-
getSuperClassName
Returns a fully-qualified name of the super class of the DataObject 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
Sets a fully-qualified name of the super class of the DataObject 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.
-
getClientSuperClassName
Returns a fully-qualified name of the client-side super class of the DataObject 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.- Since:
- 1.2
-
setClientSuperClassName
Sets a fully-qualified name of the client-side super class of the ClientDataObject 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.
- Since:
- 1.2
-
getSuperEntity
Returns a "super" entity in the entity inheritance hierarchy.- Since:
- 1.1
-
getDbEntity
Returns a DbEntity associated with this ObjEntity. -
setDbEntity
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
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
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:
getAttributein classEntity
-
getAttributeMap
Returns a Map of all attributes that either belong to this ObjEntity or inherited.- Overrides:
getAttributeMapin classEntity
-
addAttributeOverride
- Since:
- 3.0
-
removeAttributeOverride
- Since:
- 4.0
-
getDeclaredAttributeOverrides
- Since:
- 3.0
-
getAttributes
Returns a Collection of all attributes that either belong to this ObjEntity or inherited.- Overrides:
getAttributesin classEntity
-
getDeclaredAttributes
Returns a Collection of all attributes that belong to this ObjEntity, excluding inherited attributes.- Since:
- 1.1
-
getDeclaredAttribute
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
Returns a named Relationship that either belongs to this ObjEntity or is inherited. Returns null if no matching attribute is found.- Overrides:
getRelationshipin classEntity
-
getRelationshipMap
Description copied from class:EntityReturns an unmodifiable map of relationships sorted by name.- Overrides:
getRelationshipMapin classEntity
-
getRelationships
Description copied from class:EntityReturns an unmodifiable collection of Relationships that exist in this entity.- Overrides:
getRelationshipsin classEntity
-
getDeclaredRelationships
Returns a Collection of all relationships that belong to this ObjEntity, excluding inherited attributes.- Since:
- 1.1
-
getAttributeForDbAttribute
Returns ObjAttribute of this entity that maps todbAttributeparameter. Returns null if no such attribute is found. -
getPrimaryKeyNames
Returns the names of DbAtributes that comprise the primary key of the parent DbEntity.- Since:
- 3.0
-
getRelationshipForDbRelationship
Returns ObjRelationship of this entity that maps todbRelationshipparameter. 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()Returnstrueif this ObjEntity represents a set of read-only objects.- Returns:
- boolean
-
setReadOnly
public void setReadOnly(boolean readOnly) -
isSubentityOf
Returns true if this entity directly or indirectly inherits from a given entity, false otherwise.- Since:
- 1.1
-
lastPathComponent
public PathComponent<ObjAttribute,ObjRelationship> 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<ObjAttribute,ObjRelationship>> 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 ExpressionExceptionDescription 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
-
translateToDbPath
Transforms an Expression to an analogous expression in terms of the underlying DbEntity.- Since:
- 1.1
-
translateToRelatedEntity
Transforms an Expression rooted in this entity to an analogous expression rooted in related entity.- Specified by:
translateToRelatedEntityin classEntity- Since:
- 1.1
-
getCallbackMethods
- Since:
- 4.0
-
getDbEntityName
Returns the name of the underlying DbEntity.- Since:
- 1.1
-
setDbEntityName
Sets the name of underlying DbEntity.- Since:
- 1.1
-
objEntityChanged
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:
objEntityChangedin interfaceObjEntityListener- Since:
- 1.2
-
objEntityAdded
New entity has been created/added.- Specified by:
objEntityAddedin interfaceObjEntityListener
-
objEntityRemoved
Entity has been removed.- Specified by:
objEntityRemovedin interfaceObjEntityListener
-