Browse Source

Use contextual information when creating PersistentPropertyPaths.

In oder to preserve contextual information the PersistentPropertyPathFactory now obtains EntityInformation for properties from the MappingContext via their PersistentProperty representation instead of plain the TypeInformation as the former contains more information about the actual type and signatures.

Closes #2293.
Original pull request: #2294.
pull/2299/head
Christoph Strobl 5 years ago committed by Mark Paluch
parent
commit
b51bee7a0b
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 11
      src/main/java/org/springframework/data/mapping/context/PersistentPropertyPathFactory.java

11
src/main/java/org/springframework/data/mapping/context/PersistentPropertyPathFactory.java

@ -222,8 +222,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -222,8 +222,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
return null;
}
TypeInformation<?> type = property.getTypeInformation().getRequiredActualType();
return Pair.of(path.append(property), iterator.hasNext() ? context.getRequiredPersistentEntity(type) : entity);
return Pair.of(path.append(property), iterator.hasNext() ? context.getRequiredPersistentEntity(property) : entity);
}
private <T> Collection<PersistentPropertyPath<P>> from(TypeInformation<T> type, Predicate<? super P> filter,
@ -236,6 +235,12 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -236,6 +235,12 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
}
E entity = context.getRequiredPersistentEntity(actualType);
return from(entity, filter, traversalGuard, basePath);
}
private Collection<PersistentPropertyPath<P>> from(E entity, Predicate<? super P> filter, Predicate<P> traversalGuard,
DefaultPersistentPropertyPath<P> basePath) {
Set<PersistentPropertyPath<P>> properties = new HashSet<>();
PropertyHandler<P> propertyTester = persistentProperty -> {
@ -254,7 +259,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends @@ -254,7 +259,7 @@ class PersistentPropertyPathFactory<E extends PersistentEntity<?, P>, P extends
}
if (traversalGuard.and(IS_ENTITY).test(persistentProperty)) {
properties.addAll(from(typeInformation, filter, traversalGuard, currentPath));
properties.addAll(from(context.getPersistentEntity(persistentProperty), filter, traversalGuard, currentPath));
}
};

Loading…
Cancel
Save