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 MappingContexts.- Since:
- 1.8
- Author:
- Oliver Gierke, Christoph Strobl, Mark Paluch, Johannes Englmeier
-
Constructor Summary
ConstructorsConstructorDescriptionPersistentEntities(Iterable<? extends MappingContext<?, ?>> contexts) Creates a newPersistentEntitiesfor the givenMappingContexts. -
Method Summary
Modifier and TypeMethodDescriptionPersistentEntity<?,?> getEntityUltimatelyReferredToBy(PersistentProperty<?> property) Returns thePersistentEntitythe givenPersistentPropertyrefers to in case it's an association.Returns allTypeInformationexposed by the registeredMappingContexts.Optional<PersistentEntity<?,? extends PersistentProperty<?>>> getPersistentEntity(Class<?> type) Returns thePersistentEntityfor the given type.PersistentEntity<?,? extends PersistentProperty<?>> getRequiredPersistentEntity(Class<?> type) Returns thePersistentEntityfor the given type.getTypeUltimatelyReferredToBy(PersistentProperty<?> property) Returns the type the givenPersistentPropertyultimately refers to.Iterator<PersistentEntity<?,? extends PersistentProperty<?>>> iterator()<T> Optional<T>mapOnContext(Class<?> type, BiFunction<MappingContext<?, ? extends PersistentProperty<?>>, PersistentEntity<?, ?>, T> combiner) Executes the givenBiFunctionon the givenMappingContextandPersistentEntitybased on the given type.static PersistentEntitiesof(MappingContext<?, ?>... contexts) Creates a newPersistentEntitiesfor the givenMappingContexts.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PersistentEntities
Creates a newPersistentEntitiesfor the givenMappingContexts.- Parameters:
contexts-
-
-
Method Details
-
of
Creates a newPersistentEntitiesfor the givenMappingContexts.- Parameters:
contexts- must not be null.- Returns:
-
getPersistentEntity
public Optional<PersistentEntity<?,? extends PersistentProperty<?>>> getPersistentEntity(Class<?> type) Returns thePersistentEntityfor the given type. Will consider allMappingContexts registered but return Optional#empty() in case none of the registered ones already have aPersistentEntityregistered for the given type.- Parameters:
type- can be null.- Returns:
- See Also:
-
getRequiredPersistentEntity
public PersistentEntity<?,? extends PersistentProperty<?>> getRequiredPersistentEntity(Class<?> type) Returns thePersistentEntityfor the given type. Will consider allMappingContexts registered and create a newPersistentEntityin 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
PersistentEntityfor the given domain type. - Throws:
MappingException- if thePersistentEntitycannot be found orcreatedby the underlyingMappingContext.- See Also:
-
mapOnContext
public <T> Optional<T> mapOnContext(Class<?> type, BiFunction<MappingContext<?, ? extends PersistentProperty<?>>, PersistentEntity<?, ?>, T> combiner) Executes the givenBiFunctionon the givenMappingContextandPersistentEntitybased on the given type. Considers allMappingContexts for lookup. This method will create a newPersistentEntityin case there is only a singleMappingContextregistered.- Parameters:
type- must not be null.combiner- must not be null.- Returns:
- result of the
BiFunction.
-
getManagedTypes
Returns allTypeInformationexposed by the registeredMappingContexts.- Returns:
-
iterator
- Specified by:
iteratorin interfaceIterable<PersistentEntity<?,? extends PersistentProperty<?>>>
-
getEntityUltimatelyReferredToBy
@Nullable public PersistentEntity<?,?> getEntityUltimatelyReferredToBy(PersistentProperty<?> property) Returns thePersistentEntitythe givenPersistentPropertyrefers 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 aPersistentEntityidentified by thePersistentProperty's actual type.- Parameters:
property- must not be null.- Returns:
- Since:
- 2.1
-
getTypeUltimatelyReferredToBy
Returns the type the givenPersistentPropertyultimately 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:
-