Package org.apache.cayenne.map
Class EntityResolver
- java.lang.Object
-
- org.apache.cayenne.map.EntityResolver
-
- All Implemented Interfaces:
Serializable,MappingNamespace
public class EntityResolver extends Object implements MappingNamespace, Serializable
Represents a virtual shared namespace for zero or more DataMaps. Unlike DataMap, EntityResolver is intended to work as a runtime container of mapping. DataMaps can be added or removed dynamically at runtime.EntityResolver is thread-safe.
- Since:
- 1.1
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected LifecycleCallbackRegistrycallbackRegistryprotected ClassDescriptorMapclassDescriptorMapprotected EntityResolverclientEntityResolverprotected static AtomicLongincrementerprotected static org.slf4j.Loggerloggerprotected MappingNamespacemappingCacheprotected Collection<DataMap>mapsprotected ValueObjectTypeRegistryvalueObjectTypeRegistry
-
Constructor Summary
Constructors Constructor Description EntityResolver()Creates new empty EntityResolver.EntityResolver(Collection<DataMap> dataMaps)Creates new EntityResolver that indexes a collection of DataMaps.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDataMap(DataMap map)voidapplyDBLayerDefaults()Updates missing mapping artifacts that can be guessed from other mapping information.LifecycleCallbackRegistrygetCallbackRegistry()Returns aLifecycleCallbackRegistryfor handling callbacks.ClassDescriptorgetClassDescriptor(String entityName)Returns ClassDescriptor for the ObjEntity matching the name.ClassDescriptorMapgetClassDescriptorMap()Returns an object that compiles and storesClassDescriptorinstances for all entities.EntityResolvergetClientEntityResolver()Returns ClientEntityResolver with mapping information that only includes entities available on CWS Client Tier.DataMapgetDataMap(String mapName)Returns a DataMap matching the name.Collection<DataMap>getDataMaps()Returns an unmodifiable collection of DataMaps.Collection<DbEntity>getDbEntities()Returns all DbEntities.DbEntitygetDbEntity(String name)Returns DbEntity for a given name, or null if no such DbEntity is found in the MappingNamespace.EmbeddablegetEmbeddable(String className)Returns anEmbeddablematching class name or null if such Embeddable is not mapped.Collection<Embeddable>getEmbeddables()EntityInheritanceTreegetInheritanceTree(String entityName)Collection<ObjEntity>getObjEntities()Returns all ObjEntities in the namespace.ObjEntitygetObjEntity(Class<?> entityClass)Looks in the DataMap's that this object was created with for the ObjEntity that maps to the services the specified classObjEntitygetObjEntity(Class<?> entityClass, boolean lookupClientResolver)Looks in the DataMap's that this object was created with for the ObjEntity that maps to the services the specified class, with option to fallback to search by name with client resolver in case entity not found.ObjEntitygetObjEntity(String name)Returns ObjEntity for a given name, or null if no such ObjEntity is found in the MappingNamespace.ObjEntitygetObjEntity(Persistent object)ProceduregetProcedure(String procedureName)Returns Procedure for a given name, or null if no such Procedure is found in the MappingNamespace.Collection<Procedure>getProcedures()Returns all Procedures in the namespace.QueryDescriptorgetQueryDescriptor(String name)Returns a named query or null if no query exists for a given name.Collection<QueryDescriptor>getQueryDescriptors()Returns all Queries in the namespace.SQLResultgetResult(String name)Returns a named result set mapping.Collection<SQLResult>getResults()ValueObjectTypeRegistrygetValueObjectTypeRegistry()voidrefreshMappingCache()Refreshes entity cache to reflect the current state of the DataMaps in the EntityResolver.voidremoveDataMap(DataMap map)voidsetCallbackRegistry(LifecycleCallbackRegistry callbackRegistry)Sets a lifecycle callbacks registry of the EntityResolver.voidsetDataMaps(Collection<DataMap> maps)voidsetValueObjectTypeRegistry(ValueObjectTypeRegistry valueObjectTypeRegistry)
-
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
incrementer
protected static AtomicLong incrementer
-
maps
protected Collection<DataMap> maps
-
mappingCache
protected transient MappingNamespace mappingCache
-
clientEntityResolver
protected EntityResolver clientEntityResolver
-
classDescriptorMap
protected transient volatile ClassDescriptorMap classDescriptorMap
-
callbackRegistry
protected transient LifecycleCallbackRegistry callbackRegistry
-
valueObjectTypeRegistry
protected transient ValueObjectTypeRegistry valueObjectTypeRegistry
-
-
Constructor Detail
-
EntityResolver
public EntityResolver()
Creates new empty EntityResolver.
-
EntityResolver
public EntityResolver(Collection<DataMap> dataMaps)
Creates new EntityResolver that indexes a collection of DataMaps.
-
-
Method Detail
-
applyDBLayerDefaults
public void applyDBLayerDefaults()
Updates missing mapping artifacts that can be guessed from other mapping information. This implementation creates missing reverse relationships, marking newly created relationships as "runtime".- Since:
- 3.0
-
getCallbackRegistry
public LifecycleCallbackRegistry getCallbackRegistry()
Returns aLifecycleCallbackRegistryfor handling callbacks. Registry is lazily initialized on first call.- Since:
- 3.0
-
setCallbackRegistry
public void setCallbackRegistry(LifecycleCallbackRegistry callbackRegistry)
Sets a lifecycle callbacks registry of the EntityResolver. Users rarely if ever need to call this method as Cayenne would instantiate a registry itself as needed based on mapped configuration.- Since:
- 3.0
-
getClientEntityResolver
public EntityResolver getClientEntityResolver()
Returns ClientEntityResolver with mapping information that only includes entities available on CWS Client Tier.- Since:
- 1.2
-
getDbEntities
public Collection<DbEntity> getDbEntities()
Returns all DbEntities.- Specified by:
getDbEntitiesin interfaceMappingNamespace
-
getObjEntities
public Collection<ObjEntity> getObjEntities()
Description copied from interface:MappingNamespaceReturns all ObjEntities in the namespace.- Specified by:
getObjEntitiesin interfaceMappingNamespace
-
getEmbeddables
public Collection<Embeddable> getEmbeddables()
- Specified by:
getEmbeddablesin interfaceMappingNamespace- Since:
- 3.0
-
getResults
public Collection<SQLResult> getResults()
- Specified by:
getResultsin interfaceMappingNamespace- Since:
- 4.0
-
getProcedures
public Collection<Procedure> getProcedures()
Description copied from interface:MappingNamespaceReturns all Procedures in the namespace.- Specified by:
getProceduresin interfaceMappingNamespace
-
getQueryDescriptors
public Collection<QueryDescriptor> getQueryDescriptors()
Description copied from interface:MappingNamespaceReturns all Queries in the namespace.- Specified by:
getQueryDescriptorsin interfaceMappingNamespace
-
getDbEntity
public DbEntity getDbEntity(String name)
Description copied from interface:MappingNamespaceReturns DbEntity for a given name, or null if no such DbEntity is found in the MappingNamespace.- Specified by:
getDbEntityin interfaceMappingNamespace
-
getObjEntity
public ObjEntity getObjEntity(String name)
Description copied from interface:MappingNamespaceReturns ObjEntity for a given name, or null if no such ObjEntity is found in the MappingNamespace.- Specified by:
getObjEntityin interfaceMappingNamespace
-
getProcedure
public Procedure getProcedure(String procedureName)
Description copied from interface:MappingNamespaceReturns Procedure for a given name, or null if no such Procedure is found in the MappingNamespace.- Specified by:
getProcedurein interfaceMappingNamespace
-
getQueryDescriptor
public QueryDescriptor getQueryDescriptor(String name)
Returns a named query or null if no query exists for a given name.- Specified by:
getQueryDescriptorin interfaceMappingNamespace
-
getEmbeddable
public Embeddable getEmbeddable(String className)
Description copied from interface:MappingNamespaceReturns anEmbeddablematching class name or null if such Embeddable is not mapped.- Specified by:
getEmbeddablein interfaceMappingNamespace- Since:
- 3.0
-
getResult
public SQLResult getResult(String name)
Description copied from interface:MappingNamespaceReturns a named result set mapping.- Specified by:
getResultin interfaceMappingNamespace- Since:
- 3.0
-
getClassDescriptor
public ClassDescriptor getClassDescriptor(String entityName)
Returns ClassDescriptor for the ObjEntity matching the name. Returns null if no matching entity exists.- Since:
- 1.2
-
addDataMap
public void addDataMap(DataMap map)
-
refreshMappingCache
public void refreshMappingCache()
Refreshes entity cache to reflect the current state of the DataMaps in the EntityResolver.- Since:
- 4.0
-
setDataMaps
public void setDataMaps(Collection<DataMap> maps)
-
getDataMaps
public Collection<DataMap> getDataMaps()
Returns an unmodifiable collection of DataMaps.
-
getInheritanceTree
public EntityInheritanceTree getInheritanceTree(String entityName)
- Specified by:
getInheritanceTreein interfaceMappingNamespace- Since:
- 4.0
-
getObjEntity
public ObjEntity getObjEntity(Class<?> entityClass)
Looks in the DataMap's that this object was created with for the ObjEntity that maps to the services the specified class- Specified by:
getObjEntityin interfaceMappingNamespace- Returns:
- the required ObjEntity or null if there is none that matches the specifier
- Since:
- 4.0
-
getObjEntity
public ObjEntity getObjEntity(Class<?> entityClass, boolean lookupClientResolver)
Looks in the DataMap's that this object was created with for the ObjEntity that maps to the services the specified class, with option to fallback to search by name with client resolver in case entity not found.
This method can be used where entity class can be received from client.
- Parameters:
entityClass- entity class to searchlookupClientResolver- flag to fallback to client resolver- Returns:
- the required ObjEntity or null if there is none that matches the specifier
- Since:
- 4.0
-
getObjEntity
public ObjEntity getObjEntity(Persistent object)
- Specified by:
getObjEntityin interfaceMappingNamespace
-
removeDataMap
public void removeDataMap(DataMap map)
-
getClassDescriptorMap
public ClassDescriptorMap getClassDescriptorMap()
Returns an object that compiles and storesClassDescriptorinstances for all entities.- Since:
- 3.0
-
getValueObjectTypeRegistry
public ValueObjectTypeRegistry getValueObjectTypeRegistry()
-
setValueObjectTypeRegistry
public void setValueObjectTypeRegistry(ValueObjectTypeRegistry valueObjectTypeRegistry)
-
-