From 49f2af2b2f3fd8cea3a2b2bf1ceb81a59c9219b0 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 29 Nov 2023 09:17:13 +0100 Subject: [PATCH] Allow reuse of `TypeInformation` when obtaining a `PersistentPropertyPath`. Closes #2992 --- .../context/AbstractMappingContext.java | 8 ++++++-- .../data/mapping/context/MappingContext.java | 20 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index 198fce386..7a7e01553 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -33,7 +33,6 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; @@ -304,6 +303,11 @@ public abstract class AbstractMappingContext getPersistentPropertyPath(String propertyPath, TypeInformation type) { + return persistentPropertyPathFactory.from(type, propertyPath); + } + @Override public PersistentPropertyPaths findPersistentPropertyPaths(Class type, Predicate predicate) { @@ -315,7 +319,7 @@ public abstract class AbstractMappingContext, P extends Pers * * @param propertyPath must not be {@literal null}. * @return the {@link PersistentPropertyPath} representing the given {@link PropertyPath}. - * @throws InvalidPersistentPropertyPath in case not all of the segments of the given {@link PropertyPath} can be - * resolved. + * @throws InvalidPersistentPropertyPath in case not all segments of the given {@link PropertyPath} can be resolved. */ PersistentPropertyPath

getPersistentPropertyPath(PropertyPath propertyPath) throws InvalidPersistentPropertyPath; @@ -169,16 +168,27 @@ public interface MappingContext, P extends Pers * @param propertyPath must not be {@literal null}. * @param type must not be {@literal null}. * @return the {@link PersistentPropertyPath} representing the given property path on the given type. - * @throws InvalidPersistentPropertyPath in case not all of the segments of the given property path can be resolved. + * @throws InvalidPersistentPropertyPath in case not all segments of the given property path can be resolved. */ PersistentPropertyPath

getPersistentPropertyPath(String propertyPath, Class type) throws InvalidPersistentPropertyPath; + /** + * Returns all {@link PersistentProperty}s for the given dot path notation based on the given type. + * + * @param propertyPath must not be {@literal null}. + * @param type must not be {@literal null}. + * @return the {@link PersistentPropertyPath} representing the given property path on the given type. + * @throws InvalidPersistentPropertyPath in case not all segments of the given property path can be resolved. + * @since 3.2.1 + */ + PersistentPropertyPath

getPersistentPropertyPath(String propertyPath, TypeInformation type) + throws InvalidPersistentPropertyPath; + /** * Returns all {@link PersistentPropertyPath}s pointing to properties on the given type that match the given * {@link 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. + * that's already included in the path. Note, that is a potentially expensive operation as results cannot be cached. * * @param type must not be {@literal null}. * @param predicate must not be {@literal null}.