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 and Description
    --- | ---
    `protected LifecycleCallbackRegistry` | `callbackRegistry`
    `protected ClassDescriptorMap` | `classDescriptorMap`
    `protected EntityResolver` | `clientEntityResolver`
    `protected static AtomicLong` | `incrementer`
    `protected boolean` | `indexedByClass` Deprecated.
    `protected static org.slf4j.Logger` | `logger`
    `protected MappingNamespace` | `mappingCache`
    `protected Collection<DataMap>` | `maps`
    `protected ValueObjectTypeRegistry` | `valueObjectTypeRegistry`

  - ### Constructor Summary

    Constructors
    Constructor and 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 Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDataMap(DataMap map)`
    `void` | `applyDBLayerDefaults()` Updates missing mapping artifacts that can be guessed from other mapping information.
    `void` | `applyObjectLayerDefaults()` Deprecated. since 4.0 does nothing. Previously it used to create runtime ObjRelationships, that broke a lot of things.
    `void` | `clearCache()` Deprecated. since 4.0 in favor of `refreshMappingCache()`.
    `LifecycleCallbackRegistry` | `getCallbackRegistry()` Returns a `LifecycleCallbackRegistry` for handling callbacks.
    `ClassDescriptor` | `getClassDescriptor(String entityName)` Returns ClassDescriptor for the ObjEntity matching the name.
    `ClassDescriptorMap` | `getClassDescriptorMap()` Returns an object that compiles and stores `ClassDescriptor` instances for all entities.
    `EntityResolver` | `getClientEntityResolver()` Returns ClientEntityResolver with mapping information that only includes entities available on CWS Client Tier.
    `DataMap` | `getDataMap(String mapName)` Returns a DataMap matching the name.
    `Collection<DataMap>` | `getDataMaps()` Returns an unmodifiable collection of DataMaps.
    `Collection<DbEntity>` | `getDbEntities()` Returns all DbEntities.
    `DbEntity` | `getDbEntity(String name)` Returns DbEntity for a given name, or null if no such DbEntity is found in the MappingNamespace.
    `Embeddable` | `getEmbeddable(String className)` Returns an `Embeddable` matching class name or null if such Embeddable is not mapped.
    `Collection<Embeddable>` | `getEmbeddables()`
    `EntityInheritanceTree` | `getInheritanceTree(String entityName)`
    `Collection<ObjEntity>` | `getObjEntities()` Returns all ObjEntities in the namespace.
    `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
    `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.
    `ObjEntity` | `getObjEntity(Persistent object)`
    `ObjEntity` | `getObjEntity(String name)` Returns ObjEntity for a given name, or null if no such ObjEntity is found in the MappingNamespace.
    `Procedure` | `getProcedure(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.
    `QueryDescriptor` | `getQueryDescriptor(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.
    `SQLResult` | `getResult(String name)` Returns a named result set mapping.
    `Collection<SQLResult>` | `getResults()`
    `Collection<SQLResult>` | `getResultSets()` Deprecated. since 4.0 use `getResults()`.
    `ValueObjectTypeRegistry` | `getValueObjectTypeRegistry()`
    `boolean` | `isIndexedByClass()` Deprecated. since 4.0. There's no replacement. This property is meaningless and is no longer respected by the code.
    `EntityInheritanceTree` | `lookupInheritanceTree(String entityName)` Deprecated. since 4.0 use `getInheritanceTree(String)`.
    `ObjEntity` | `lookupObjEntity(Class<?> entityClass)` Deprecated. since 4.0, use `getObjEntity(Class)`.
    `ObjEntity` | `lookupObjEntity(Object object)` Deprecated.
    `Procedure` | `lookupProcedure(Query q)` Deprecated. since 4.0. Use q.getMetaData(resolver).getProcedure()
    `Procedure` | `lookupProcedure(String procedureName)` Deprecated. since 4.0 use `getProcedure(String)`.
    `void` | `refreshMappingCache()` Refreshes entity cache to reflect the current state of the DataMaps in the EntityResolver.
    `void` | `removeDataMap(DataMap map)`
    `void` | `setCallbackRegistry(LifecycleCallbackRegistry callbackRegistry)` Sets a lifecycle callbacks registry of the EntityResolver.
    `void` | `setDataMaps(Collection<DataMap> maps)`
    `void` | `setEntityListenerFactory(EntityListenerFactory entityListenerFactory)` Deprecated. since 4.0 this method does nothing, as EntityResolver no longer loads listeners from its DataMaps.
    `void` | `setIndexedByClass(boolean b)` Deprecated. since 4.0. There's no replacement. This property is meaningless.
    `void` | `setValueObjectTypeRegistry(ValueObjectTypeRegistry valueObjectTypeRegistry)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### logger

          protected static final org.slf4j.Logger logger

    - #### incrementer

          protected static AtomicLong incrementer

    - #### indexedByClass

          @Deprecated
          protected boolean indexedByClass

      Deprecated.

    - #### 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

    - #### applyObjectLayerDefaults

          @Deprecated
          public void applyObjectLayerDefaults()

      Deprecated. since 4.0 does nothing. Previously it used to create runtime ObjRelationships, that broke a lot of things.
      Since:
        3.0

    - #### getCallbackRegistry

          public LifecycleCallbackRegistry getCallbackRegistry()

      Returns a `LifecycleCallbackRegistry` for 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:
        `getDbEntities` in interface `MappingNamespace`

    - #### getObjEntities

          public Collection<ObjEntity> getObjEntities()

      Description copied from interface: `MappingNamespace`
      Returns all ObjEntities in the namespace.
      Specified by:
        `getObjEntities` in interface `MappingNamespace`

    - #### getEmbeddables

          public Collection<Embeddable> getEmbeddables()

      Specified by:
        `getEmbeddables` in interface `MappingNamespace`
      Since:
        3.0

    - #### getResultSets

          @Deprecated
          public Collection<SQLResult> getResultSets()

      Deprecated. since 4.0 use `getResults()`.

    - #### getResults

          public Collection<SQLResult> getResults()

      Specified by:
        `getResults` in interface `MappingNamespace`
      Since:
        4.0

    - #### getProcedures

          public Collection<Procedure> getProcedures()

      Description copied from interface: `MappingNamespace`
      Returns all Procedures in the namespace.
      Specified by:
        `getProcedures` in interface `MappingNamespace`

    - #### getQueryDescriptors

          public Collection<QueryDescriptor> getQueryDescriptors()

      Description copied from interface: `MappingNamespace`
      Returns all Queries in the namespace.
      Specified by:
        `getQueryDescriptors` in interface `MappingNamespace`

    - #### getDbEntity

          public DbEntity getDbEntity(String name)

      Description copied from interface: `MappingNamespace`
      Returns DbEntity for a given name, or null if no such DbEntity is found in the MappingNamespace.
      Specified by:
        `getDbEntity` in interface `MappingNamespace`

    - #### getObjEntity

          public ObjEntity getObjEntity(String name)

      Description copied from interface: `MappingNamespace`
      Returns ObjEntity for a given name, or null if no such ObjEntity is found in the MappingNamespace.
      Specified by:
        `getObjEntity` in interface `MappingNamespace`

    - #### getProcedure

          public Procedure getProcedure(String procedureName)

      Description copied from interface: `MappingNamespace`
      Returns Procedure for a given name, or null if no such Procedure is found in the MappingNamespace.
      Specified by:
        `getProcedure` in interface `MappingNamespace`

    - #### getQueryDescriptor

          public QueryDescriptor getQueryDescriptor(String name)

      Returns a named query or null if no query exists for a given name.
      Specified by:
        `getQueryDescriptor` in interface `MappingNamespace`

    - #### getEmbeddable

          public Embeddable getEmbeddable(String className)

      Description copied from interface: `MappingNamespace`
      Returns an `Embeddable` matching class name or null if such Embeddable is not mapped.
      Specified by:
        `getEmbeddable` in interface `MappingNamespace`
      Since:
        3.0

    - #### getResult

          public SQLResult getResult(String name)

      Description copied from interface: `MappingNamespace`
      Returns a named result set mapping.
      Specified by:
        `getResult` in interface `MappingNamespace`
      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)

    - #### clearCache

          @Deprecated
          public void clearCache()

      Deprecated. since 4.0 in favor of `refreshMappingCache()`.
      Removes all entity mappings from the cache.

    - #### refreshMappingCache

          public void refreshMappingCache()

      Refreshes entity cache to reflect the current state of the DataMaps in the EntityResolver.
      Since:
        4.0

    - #### getDataMap

          public DataMap getDataMap(String mapName)

      Returns a DataMap matching the name.

    - #### 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:
        `getInheritanceTree` in interface `MappingNamespace`
      Since:
        4.0

    - #### lookupInheritanceTree

          @Deprecated
          public EntityInheritanceTree lookupInheritanceTree(String entityName)

      Deprecated. since 4.0 use `getInheritanceTree(String)`.

    - #### 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:
        `getObjEntity` in interface `MappingNamespace`
      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 search
        `lookupClientResolver` - flag to fallback to client resolver
      Returns:
        the required ObjEntity or null if there is none that matches the specifier
      Since:
        4.0

    - #### lookupObjEntity

          public ObjEntity lookupObjEntity(Class<?> entityClass)

      Deprecated. since 4.0, use `getObjEntity(Class)`.

    - #### getObjEntity

          public ObjEntity getObjEntity(Persistent object)

      Specified by:
        `getObjEntity` in interface `MappingNamespace`

    - #### lookupObjEntity

          @Deprecated
          public ObjEntity lookupObjEntity(Object object)

      Deprecated.
      Looks in the DataMap's that this object was created with for the ObjEntity that services the specified data Object
      Returns:
        the required ObjEntity, or null if none matches the specifier
      Since:
        4.0 a corresponding getObjEntity method should be used.

    - #### lookupProcedure

          @Deprecated
          public Procedure lookupProcedure(Query q)

      Deprecated. since 4.0. Use q.getMetaData(resolver).getProcedure()

    - #### lookupProcedure

          @Deprecated
          public Procedure lookupProcedure(String procedureName)

      Deprecated. since 4.0 use `getProcedure(String)`.

    - #### removeDataMap

          public void removeDataMap(DataMap map)

    - #### isIndexedByClass

          @Deprecated
          public boolean isIndexedByClass()

      Deprecated. since 4.0. There's no replacement. This property is meaningless and is no longer respected by the code.

    - #### setIndexedByClass

          public void setIndexedByClass(boolean b)

      Deprecated. since 4.0. There's no replacement. This property is meaningless.

    - #### getClassDescriptorMap

          public ClassDescriptorMap getClassDescriptorMap()

      Returns an object that compiles and stores `ClassDescriptor` instances for all entities.
      Since:
        3.0

    - #### setEntityListenerFactory

          @Deprecated
          public void setEntityListenerFactory(EntityListenerFactory entityListenerFactory)

      Deprecated. since 4.0 this method does nothing, as EntityResolver no longer loads listeners from its DataMaps.
      Since:
        3.0

    - #### getValueObjectTypeRegistry

          public ValueObjectTypeRegistry getValueObjectTypeRegistry()

    - #### setValueObjectTypeRegistry

          public void setValueObjectTypeRegistry(ValueObjectTypeRegistry valueObjectTypeRegistry)

Copyright © 2001–2018 Apache Cayenne. All rights reserved.