Package org.apache.cayenne.reflect
Class PersistentDescriptor
- java.lang.Object
-
- org.apache.cayenne.reflect.PersistentDescriptor
-
- All Implemented Interfaces:
ClassDescriptor
public class PersistentDescriptor extends Object implements ClassDescriptor
A default ClassDescriptor implementation for persistent objects.- Since:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,DbEntity>additionalDbEntitiesprotected Collection<ObjAttribute>allDiscriminatorColumnsprotected Map<String,PropertyDescriptor>declaredPropertiesprotected ObjEntityentityprotected EntityInheritanceTreeentityInheritanceTreeprotected ExpressionentityQualifierprotected Collection<AttributeProperty>idPropertiesprotected Collection<ArcProperty>mapArcPropertiesprotected Class<?>objectClassprotected AccessorpersistenceStateAccessorprotected Map<String,PropertyDescriptor>propertiesprotected Collection<DbEntity>rootDbEntitiesprotected Map<String,ClassDescriptor>subclassDescriptorsprotected ClassDescriptorsuperclassDescriptor
-
Constructor Summary
Constructors Constructor Description PersistentDescriptor()Creates a PersistentDescriptor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDeclaredProperty(PropertyDescriptor property)Registers a property.voidaddRootDbEntity(DbEntity dbEntity)Adds a root DbEntity to the list of roots, filtering duplicates.voidaddSubclassDescriptor(String className, ClassDescriptor subclassDescriptor)Adds a subclass descriptor that maps to a given class name.voidaddSuperProperty(PropertyDescriptor property)Registers a superclass property.ObjectcreateObject()Creates a new instance of a class described by this object.Map<String,DbEntity>getAdditionalDbEntities()Returns information about additional db entities that is used for this ObjEntity (i.e.PropertyDescriptorgetDeclaredProperty(String propertyName)Returns a Java Bean property descriptor matching property name or null if no such property is found.Collection<ObjAttribute>getDiscriminatorColumns()Returns a collection of ObjAttribute for the described class, its superclasses and subclasses, that participate in inheritance qualifier.ObjEntitygetEntity()Returns an ObjEntity associated with this descriptor.EntityInheritanceTreegetEntityInheritanceTree()ExpressiongetEntityQualifier()Returns entity qualifier as a Cayenne expression that includes qualifiers for this entity and all subentities.Collection<AttributeProperty>getIdProperties()Returns a collection of the properties mapped to id columns.Collection<ArcProperty>getMapArcProperties()Returns a collection over the arc properties whose reverse arcs are to-many maps.Class<?>getObjectClass()Returns a class mapped by this descriptor.PropertyDescriptorgetProperty(String propertyName)Recursively looks up property descriptor in this class descriptor and all superclass descriptors.Collection<DbEntity>getRootDbEntities()Returns a collection of DbEntities that are the root tables for this descriptor's ObjEntity.ClassDescriptorgetSubclassDescriptor(Class<?> objectClass)Returns the most "specialized" descriptor for a given class.ClassDescriptorgetSuperclassDescriptor()Returns a descriptor of the mapped superclass or null if the descriptor's entity sits at the top of inheritance hierarchy.booleanhasSubclasses()Returns whether this class has persistent subclasses.voidinjectValueHolders(Object object)Invokes 'prepareForAccess' of a super descriptor and then invokes 'prepareForAccess' of each declared property.booleanisFault(Object object)Returns true if an object is not fully resolved.voidremoveDeclaredProperty(String propertyName)Removes declared property.voidsetDiscriminatorColumns(Collection<ObjAttribute> columns)voidsetEntity(ObjEntity entity)voidsetEntityInheritanceTree(EntityInheritanceTree entityInheritanceTree)voidsetEntityQualifier(Expression entityQualifier)voidsetPersistenceStateAccessor(Accessor persistenceStateAccessor)voidsetSuperclassDescriptor(ClassDescriptor superclassDescriptor)voidshallowMerge(Object from, Object to)Copies object properties from one object to another.booleanvisitAllProperties(PropertyVisitor visitor)Passes the visitor to the properties "visit" method for a combination of all properties, including properties declared in this descriptor, its super descriptors, and all subdescriptors.booleanvisitDeclaredProperties(PropertyVisitor visitor)Passes the visitor to the properties "visit" method for all properties declared in this descriptor.booleanvisitProperties(PropertyVisitor visitor)Passes the visitor to the properties "visit" method for all properties declared in this descriptor and all its super-decsriptors.
-
-
-
Field Detail
-
superclassDescriptor
protected ClassDescriptor superclassDescriptor
-
objectClass
protected Class<?> objectClass
-
declaredProperties
protected Map<String,PropertyDescriptor> declaredProperties
-
properties
protected Map<String,PropertyDescriptor> properties
-
subclassDescriptors
protected Map<String,ClassDescriptor> subclassDescriptors
-
persistenceStateAccessor
protected Accessor persistenceStateAccessor
-
entity
protected ObjEntity entity
-
rootDbEntities
protected Collection<DbEntity> rootDbEntities
-
entityInheritanceTree
protected EntityInheritanceTree entityInheritanceTree
-
idProperties
protected Collection<AttributeProperty> idProperties
-
mapArcProperties
protected Collection<ArcProperty> mapArcProperties
-
allDiscriminatorColumns
protected Collection<ObjAttribute> allDiscriminatorColumns
-
entityQualifier
protected Expression entityQualifier
-
-
Method Detail
-
setDiscriminatorColumns
public void setDiscriminatorColumns(Collection<ObjAttribute> columns)
-
addSuperProperty
public void addSuperProperty(PropertyDescriptor property)
Registers a superclass property.
-
addDeclaredProperty
public void addDeclaredProperty(PropertyDescriptor property)
Registers a property. This method is useful to customize default ClassDescriptor generated from ObjEntity by adding new properties or overriding the standard ones.
-
addRootDbEntity
public void addRootDbEntity(DbEntity dbEntity)
Adds a root DbEntity to the list of roots, filtering duplicates.
-
removeDeclaredProperty
public void removeDeclaredProperty(String propertyName)
Removes declared property. This method can be used to customize default ClassDescriptor generated from ObjEntity.
-
addSubclassDescriptor
public void addSubclassDescriptor(String className, ClassDescriptor subclassDescriptor)
Adds a subclass descriptor that maps to a given class name.
-
getEntity
public ObjEntity getEntity()
Description copied from interface:ClassDescriptorReturns an ObjEntity associated with this descriptor.- Specified by:
getEntityin interfaceClassDescriptor
-
getRootDbEntities
public Collection<DbEntity> getRootDbEntities()
Description copied from interface:ClassDescriptorReturns a collection of DbEntities that are the root tables for this descriptor's ObjEntity. Usually such collection would contain only one entity, however in cases involving subclass horizontal inheritance, it will be more than one, and in cases of abstract entities with no subclasses, the collection will be empty.- Specified by:
getRootDbEntitiesin interfaceClassDescriptor
-
getAdditionalDbEntities
public Map<String,DbEntity> getAdditionalDbEntities()
Description copied from interface:ClassDescriptorReturns information about additional db entities that is used for this ObjEntity (i.e. for flattened attributes).Keys are full paths for corresponding flattened attributes.
- Specified by:
getAdditionalDbEntitiesin interfaceClassDescriptor- Returns:
- information about additional db entities
-
isFault
public boolean isFault(Object object)
Description copied from interface:ClassDescriptorReturns true if an object is not fully resolved.- Specified by:
isFaultin interfaceClassDescriptor
-
getObjectClass
public Class<?> getObjectClass()
Description copied from interface:ClassDescriptorReturns a class mapped by this descriptor.- Specified by:
getObjectClassin interfaceClassDescriptor
-
getSubclassDescriptor
public ClassDescriptor getSubclassDescriptor(Class<?> objectClass)
Description copied from interface:ClassDescriptorReturns the most "specialized" descriptor for a given class. This method assumes that the following is true:this.getObjectClass().isAssignableFrom(objectClass)
- Specified by:
getSubclassDescriptorin interfaceClassDescriptor
-
getDiscriminatorColumns
public Collection<ObjAttribute> getDiscriminatorColumns()
Description copied from interface:ClassDescriptorReturns a collection of ObjAttribute for the described class, its superclasses and subclasses, that participate in inheritance qualifier. If a discriminator expression specifies a DbAttribute instead of an ObjAttribute, a synthetic ObjAttribute is created and returned.- Specified by:
getDiscriminatorColumnsin interfaceClassDescriptor
-
getIdProperties
public Collection<AttributeProperty> getIdProperties()
Description copied from interface:ClassDescriptorReturns a collection of the properties mapped to id columns.- Specified by:
getIdPropertiesin interfaceClassDescriptor
-
getMapArcProperties
public Collection<ArcProperty> getMapArcProperties()
Description copied from interface:ClassDescriptorReturns a collection over the arc properties whose reverse arcs are to-many maps. I.e. for each ArcProperty in returned collection, the following is true:arc.getComplimentaryReverseArc() instanceof ToManyMapProperty
- Specified by:
getMapArcPropertiesin interfaceClassDescriptor
-
getProperty
public PropertyDescriptor getProperty(String propertyName)
Recursively looks up property descriptor in this class descriptor and all superclass descriptors.- Specified by:
getPropertyin interfaceClassDescriptor
-
getDeclaredProperty
public PropertyDescriptor getDeclaredProperty(String propertyName)
Description copied from interface:ClassDescriptorReturns a Java Bean property descriptor matching property name or null if no such property is found. Lookup DOES NOT including properties from the superclass descriptors. Returned property can be any one ofAttributeProperty,ToManyProperty,ToOneProperty.- Specified by:
getDeclaredPropertyin interfaceClassDescriptor
-
getSuperclassDescriptor
public ClassDescriptor getSuperclassDescriptor()
Returns a descriptor of the mapped superclass or null if the descriptor's entity sits at the top of inheritance hierarchy.- Specified by:
getSuperclassDescriptorin interfaceClassDescriptor
-
createObject
public Object createObject()
Creates a new instance of a class described by this object.- Specified by:
createObjectin interfaceClassDescriptor
-
injectValueHolders
public void injectValueHolders(Object object) throws PropertyException
Invokes 'prepareForAccess' of a super descriptor and then invokes 'prepareForAccess' of each declared property.- Specified by:
injectValueHoldersin interfaceClassDescriptor- Throws:
PropertyException
-
shallowMerge
public void shallowMerge(Object from, Object to) throws PropertyException
Copies object properties from one object to another. Invokes 'shallowCopy' of a super descriptor and then invokes 'shallowCopy' of each declared property.- Specified by:
shallowMergein interfaceClassDescriptor- Throws:
PropertyException
-
visitDeclaredProperties
public boolean visitDeclaredProperties(PropertyVisitor visitor)
Description copied from interface:ClassDescriptorPasses the visitor to the properties "visit" method for all properties declared in this descriptor. This property set excludes inherited properties, even those that got overridden in this subclass. Walkthrough is terminated in case one of the properties returns false. Returns true if all visited properties returned true, false - if one property returned false.- Specified by:
visitDeclaredPropertiesin interfaceClassDescriptor- Since:
- 3.0
-
visitAllProperties
public boolean visitAllProperties(PropertyVisitor visitor)
Description copied from interface:ClassDescriptorPasses the visitor to the properties "visit" method for a combination of all properties, including properties declared in this descriptor, its super descriptors, and all subdescriptors. Walkthrough is terminated in case one of the properties returns false. Returns true if all visited properties returned true, false - if one property returned false.- Specified by:
visitAllPropertiesin interfaceClassDescriptor- Since:
- 3.0
-
visitProperties
public boolean visitProperties(PropertyVisitor visitor)
Description copied from interface:ClassDescriptorPasses the visitor to the properties "visit" method for all properties declared in this descriptor and all its super-decsriptors. Properties that are overridden in subdescriptors will include overridden information. Walkthrough is terminated in case one of the properties returns false. Returns true if all visited properties returned true, false - if one property returned false.- Specified by:
visitPropertiesin interfaceClassDescriptor
-
setPersistenceStateAccessor
public void setPersistenceStateAccessor(Accessor persistenceStateAccessor)
-
setEntity
public void setEntity(ObjEntity entity)
-
setSuperclassDescriptor
public void setSuperclassDescriptor(ClassDescriptor superclassDescriptor)
-
getEntityQualifier
public Expression getEntityQualifier()
Description copied from interface:ClassDescriptorReturns entity qualifier as a Cayenne expression that includes qualifiers for this entity and all subentities.- Specified by:
getEntityQualifierin interfaceClassDescriptor
-
setEntityQualifier
public void setEntityQualifier(Expression entityQualifier)
-
getEntityInheritanceTree
public EntityInheritanceTree getEntityInheritanceTree()
- Specified by:
getEntityInheritanceTreein interfaceClassDescriptor
-
setEntityInheritanceTree
public void setEntityInheritanceTree(EntityInheritanceTree entityInheritanceTree)
-
hasSubclasses
public boolean hasSubclasses()
Description copied from interface:ClassDescriptorReturns whether this class has persistent subclasses.- Specified by:
hasSubclassesin interfaceClassDescriptor
-
-