org.springframework.data.mapping.context

## 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 concrete `PersistentEntity` type the `MappingContext` implementation creates
  `P` - the concrete `PersistentProperty` type the `MappingContext` 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

Constructors
`protected` `AbstractMappingContext()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected Optional<E>` `addPersistentEntity(Class<?> type)` Adds the given type to the `MappingContext`.
`protected Optional<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(Property property, E owner, SimpleTypeHolder simpleTypeHolder)` Creates the concrete instance of `PersistentProperty`.
`protected <T> PersistentPropertyPaths<T,P>` `doFindPersistentPropertyPaths(Class<T> type, Predicate<? super P> predicate, Predicate<P> traversalGuard)` Actually looks up the `PersistentPropertyPaths` for the given type, selection predicate and traversal guard.
`<T> PersistentPropertyPaths<T,P>` `findPersistentPropertyPaths(Class<T> type, Predicate<? super P> predicate)` Returns all `PersistentPropertyPath`s pointing to properties on the given type that match the given `Predicate`.
`Collection<TypeInformation<?>>` `getManagedTypes()` Returns the `TypeInformation`s for all `PersistentEntity`s in the `MappingContext`.
`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(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` `setApplicationContext(ApplicationContext applicationContext)`
`void` `setApplicationEventPublisher(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`.

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

#### AbstractMappingContext

    protected AbstractMappingContext()

### Method Detail

#### setApplicationEventPublisher

    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)

Specified by:
  `setApplicationEventPublisher` in interface `ApplicationEventPublisherAware`

#### setApplicationContext

    public void setApplicationContext(ApplicationContext applicationContext)
                               throws BeansException

Specified by:
  `setApplicationContext` in interface `ApplicationContextAware`
Throws:
  `BeansException`

#### setInitialEntitySet

    public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet)

Sets the `Set` of types to populate the context initially.

Parameters:
  `initialEntitySet` -

#### setStrict

    public 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. This defaults to false so that unknown types will be transparently added to the MappingContext if not known in advance.

Parameters:
  `strict` -

#### setSimpleTypeHolder

    public void setSimpleTypeHolder(SimpleTypeHolder simpleTypes)

Configures the `SimpleTypeHolder` to be used by the `MappingContext`. Allows customization of what types will be regarded as simple types and thus not recursively analyzed.

Parameters:
  `simpleTypes` - must not be null.

#### getPersistentEntities

    public Collection<E> getPersistentEntities()

Description copied from interface: `MappingContext`
Returns all `PersistentEntity`s held in the context.

Specified by:
  `getPersistentEntities` in interface `MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>`
Returns:
  never null.

#### getPersistentEntity

    @Nullable
    public E getPersistentEntity(Class<?> type)

Description copied from interface: `MappingContext`
Returns a `PersistentEntity` for the given `Class`. Will return `null` for types that are considered simple ones.

Specified by:
  `getPersistentEntity` in interface `MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>`
Parameters:
  `type` - must not be null.
Returns:
  null if no `PersistentEntity` found for type.
See Also:
  `SimpleTypeHolder.isSimpleType(Class)`

#### hasPersistentEntityFor

    public boolean hasPersistentEntityFor(Class<?> type)

Description copied from interface: `MappingContext`
Returns whether the `MappingContext` currently contains a `PersistentEntity` for the type.

Specified by:
  `hasPersistentEntityFor` in interface `MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>`
Parameters:
  `type` - must not be null.
Returns:
  true if `PersistentEntity` present for given type.

#### getPersistentEntity

    @Nullable
    public E getPersistentEntity(TypeInformation<?> type)

Description copied from interface: `MappingContext`
Returns a `PersistentEntity` for the given `TypeInformation`. Will return `null` for types that are considered simple ones.

Specified by:
  `getPersistentEntity` in interface `MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>`
Parameters:
  `type` - must not be null.
Returns:
  null if no `PersistentEntity` found for `TypeInformation`.
See Also:
  `SimpleTypeHolder.isSimpleType(Class)`

#### getPersistentEntity

    @Nullable
    public E getPersistentEntity(P persistentProperty)

Description copied from interface: `MappingContext`
Returns the `PersistentEntity` mapped by the given `PersistentProperty`.

Specified by:
  `getPersistentEntity` in interface `MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>`
Parameters:
  `persistentProperty` - must not be null.
Returns:
  the `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)`).

#### getPersistentPropertyPath

    public PersistentPropertyPath<P> getPersistentPropertyPath(PropertyPath propertyPath)

Description copied from interface: `MappingContext`
Returns all `PersistentProperty`s for the given path expression based on the given `PropertyPath`.

Specified by:
  `getPersistentPropertyPath` in interface `MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>`
Parameters:
  `propertyPath` - must not be null.
Returns:
  the `PersistentPropertyPath` representing the given `PropertyPath`.

#### getPersistentPropertyPath

    public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath,
                                                               Class<?> type)

Description copied from interface: `MappingContext`
Returns all `PersistentProperty`s for the given dot path notation based on the given type.

Specified by:
  `getPersistentPropertyPath` in interface `MappingContext<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 all `PersistentPropertyPath`s pointing to properties on the given type that match the given `Predicate`. 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 is a potentially expensive operation as results cannot be cached.

Specified by:
  `findPersistentPropertyPaths` in interface `MappingContext<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 the `PersistentPropertyPaths` for the given type, selection predicate and traversal guard. Primary purpose is to allow sub-types to alter the default traversal guard, e.g. used by `findPersistentPropertyPaths(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:
  `findPersistentPropertyPaths(Class, Predicate)`

#### addPersistentEntity

    protected Optional<E> addPersistentEntity(Class<?> type)

Adds the given type to the `MappingContext`.

Parameters:
  `type` - must not be null.
Returns:

#### addPersistentEntity

    protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation)

Adds the given `TypeInformation` to the `MappingContext`.

Parameters:
  `typeInformation` - must not be null.
Returns:

#### getManagedTypes

    public Collection<TypeInformation<?>> getManagedTypes()

Description copied from interface: `MappingContext`
Returns the `TypeInformation`s for all `PersistentEntity`s in the `MappingContext`.

Specified by:
  `getManagedTypes` in interface `MappingContext<E extends MutablePersistentEntity<?,P>,P extends PersistentProperty<P>>`
Returns:
  all `TypeInformation`s for the `PersistentEntity`s in the `MappingContext`.

#### createPersistentEntity

    protected abstract <T> E createPersistentEntity(TypeInformation<T> typeInformation)

Creates the concrete `PersistentEntity` instance.

Type Parameters:
  `T` -
Parameters:
  `typeInformation` -
Returns:

#### createPersistentProperty

    protected abstract P createPersistentProperty(Property property,
                                                  E owner,
                                                  SimpleTypeHolder simpleTypeHolder)

Creates the concrete instance of `PersistentProperty`.

Parameters:
  `property` -
  `owner` -
  `simpleTypeHolder` -
Returns:

#### afterPropertiesSet

    public void afterPropertiesSet()

Specified by:
  `afterPropertiesSet` in interface `InitializingBean`

#### initialize

    public void initialize()

Initializes the mapping context. Will add the types configured through `setInitialEntitySet(Set)` to the context.

#### shouldCreatePersistentEntityFor

    protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type)

Returns whether a `PersistentEntity` instance should be created for the given `TypeInformation`. 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: