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 concretePersistentEntity
type theMappingContext
implementation createsP
- the concretePersistentProperty
type theMappingContext
implementation creates
- All Implemented Interfaces:
Aware
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,MappingContext<E,
P>
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
extends Object
implements MappingContext<E,P>, ApplicationEventPublisherAware, ApplicationContextAware, 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
-
Method Summary
Modifier and TypeMethodDescriptionaddPersistentEntity
(Class<?> type) Adds the given type to theMappingContext
.addPersistentEntity
(TypeInformation<?> typeInformation) Adds the givenTypeInformation
to theMappingContext
.void
protected abstract <T> E
createPersistentEntity
(TypeInformation<T> typeInformation) Creates the concretePersistentEntity
instance.protected abstract P
createPersistentProperty
(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 thePersistentPropertyPaths
for the given type, selection predicate and traversal guard.<T> PersistentPropertyPaths<T,
P> findPersistentPropertyPaths
(Class<T> type, Predicate<? super P> predicate) Returns allPersistentPropertyPath
s pointing to properties on the given type that match the givenPredicate
.Returns allPersistentEntity
s held in the context.getPersistentEntity
(Class<?> type) Returns aPersistentEntity
for the givenClass
.getPersistentEntity
(TypeInformation<?> type) Returns aPersistentEntity
for the givenTypeInformation
.getPersistentEntity
(P persistentProperty) Returns thePersistentEntity
mapped by the givenPersistentProperty
.getPersistentPropertyPath
(String propertyPath, Class<?> type) Returns allPersistentProperty
s for the given dot path notation based on the given type.getPersistentPropertyPath
(String propertyPath, TypeInformation<?> type) Returns allPersistentProperty
s for the given dot path notation based on the given type.getPersistentPropertyPath
(PropertyPath propertyPath) Returns allPersistentProperty
s for the given path expression based on the givenPropertyPath
.boolean
hasPersistentEntityFor
(Class<?> type) Returns whether theMappingContext
currently contains aPersistentEntity
for the type.void
Initializes the mapping context.void
setApplicationContext
(ApplicationContext applicationContext) void
setApplicationEventPublisher
(ApplicationEventPublisher applicationEventPublisher) void
setInitialEntitySet
(Set<? extends Class<?>> initialEntitySet) Sets theSet
of types to populate the context initially.void
setManagedTypes
(ManagedTypes managedTypes) Sets the types to populate the context initially.void
setSimpleTypeHolder
(SimpleTypeHolder simpleTypes) Configures theSimpleTypeHolder
to be used by theMappingContext
.void
setStrict
(boolean strict) Configures whether theMappingContext
is in strict mode which means, that it will throwMappingException
s in case one tries to lookup aPersistentEntity
not already in the context.protected boolean
Returns whether aPersistentEntity
instance should be created for the givenTypeInformation
.protected boolean
shouldCreateProperties
(TypeInformation<?> typeInformation) Whether to create thePersistentProperty
s for the givenTypeInformation
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.mapping.context.MappingContext
getRequiredPersistentEntity, getRequiredPersistentEntity, getRequiredPersistentEntity
-
Constructor Details
-
AbstractMappingContext
protected AbstractMappingContext()
-
-
Method Details
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
setInitialEntitySet
Sets theSet
of 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 theMappingContext
is in strict mode which means, that it will throwMappingException
s in case one tries to lookup aPersistentEntity
not 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 theSimpleTypeHolder
to 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:MappingContext
Returns allPersistentEntity
s held in the context.- Specified by:
getPersistentEntities
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Returns:
- never null.
-
getPersistentEntity
Description copied from interface:MappingContext
Returns aPersistentEntity
for the givenClass
. Will returnnull
for types that are considered simple ones.- Specified by:
getPersistentEntity
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Parameters:
type
- must not be null.- Returns:
- null if no
PersistentEntity
found for type. - See Also:
-
hasPersistentEntityFor
Description copied from interface:MappingContext
Returns whether theMappingContext
currently contains aPersistentEntity
for the type.- Specified by:
hasPersistentEntityFor
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Parameters:
type
- must not be null.- Returns:
- true if
PersistentEntity
present for given type.
-
getPersistentEntity
Description copied from interface:MappingContext
Returns aPersistentEntity
for the givenTypeInformation
. Will returnnull
for types that are considered simple ones.- Specified by:
getPersistentEntity
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Parameters:
type
- must not be null.- Returns:
- null if no
PersistentEntity
found forTypeInformation
. - See Also:
-
getPersistentEntity
Description copied from interface:MappingContext
Returns thePersistentEntity
mapped by the givenPersistentProperty
.- Specified by:
getPersistentEntity
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Parameters:
persistentProperty
- must not be null.- Returns:
- the
PersistentEntity
mapped by the givenPersistentProperty
or null if noPersistentEntity
exists for it or thePersistentProperty
does not refer to an entity (the type of the property is considered simple seeSimpleTypeHolder.isSimpleType(Class)
).
-
getPersistentPropertyPath
Description copied from interface:MappingContext
Returns allPersistentProperty
s for the given path expression based on the givenPropertyPath
.- Specified by:
getPersistentPropertyPath
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Parameters:
propertyPath
- must not be null.- Returns:
- the
PersistentPropertyPath
representing the givenPropertyPath
.
-
getPersistentPropertyPath
Description copied from interface:MappingContext
Returns allPersistentProperty
s for the given dot path notation based on the given type.- Specified by:
getPersistentPropertyPath
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Parameters:
propertyPath
- must not be null.type
- must not be null.- Returns:
- the
PersistentPropertyPath
representing the given property path on the given type.
-
getPersistentPropertyPath
public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, TypeInformation<?> type) Description copied from interface:MappingContext
Returns allPersistentProperty
s for the given dot path notation based on the given type.- Specified by:
getPersistentPropertyPath
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Parameters:
propertyPath
- must not be null.type
- must not be null.- Returns:
- the
PersistentPropertyPath
representing 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:MappingContext
Returns allPersistentPropertyPath
s 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:
findPersistentPropertyPaths
in 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 thePersistentPropertyPaths
for 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 givenTypeInformation
to theMappingContext
.- Parameters:
typeInformation
- must not be null.- Returns:
-
getManagedTypes
Description copied from interface:MappingContext
- Specified by:
getManagedTypes
in interfaceMappingContext<E extends MutablePersistentEntity<?,
P>, P extends PersistentProperty<P>> - Returns:
- all
TypeInformation
s for thePersistentEntity
s in theMappingContext
.
-
createPersistentEntity
Creates the concretePersistentEntity
instance.- 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 thePersistentProperty
s for the givenTypeInformation
.- Parameters:
typeInformation
- must not be null.- Returns:
- true properties should be created, false otherwise
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
initialize
public void initialize()Initializes the mapping context. Will add the types configured throughsetInitialEntitySet(Set)
to the context. -
shouldCreatePersistentEntityFor
Returns whether aPersistentEntity
instance 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:
-