DATACMNS-867 - Adapt codebase after rebase on forward ports.

This commit is contained in:
Oliver Gierke
2016-12-20 13:47:18 +01:00
parent 9b3dd05baa
commit 2210f2e8e9
12 changed files with 60 additions and 102 deletions

View File

@@ -22,6 +22,7 @@ import lombok.ToString;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.Optional;
import org.springframework.beans.BeanUtils;
import org.springframework.data.mapping.PropertyPath;
@@ -118,24 +119,29 @@ class PropertyPathInformation implements PathInformation {
*/
@Override
public Path<?> reifyPath(EntityPathResolver resolver) {
return reifyPath(resolver, path, null);
return reifyPath(resolver, path, Optional.empty());
}
private static Path<?> reifyPath(EntityPathResolver resolver, PropertyPath path, Path<?> base) {
private static Path<?> reifyPath(EntityPathResolver resolver, PropertyPath path, Optional<Path<?>> base) {
if (base instanceof CollectionPathBase) {
return reifyPath(resolver, path, (Path<?>) ((CollectionPathBase<?, ?, ?>) base).any());
}
Optional<Path<?>> map = base.filter(it -> it instanceof CollectionPathBase)
.map(it -> CollectionPathBase.class.cast(it))//
.map(CollectionPathBase::any)//
.map(it -> Path.class.cast(it))//
.map(it -> reifyPath(resolver, path, Optional.of(it)));
Path<?> entityPath = base != null ? base : resolver.createPath(path.getOwningType().getType());
return map.orElseGet(() -> {
Field field = ReflectionUtils.findField(entityPath.getClass(), path.getSegment());
Object value = ReflectionUtils.getField(field, entityPath);
Path<?> entityPath = base.orElseGet(() -> resolver.createPath(path.getOwningType().getType()));
if (path.hasNext()) {
return reifyPath(resolver, path.next(), (Path<?>) value);
}
Field field = ReflectionUtils.findField(entityPath.getClass(), path.getSegment());
Object value = ReflectionUtils.getField(field, entityPath);
return (Path<?>) value;
if (path.hasNext()) {
return reifyPath(resolver, path.next(), Optional.of((Path<?>) value));
}
return (Path<?>) value;
});
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.data.querydsl.binding;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -40,6 +41,7 @@ import org.springframework.util.StringUtils;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.CollectionPathBase;
/**
* Builder assembling {@link Predicate} out of {@link PropertyValues}.
@@ -148,7 +150,7 @@ public class QuerydslPredicateBuilder {
Optional<Path<?>> resolvedPath = bindings.getExistingPath(path);
return resolvedPath.orElseGet(() -> paths.computeIfAbsent(path, it -> reifyPath(path, Optional.empty())));
return resolvedPath.orElseGet(() -> paths.computeIfAbsent(path, it -> it.reifyPath(resolver)));
}
/**
@@ -192,7 +194,7 @@ public class QuerydslPredicateBuilder {
*/
private Collection<Object> convertToPropertyPathSpecificType(List<String> source, PathInformation path) {
Class<?> targetType = path.getLeafProperty().getType();
Class<?> targetType = path.getLeafType();
if (source.isEmpty() || isSingleElementCollectionWithoutText(source)) {
return Collections.emptyList();