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
ConstructorDescriptionPersistentEntities
(Iterable<? extends MappingContext<?, ?>> contexts) Creates a newPersistentEntities
for the givenMappingContext
s. -
Method Summary
Modifier and TypeMethodDescriptionPersistentEntity<?,
?> getEntityUltimatelyReferredToBy
(PersistentProperty<?> property) Returns thePersistentEntity
the givenPersistentProperty
refers to in case it's an association.Returns allTypeInformation
exposed by the registeredMappingContext
s.Optional<PersistentEntity<?,
? extends PersistentProperty<?>>> getPersistentEntity
(Class<?> type) Returns thePersistentEntity
for the given type.PersistentEntity<?,
? extends PersistentProperty<?>> getRequiredPersistentEntity
(Class<?> type) Returns thePersistentEntity
for the given type.getTypeUltimatelyReferredToBy
(PersistentProperty<?> property) Returns the type the givenPersistentProperty
ultimately refers to.Iterator<PersistentEntity<?,
? extends PersistentProperty<?>>> iterator()
<T> Optional<T>
mapOnContext
(Class<?> type, BiFunction<MappingContext<?, ? extends PersistentProperty<?>>, PersistentEntity<?, ?>, T> combiner) Executes the givenBiFunction
on the givenMappingContext
andPersistentEntity
based on the given type.static PersistentEntities
of
(MappingContext<?, ?>... contexts) Creates a newPersistentEntities
for the givenMappingContext
s.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PersistentEntities
Creates a newPersistentEntities
for the givenMappingContext
s.- Parameters:
contexts
-
-
-
Method Details
-
of
Creates a newPersistentEntities
for the givenMappingContext
s.- Parameters:
contexts
- must not be null.- Returns:
-
getPersistentEntity
public Optional<PersistentEntity<?,? extends PersistentProperty<?>>> getPersistentEntity(Class<?> type) Returns thePersistentEntity
for the given type. Will consider allMappingContext
s registered but return Optional#empty() in case none of the registered ones already have aPersistentEntity
registered for the given type.- Parameters:
type
- can be null.- Returns:
- See Also:
-
getRequiredPersistentEntity
public PersistentEntity<?,? extends PersistentProperty<?>> getRequiredPersistentEntity(Class<?> type) Returns thePersistentEntity
for the given type. Will consider allMappingContext
s registered and create a newPersistentEntity
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 thePersistentEntity
cannot be found orcreated
by the underlyingMappingContext
.- See Also:
-
mapOnContext
public <T> Optional<T> mapOnContext(Class<?> type, BiFunction<MappingContext<?, ? extends PersistentProperty<?>>, PersistentEntity<?, ?>, T> combiner) Executes the givenBiFunction
on the givenMappingContext
andPersistentEntity
based on the given type. Considers allMappingContext
s for lookup. This method will create a newPersistentEntity
in case there is only a singleMappingContext
registered.- Parameters:
type
- must not be null.combiner
- must not be null.- Returns:
- result of the
BiFunction
.
-
getManagedTypes
Returns allTypeInformation
exposed by the registeredMappingContext
s.- Returns:
-
iterator
- Specified by:
iterator
in interfaceIterable<PersistentEntity<?,
? extends PersistentProperty<?>>>
-
getEntityUltimatelyReferredToBy
@Nullable public PersistentEntity<?,?> getEntityUltimatelyReferredToBy(PersistentProperty<?> property) Returns thePersistentEntity
the givenPersistentProperty
refers to in case it's an association. For direct aggregate references, that's simply the entity for thePersistentProperty
'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 aPersistentEntity
identified by thePersistentProperty
's actual type.- Parameters:
property
- must not be null.- Returns:
- Since:
- 2.1
-
getTypeUltimatelyReferredToBy
Returns the type the givenPersistentProperty
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:
-