org.springframework.data.mapping.context

## Class PersistentEntities

- java.lang.Object
- - org.springframework.data.mapping.context.PersistentEntities

All Implemented Interfaces:
  Iterable<PersistentEntity<?,? extends PersistentProperty<?>>>, Supplier<Stream<PersistentEntity<?,? extends PersistentProperty<?>>>>, Streamable<PersistentEntity<?,? extends PersistentProperty<?>>>

    public class PersistentEntities
    extends Object
    implements Streamable<PersistentEntity<?,? extends PersistentProperty<?>>>

Value object to access `PersistentEntity` instances managed by `MappingContext`s.

Since:
  1.8
Author:
  Oliver Gierke, Christoph Strobl, Mark Paluch

### Constructor Summary

Constructors
Constructor and Description
`PersistentEntities(Iterable<? extends MappingContext<?,?>> contexts)` Creates a new `PersistentEntities` for the given `MappingContext`s.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`PersistentEntity<?,?>` `getEntityUltimatelyReferredToBy(PersistentProperty<?> property)` Returns the `PersistentEntity` the given `PersistentProperty` refers to in case it's an association.
`Streamable<TypeInformation<?>>` `getManagedTypes()` Returns all `TypeInformation` exposed by the registered `MappingContext`s.
`Optional<PersistentEntity<?,? extends PersistentProperty<?>>>` `getPersistentEntity(Class<?> type)` Returns the `PersistentEntity` for the given type.
`PersistentEntity<?,? extends PersistentProperty<?>>` `getRequiredPersistentEntity(Class<?> type)` Returns the `PersistentEntity` for the given type.
`TypeInformation<?>` `getTypeUltimatelyReferredToBy(PersistentProperty<?> property)` Returns the type the given `PersistentProperty` ultimately refers to.
`Iterator<PersistentEntity<?,? extends PersistentProperty<?>>>` `iterator()`
`<T> Optional<T>` `mapOnContext(Class<?> type, BiFunction<MappingContext<?,? extends PersistentProperty<?>>,PersistentEntity<?,?>,T> combiner)` Executes the given `BiFunction` on the given `MappingContext` and `PersistentEntity` based on the given type.
`static PersistentEntities` `of(MappingContext<?,?>... contexts)` Creates a new `PersistentEntities` for the given `MappingContext`s.

### 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.util.Streamable

`and, and, and, and, empty, filter, flatMap, get, isEmpty, map, of, of, of, stream, toList, toSet, toStreamable, toStreamable`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Constructor Detail

#### PersistentEntities

    public PersistentEntities(Iterable<? extends MappingContext<?,?>> contexts)

Creates a new `PersistentEntities` for the given `MappingContext`s.

Parameters:
  `contexts` -

### Method Detail

#### of

    public static PersistentEntities of(MappingContext<?,?>... contexts)

Creates a new `PersistentEntities` for the given `MappingContext`s.

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

#### getPersistentEntity

    public Optional<PersistentEntity<?,? extends PersistentProperty<?>>> getPersistentEntity(Class<?> type)

Returns the `PersistentEntity` for the given type. Will consider all `MappingContext`s registered but return Optional#empty() in case none of the registered ones already have a `PersistentEntity` registered for the given type.

Parameters:
  `type` - can be null.
Returns:
See Also:
  `MappingContext.hasPersistentEntityFor(Class)`, `MappingContext.getPersistentEntity(Class)`

#### getRequiredPersistentEntity

    public PersistentEntity<?,? extends PersistentProperty<?>> getRequiredPersistentEntity(Class<?> type)

Returns the `PersistentEntity` for the given type. Will consider all `MappingContext`s registered and create a new `PersistentEntity` in case none of the registered ones already have it registered for the given type, if there is only one context available.

Parameters:
  `type` - must not be null.
Returns:
  the `PersistentEntity` for the given domain type.
Throws:
  `MappingException` - if the `PersistentEntity` cannot be found or `created` by the underlying `MappingContext`.
See Also:
  `MappingContext.getRequiredPersistentEntity(Class)`

#### mapOnContext

    public <T> Optional<T> mapOnContext(Class<?> type,
                                        BiFunction<MappingContext<?,? extends PersistentProperty<?>>,PersistentEntity<?,?>,T> combiner)

Executes the given `BiFunction` on the given `MappingContext` and `PersistentEntity` based on the given type. Considers all `MappingContext`s for lookup. This method will create a new `PersistentEntity` in case there is only a single `MappingContext` registered.

Parameters:
  `type` - must not be null.
  `combiner` - must not be null.
Returns:
  result of the `BiFunction`.

#### getManagedTypes

    public Streamable<TypeInformation<?>> getManagedTypes()

Returns all `TypeInformation` exposed by the registered `MappingContext`s.

Returns:

#### iterator

    public Iterator<PersistentEntity<?,? extends PersistentProperty<?>>> iterator()

Specified by:
  `iterator` in interface `Iterable<PersistentEntity<?,? extends PersistentProperty<?>>>`

#### getEntityUltimatelyReferredToBy

    @Nullable
    public PersistentEntity<?,?> getEntityUltimatelyReferredToBy(PersistentProperty<?> property)

Returns the `PersistentEntity` the given `PersistentProperty` refers to in case it's an association. For direct aggregate references, that's simply the entity for the `PersistentProperty`'s actual type. If the property type is not an entity - as it might rather refer to the identifier type - we either use the reference's defined target type and fall back to trying to find a `PersistentEntity` identified by the `PersistentProperty`'s actual type.

Parameters:
  `property` - must not be null.
Returns:
Since:
  2.1

#### getTypeUltimatelyReferredToBy

    public TypeInformation<?> getTypeUltimatelyReferredToBy(PersistentProperty<?> property)

Returns the type the given `PersistentProperty` ultimately refers to. In case it's of a unique identifier type of an entity known it'll return the entity type.

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