public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>> extends Object implements MappingContext<E,P>, org.springframework.context.ApplicationEventPublisherAware, org.springframework.beans.factory.InitializingBean
PersistentEntity
and
PersistentProperty
.
The implementation uses a ReentrantReadWriteLock
to make sure PersistentEntity
are completely
populated before accessing them from outside.
Constructor and Description |
---|
AbstractMappingContext() |
Modifier and Type | Method and Description |
---|---|
protected E |
addPersistentEntity(Class<?> type)
Adds the given type to the
MappingContext . |
protected E |
addPersistentEntity(TypeInformation<?> typeInformation)
Adds the given
TypeInformation to the MappingContext . |
void |
afterPropertiesSet() |
protected abstract <T> E |
createPersistentEntity(TypeInformation<T> typeInformation)
Creates the concrete
PersistentEntity instance. |
protected abstract P |
createPersistentProperty(Field field,
PropertyDescriptor descriptor,
E owner,
SimpleTypeHolder simpleTypeHolder)
Creates the concrete instance of
PersistentProperty . |
Collection<TypeInformation<?>> |
getManagedTypes()
|
Collection<E> |
getPersistentEntities()
Returns all
PersistentEntity s held in the context. |
E |
getPersistentEntity(Class<?> type)
Returns a
PersistentEntity for the given Class . |
E |
getPersistentEntity(P persistentProperty)
Returns the
PersistentEntity mapped by the given PersistentProperty . |
E |
getPersistentEntity(TypeInformation<?> type)
Returns a
PersistentEntity for the given TypeInformation . |
PersistentPropertyPath<P> |
getPersistentPropertyPath(InvalidPersistentPropertyPath invalidPath)
Returns the
PersistentPropertyPath for the resolvable part of the given InvalidPersistentPropertyPath . |
PersistentPropertyPath<P> |
getPersistentPropertyPath(PropertyPath propertyPath)
Returns all
PersistentProperty s for the given path expression based on the given PropertyPath . |
PersistentPropertyPath<P> |
getPersistentPropertyPath(String propertyPath,
Class<?> type)
Returns all
PersistentProperty s for the given dot path notation based on the given type. |
boolean |
hasPersistentEntityFor(Class<?> type)
Returns whether the
MappingContext currently contains a PersistentEntity for the type. |
void |
initialize()
Initializes the mapping context.
|
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
setInitialEntitySet(Set<? extends Class<?>> initialEntitySet)
Sets the
Set of types to populate the context initially. |
void |
setSimpleTypeHolder(SimpleTypeHolder simpleTypes)
Configures the
SimpleTypeHolder to be used by the MappingContext . |
void |
setStrict(boolean strict)
Configures whether the
MappingContext is in strict mode which means, that it will throw
MappingException s in case one tries to lookup a PersistentEntity not already in the context. |
protected boolean |
shouldCreatePersistentEntityFor(TypeInformation<?> type)
Returns whether a
PersistentEntity instance should be created for the given TypeInformation . |
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet)
Set
of types to populate the context initially.initialEntitySet
- public void setStrict(boolean strict)
MappingContext
is in strict mode which means, that it will throw
MappingException
s in case one tries to lookup a PersistentEntity
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.strict
- public void setSimpleTypeHolder(SimpleTypeHolder simpleTypes)
SimpleTypeHolder
to be used by the MappingContext
. Allows customization of what
types will be regarded as simple types and thus not recursively analysed. Setting this to null will
reset the context to use the default SimpleTypeHolder
.simpleTypes
- public Collection<E> getPersistentEntities()
MappingContext
PersistentEntity
s held in the context.getPersistentEntities
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
public E getPersistentEntity(Class<?> type)
MappingContext
PersistentEntity
for the given Class
. Will return null for types that are
considered simple ones.getPersistentEntity
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
type
- must not be null.SimpleTypeHolder.isSimpleType(Class)
public boolean hasPersistentEntityFor(Class<?> type)
MappingContext
MappingContext
currently contains a PersistentEntity
for the type.hasPersistentEntityFor
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
type
- can be null.public E getPersistentEntity(TypeInformation<?> type)
MappingContext
PersistentEntity
for the given TypeInformation
. Will return null for types
that are considered simple ones.getPersistentEntity
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
type
- must not be null.SimpleTypeHolder.isSimpleType(Class)
public E getPersistentEntity(P persistentProperty)
MappingContext
PersistentEntity
mapped by the given PersistentProperty
.getPersistentEntity
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
PersistentEntity
mapped by the given PersistentProperty
or null if no
PersistentEntity
exists for it or the PersistentProperty
does not refer to an entity (the
type of the property is considered simple see
SimpleTypeHolder.isSimpleType(Class)
).public PersistentPropertyPath<P> getPersistentPropertyPath(PropertyPath propertyPath)
MappingContext
PersistentProperty
s for the given path expression based on the given PropertyPath
.getPersistentPropertyPath
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
propertyPath
- must not be null.PersistentPropertyPath
representing the given PropertyPath
.public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, Class<?> type)
MappingContext
PersistentProperty
s for the given dot path notation based on the given type.getPersistentPropertyPath
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
propertyPath
- must not be null.type
- must not be null.PersistentPropertyPath
representing the given property path on the given type.public PersistentPropertyPath<P> getPersistentPropertyPath(InvalidPersistentPropertyPath invalidPath)
MappingContext
PersistentPropertyPath
for the resolvable part of the given InvalidPersistentPropertyPath
.getPersistentPropertyPath
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
invalidPath
- must not be null.PersistentPropertyPath
for the resolvable part of the given InvalidPersistentPropertyPath
.protected E addPersistentEntity(Class<?> type)
MappingContext
.type
- must not be null.protected E addPersistentEntity(TypeInformation<?> typeInformation)
TypeInformation
to the MappingContext
.typeInformation
- must not be null.public Collection<TypeInformation<?>> getManagedTypes()
MappingContext
getManagedTypes
in interface MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>
TypeInformation
s for the PersistentEntity
s in the MappingContext
.protected abstract <T> E createPersistentEntity(TypeInformation<T> typeInformation)
PersistentEntity
instance.T
- typeInformation
- protected abstract P createPersistentProperty(Field field, PropertyDescriptor descriptor, E owner, SimpleTypeHolder simpleTypeHolder)
PersistentProperty
.field
- descriptor
- owner
- simpleTypeHolder
- public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public void initialize()
setInitialEntitySet(Set)
to the
context.protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type)
PersistentEntity
instance should be created for the given TypeInformation
. By
default this will reject this for all types considered simple, 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.type
- will never be null.Copyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.