Skip to content

Commit ee452d5

Browse files
committed
Allow reuse of TypeInformation when obtaining a PersistentPropertyPath.
Closes #2992
1 parent cbcf186 commit ee452d5

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import org.apache.commons.logging.Log;
3535
import org.apache.commons.logging.LogFactory;
36-
3736
import org.springframework.beans.BeanUtils;
3837
import org.springframework.beans.BeansException;
3938
import org.springframework.beans.factory.InitializingBean;
@@ -304,6 +303,11 @@ public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath,
304303
return persistentPropertyPathFactory.from(type, propertyPath);
305304
}
306305

306+
@Override
307+
public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, TypeInformation<?> type) {
308+
return persistentPropertyPathFactory.from(type, propertyPath);
309+
}
310+
307311
@Override
308312
public <T> PersistentPropertyPaths<T, P> findPersistentPropertyPaths(Class<T> type, Predicate<? super P> predicate) {
309313

@@ -315,7 +319,7 @@ public <T> PersistentPropertyPaths<T, P> findPersistentPropertyPaths(Class<T> ty
315319

316320
/**
317321
* Actually looks up the {@link PersistentPropertyPaths} for the given type, selection predicate and traversal guard.
318-
* Primary purpose is to allow sub-types to alter the default traversal guard, e.g. used by
322+
* Primary purpose is to allow subtypes to alter the default traversal guard, e.g. used by
319323
* {@link #findPersistentPropertyPaths(Class, Predicate)}.
320324
*
321325
* @param type will never be {@literal null}.

src/main/java/org/springframework/data/mapping/context/MappingContext.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ default E getRequiredPersistentEntity(P persistentProperty) throws MappingExcept
158158
*
159159
* @param propertyPath must not be {@literal null}.
160160
* @return the {@link PersistentPropertyPath} representing the given {@link PropertyPath}.
161-
* @throws InvalidPersistentPropertyPath in case not all of the segments of the given {@link PropertyPath} can be
162-
* resolved.
161+
* @throws InvalidPersistentPropertyPath in case not all segments of the given {@link PropertyPath} can be resolved.
163162
*/
164163
PersistentPropertyPath<P> getPersistentPropertyPath(PropertyPath propertyPath) throws InvalidPersistentPropertyPath;
165164

@@ -169,16 +168,27 @@ default E getRequiredPersistentEntity(P persistentProperty) throws MappingExcept
169168
* @param propertyPath must not be {@literal null}.
170169
* @param type must not be {@literal null}.
171170
* @return the {@link PersistentPropertyPath} representing the given property path on the given type.
172-
* @throws InvalidPersistentPropertyPath in case not all of the segments of the given property path can be resolved.
171+
* @throws InvalidPersistentPropertyPath in case not all segments of the given property path can be resolved.
173172
*/
174173
PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, Class<?> type)
175174
throws InvalidPersistentPropertyPath;
176175

176+
/**
177+
* Returns all {@link PersistentProperty}s for the given dot path notation based on the given type.
178+
*
179+
* @param propertyPath must not be {@literal null}.
180+
* @param type must not be {@literal null}.
181+
* @return the {@link PersistentPropertyPath} representing the given property path on the given type.
182+
* @throws InvalidPersistentPropertyPath in case not all segments of the given property path can be resolved.
183+
* @since 3.2.1
184+
*/
185+
PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, TypeInformation<?> type)
186+
throws InvalidPersistentPropertyPath;
187+
177188
/**
178189
* Returns all {@link PersistentPropertyPath}s pointing to properties on the given type that match the given
179190
* {@link Predicate}. In case of circular references the detection will stop at the property that references a type
180-
* that's already included in the path. Note, that is is a potentially expensive operation as results cannot be
181-
* cached.
191+
* that's already included in the path. Note, that is a potentially expensive operation as results cannot be cached.
182192
*
183193
* @param type must not be {@literal null}.
184194
* @param predicate must not be {@literal null}.

0 commit comments

Comments
 (0)