Class AbstractMappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
java.lang.Object
org.springframework.data.mapping.context.AbstractMappingContext<E,P>
- Type Parameters:
E- the concretePersistentEntitytype theMappingContextimplementation createsP- the concretePersistentPropertytype theMappingContextimplementation creates
- All Implemented Interfaces:
Aware,BeanFactoryAware,InitializingBean,ApplicationContextAware,ApplicationEventPublisherAware,EnvironmentAware,MappingContext<E,P>
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
extends Object
implements MappingContext<E,P>, ApplicationEventPublisherAware, ApplicationContextAware, BeanFactoryAware, EnvironmentAware, InitializingBean
Base class to build mapping metadata and thus create instances of
PersistentEntity and
PersistentProperty.
The implementation uses a ReentrantReadWriteLock to make sure PersistentEntity are completely
populated before accessing them from outside.
- Author:
- Jon Brisbin, Oliver Gierke, Michael Hunger, Thomas Darimont, Tomasz Wysocki, Mark Paluch, Mikael Klamra, Christoph Strobl
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddPersistentEntity(Class<?> type) Adds the given type to theMappingContext.addPersistentEntity(TypeInformation<?> typeInformation) Adds the givenTypeInformationto theMappingContext.voidprotected abstract <T> EcreatePersistentEntity(TypeInformation<T> typeInformation) Creates the concretePersistentEntityinstance.protected abstract PcreatePersistentProperty(Property property, E owner, SimpleTypeHolder simpleTypeHolder) Creates the concrete instance ofPersistentProperty.protected final <T> PersistentPropertyPaths<T,P> doFindPersistentPropertyPaths(Class<T> type, Predicate<? super P> predicate, Predicate<P> traversalGuard) Actually looks up thePersistentPropertyPathsfor the given type, selection predicate and traversal guard.<T> PersistentPropertyPaths<T,P> findPersistentPropertyPaths(Class<T> type, Predicate<? super P> predicate) Returns allPersistentPropertyPaths pointing to properties on the given type that match the givenPredicate.Returns allPersistentEntitys held in the context.getPersistentEntity(Class<?> type) Returns aPersistentEntityfor the givenClass.getPersistentEntity(TypeInformation<?> type) Returns aPersistentEntityfor the givenTypeInformation.getPersistentEntity(P persistentProperty) Returns thePersistentEntitymapped by the givenPersistentProperty.getPersistentPropertyPath(String propertyPath, Class<?> type) Returns allPersistentPropertys for the given dot path notation based on the given type.getPersistentPropertyPath(String propertyPath, TypeInformation<?> type) Returns allPersistentPropertys for the given dot path notation based on the given type.getPersistentPropertyPath(PropertyPath propertyPath) Returns allPersistentPropertys for the given path expression based on the givenPropertyPath.booleanhasPersistentEntityFor(Class<?> type) Returns whether theMappingContextcurrently contains aPersistentEntityfor the type.voidInitializes the mapping context.voidsetApplicationContext(ApplicationContext applicationContext) Sets the application context.voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) voidsetBeanFactory(BeanFactory beanFactory) voidsetEnvironment(Environment environment) voidsetInitialEntitySet(Set<? extends Class<?>> initialEntitySet) Sets theSetof types to populate the context initially.voidsetManagedTypes(ManagedTypes managedTypes) Sets the types to populate the context initially.voidsetSimpleTypeHolder(SimpleTypeHolder simpleTypes) Configures theSimpleTypeHolderto be used by theMappingContext.voidsetStrict(boolean strict) Configures whether theMappingContextis in strict mode which means, that it will throwMappingExceptions in case one tries to lookup aPersistentEntitynot already in the context.protected booleanReturns whether aPersistentEntityinstance should be created for the givenTypeInformation.protected booleanshouldCreateProperties(TypeInformation<?> typeInformation) Whether to create thePersistentPropertys for the givenTypeInformation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mapping.context.MappingContext
getRequiredPersistentEntity, getRequiredPersistentEntity, getRequiredPersistentEntity
-
Constructor Details
-
AbstractMappingContext
protected AbstractMappingContext()
-
-
Method Details
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware
-
setApplicationContext
Sets the application context. Sets alsoApplicationEventPublisherandEnvironmentif these weren't already set.- Specified by:
setApplicationContextin interfaceApplicationContextAware- Parameters:
applicationContext- the ApplicationContext object to be used by this object.- Throws:
BeansException
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Parameters:
beanFactory- owning BeanFactory.- Throws:
BeansException- Since:
- 3.3
-
setEnvironment
- Specified by:
setEnvironmentin interfaceEnvironmentAware- Parameters:
environment- theEnvironmentthat this component runs in.- Since:
- 3.3
-
setInitialEntitySet
Sets theSetof types to populate the context initially.- Parameters:
initialEntitySet-- See Also:
-
setManagedTypes
Sets the types to populate the context initially.- Parameters:
managedTypes- must not be null. UseManagedTypes.empty()instead.- Since:
- 3.0
-
setStrict
public void setStrict(boolean strict) Configures whether theMappingContextis in strict mode which means, that it will throwMappingExceptions in case one tries to lookup aPersistentEntitynot already in the context. This defaults to false so that unknown types will be transparently added to the MappingContext if not known in advance.- Parameters:
strict-
-
setSimpleTypeHolder
Configures theSimpleTypeHolderto be used by theMappingContext. Allows customization of what types will be regarded as simple types and thus not recursively analyzed.- Parameters:
simpleTypes- must not be null.
-
getPersistentEntities
Description copied from interface:MappingContextReturns allPersistentEntitys held in the context.- Specified by:
getPersistentEntitiesin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Returns:
- never null.
-
getPersistentEntity
Description copied from interface:MappingContextReturns aPersistentEntityfor the givenClass. Will returnnullfor types that are considered simple ones.- Specified by:
getPersistentEntityin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
type- must not be null.- Returns:
- null if no
PersistentEntityfound for type. - See Also:
-
hasPersistentEntityFor
Description copied from interface:MappingContextReturns whether theMappingContextcurrently contains aPersistentEntityfor the type.- Specified by:
hasPersistentEntityForin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
type- must not be null.- Returns:
- true if
PersistentEntitypresent for given type.
-
getPersistentEntity
Description copied from interface:MappingContextReturns aPersistentEntityfor the givenTypeInformation. Will returnnullfor types that are considered simple ones.- Specified by:
getPersistentEntityin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
type- must not be null.- Returns:
- null if no
PersistentEntityfound forTypeInformation. - See Also:
-
getPersistentEntity
Description copied from interface:MappingContextReturns thePersistentEntitymapped by the givenPersistentProperty.- Specified by:
getPersistentEntityin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
persistentProperty- must not be null.- Returns:
- the
PersistentEntitymapped by the givenPersistentPropertyor null if noPersistentEntityexists for it or thePersistentPropertydoes not refer to an entity (the type of the property is considered simple seeSimpleTypeHolder.isSimpleType(Class)).
-
getPersistentPropertyPath
Description copied from interface:MappingContextReturns allPersistentPropertys for the given path expression based on the givenPropertyPath.- Specified by:
getPersistentPropertyPathin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
propertyPath- must not be null.- Returns:
- the
PersistentPropertyPathrepresenting the givenPropertyPath.
-
getPersistentPropertyPath
Description copied from interface:MappingContextReturns allPersistentPropertys for the given dot path notation based on the given type.- Specified by:
getPersistentPropertyPathin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
propertyPath- must not be null.type- must not be null.- Returns:
- the
PersistentPropertyPathrepresenting the given property path on the given type.
-
getPersistentPropertyPath
public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, TypeInformation<?> type) Description copied from interface:MappingContextReturns allPersistentPropertys for the given dot path notation based on the given type.- Specified by:
getPersistentPropertyPathin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
propertyPath- must not be null.type- must not be null.- Returns:
- the
PersistentPropertyPathrepresenting the given property path on the given type.
-
findPersistentPropertyPaths
public <T> PersistentPropertyPaths<T,P> findPersistentPropertyPaths(Class<T> type, Predicate<? super P> predicate) Description copied from interface:MappingContextReturns allPersistentPropertyPaths pointing to properties on the given type that match the givenPredicate. In case of circular references the detection will stop at the property that references a type that's already included in the path. Note, that is a potentially expensive operation as results cannot be cached.- Specified by:
findPersistentPropertyPathsin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Parameters:
type- must not be null.predicate- must not be null.- Returns:
-
doFindPersistentPropertyPaths
protected final <T> PersistentPropertyPaths<T,P> doFindPersistentPropertyPaths(Class<T> type, Predicate<? super P> predicate, Predicate<P> traversalGuard) Actually looks up thePersistentPropertyPathsfor the given type, selection predicate and traversal guard. Primary purpose is to allow subtypes to alter the default traversal guard, e.g. used byfindPersistentPropertyPaths(Class, Predicate).- Parameters:
type- will never be null.predicate- will never be null.traversalGuard- will never be null.- Returns:
- will never be null.
- See Also:
-
addPersistentEntity
Adds the given type to theMappingContext.- Parameters:
type- must not be null.- Returns:
-
addPersistentEntity
Adds the givenTypeInformationto theMappingContext.- Parameters:
typeInformation- must not be null.- Returns:
-
getManagedTypes
Description copied from interface:MappingContext- Specified by:
getManagedTypesin interfaceMappingContext<E extends MutablePersistentEntity<?,P>, P extends PersistentProperty<P>> - Returns:
- all
TypeInformations for thePersistentEntitys in theMappingContext.
-
createPersistentEntity
Creates the concretePersistentEntityinstance.- Type Parameters:
T-- Parameters:
typeInformation-- Returns:
-
createPersistentProperty
protected abstract P createPersistentProperty(Property property, E owner, SimpleTypeHolder simpleTypeHolder) Creates the concrete instance ofPersistentProperty.- Parameters:
property-owner-simpleTypeHolder-- Returns:
-
shouldCreateProperties
Whether to create thePersistentPropertys for the givenTypeInformation.- Parameters:
typeInformation- must not be null.- Returns:
- true properties should be created, false otherwise
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
initialize
public void initialize()Initializes the mapping context. Will add the types configured throughsetInitialEntitySet(Set)to the context. -
shouldCreatePersistentEntityFor
Returns whether aPersistentEntityinstance should be created for the givenTypeInformation. By default this will reject all types considered simple and non-supported Kotlin classes, but it might be necessary to tweak that in case you have registered custom converters for top level types (which renders them to be considered simple) but still need meta-information about them.- Parameters:
type- will never be null.- Returns:
-