DATACMNS-867 - Adapt codebase after rebase on forward ports.
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -56,6 +56,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
|
||||
|
||||
private final Class<? extends T> repositoryInterface;
|
||||
|
||||
private RepositoryFactorySupport factory;
|
||||
private Key queryLookupStrategyKey;
|
||||
private Optional<Class<?>> repositoryBaseClass = Optional.empty();
|
||||
private Optional<Object> customImplementation = Optional.empty();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.repository.util;
|
||||
|
||||
import javaslang.collection.LinkedHashMap;
|
||||
import javaslang.collection.LinkedHashSet;
|
||||
import javaslang.collection.Traversable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.repository.util.QueryExecutionConverters.WrapperType;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Converter implementations to map from and to Javaslang collections.
|
||||
@@ -112,15 +112,15 @@ class JavaslangCollections {
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
||||
if (source instanceof List) {
|
||||
return ReflectionUtils.invokeMethod(LIST_FACTORY_METHOD, null, source);
|
||||
return javaslang.collection.List.ofAll((Iterable<?>) source);
|
||||
}
|
||||
|
||||
if (source instanceof java.util.Set) {
|
||||
return ReflectionUtils.invokeMethod(SET_FACTORY_METHOD, null, source);
|
||||
return LinkedHashSet.ofAll((Iterable<?>) source);
|
||||
}
|
||||
|
||||
if (source instanceof java.util.Map) {
|
||||
return ReflectionUtils.invokeMethod(MAP_FACTORY_METHOD, null, source);
|
||||
return LinkedHashMap.ofAll((java.util.Map<?, ?>) source);
|
||||
}
|
||||
|
||||
return source;
|
||||
@@ -128,9 +128,6 @@ class JavaslangCollections {
|
||||
};
|
||||
|
||||
private static final Set<ConvertiblePair> CONVERTIBLE_PAIRS;
|
||||
private static final Method LIST_FACTORY_METHOD;
|
||||
private static final Method SET_FACTORY_METHOD;
|
||||
private static final Method MAP_FACTORY_METHOD;
|
||||
|
||||
static {
|
||||
|
||||
@@ -139,11 +136,6 @@ class JavaslangCollections {
|
||||
pairs.add(new ConvertiblePair(Map.class, javaslang.collection.Traversable.class));
|
||||
|
||||
CONVERTIBLE_PAIRS = Collections.unmodifiableSet(pairs);
|
||||
|
||||
MAP_FACTORY_METHOD = ReflectionUtils.findMethod(javaslang.collection.LinkedHashMap.class, "ofAll", Map.class);
|
||||
LIST_FACTORY_METHOD = ReflectionUtils.findMethod(javaslang.collection.List.class, "ofAll", Iterable.class);
|
||||
SET_FACTORY_METHOD = ReflectionUtils.findMethod(javaslang.collection.LinkedHashSet.class, "ofAll",
|
||||
Iterable.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ import scala.Function0;
|
||||
import scala.Option;
|
||||
import scala.runtime.AbstractFunction0;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -60,8 +60,8 @@ import com.google.common.base.Optional;
|
||||
* <li>{@code org.springframework.util.concurrent.ListenableFuture<}</li>
|
||||
* <li>{@code javaslang.control.Option} - as of 1.13</li>
|
||||
* <li>{@code javaslang.collection.Seq}, {@code javaslang.collection.Map}, {@code javaslang.collection.Set} - as of
|
||||
* <li>Reactive wrappers supported by {@link ReactiveWrappers}</li>
|
||||
* 1.13</li>
|
||||
* <li>Reactive wrappers supported by {@link ReactiveWrappers} - as of 2.0</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
@@ -482,7 +482,7 @@ public abstract class QueryExecutionConverters {
|
||||
* @param conversionService must not be {@literal null}.
|
||||
*/
|
||||
public NullableWrapperToJavaslangOptionConverter(ConversionService conversionService) {
|
||||
super(conversionService, javaslang.control.Option.none(), getWrapperType());
|
||||
super(conversionService, javaslang.control.Option.none(), javaslang.control.Option.class);
|
||||
}
|
||||
|
||||
public static WrapperType getWrapperType() {
|
||||
@@ -582,17 +582,6 @@ public abstract class QueryExecutionConverters {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
private static final Supplier<Object> NULL_SUPPLIER = new Supplier<Object>() {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.util.function.Supplier#get()
|
||||
*/
|
||||
public Object get() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
@@ -602,7 +591,7 @@ public abstract class QueryExecutionConverters {
|
||||
public Object convert(Object source) {
|
||||
|
||||
if (source instanceof javaslang.control.Option) {
|
||||
return ((javaslang.control.Option<Object>) source).getOrElse(NULL_SUPPLIER);
|
||||
return ((javaslang.control.Option<Object>) source).getOrElse(() -> null);
|
||||
}
|
||||
|
||||
if (source instanceof Traversable) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
@@ -59,11 +59,11 @@ public class QuerydslBindingsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void returnsNullIfNoBindingRegisteredForPath() {
|
||||
public void returnsEmptyOptionalIfNoBindingRegisteredForPath() {
|
||||
|
||||
PathInformation path = PropertyPathInformation.of("lastname", User.class);
|
||||
|
||||
assertThat(bindings.getBindingForPath(path)).isNull();
|
||||
assertThat(bindings.getBindingForPath(path)).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -102,7 +102,7 @@ public class QuerydslBindingsUnitTests {
|
||||
|
||||
PathInformation path = PropertyPathInformation.of("inceptionYear", User.class);
|
||||
|
||||
assertThat(bindings.getBindingForPath(path)).isNull();
|
||||
assertThat(bindings.getBindingForPath(path)).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.repository.core.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.Getter;
|
||||
@@ -101,7 +99,7 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
|
||||
|
||||
@Test // DATACMNS-928
|
||||
public void doesNotCreatePublishingMethodIfNoAnnotationDetected() {
|
||||
assertThat(EventPublishingMethod.of(Object.class), is(nullValue()));
|
||||
assertThat(EventPublishingMethod.of(Object.class)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-928
|
||||
|
||||
@@ -255,8 +255,8 @@ public class ExampleSpecificationAccessorUnitTests {
|
||||
ExampleMatcher matcher = ExampleMatcher.matching()//
|
||||
.withMatcher("firstname", exact());
|
||||
|
||||
assertThat(new ExampleMatcherAccessor(matcher).getPropertySpecifier("firstname").getStringMatcher(),
|
||||
is(StringMatcher.EXACT));
|
||||
assertThat(new ExampleMatcherAccessor(matcher).getPropertySpecifier("firstname").getStringMatcher())
|
||||
.isEqualTo(StringMatcher.EXACT);
|
||||
}
|
||||
|
||||
static class Person {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RepositoryFactoryBeanSupportUnitTests {
|
||||
public void initializationFailsWithMissingRepositoryInterface() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)//
|
||||
.isThrownBy(() -> new DummyRepositoryFactoryBean().afterPropertiesSet())//
|
||||
.isThrownBy(() -> new DummyRepositoryFactoryBean(null))//
|
||||
.withMessageContaining("Repository interface");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.data.repository.util;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.repository.util.QueryExecutionConverters.*;
|
||||
|
||||
import javaslang.collection.HashMap;
|
||||
import javaslang.collection.HashSet;
|
||||
import javaslang.collection.LinkedHashMap;
|
||||
import javaslang.collection.LinkedHashSet;
|
||||
import javaslang.collection.Seq;
|
||||
import javaslang.collection.Traversable;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -29,7 +29,6 @@ import rx.Observable;
|
||||
import rx.Single;
|
||||
import scala.Option;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -44,7 +43,6 @@ import org.reactivestreams.Publisher;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
@@ -201,12 +199,12 @@ public class QueryExecutionConvertersUnitTests {
|
||||
|
||||
@Test // DATACMNS-937
|
||||
public void unwrapsEmptyJavaslangOption() {
|
||||
assertThat(QueryExecutionConverters.unwrap(optionNone())).isNull();
|
||||
assertThat(QueryExecutionConverters.unwrap(javaslang.control.Option.none())).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-937
|
||||
public void unwrapsJavaslangOption() {
|
||||
assertThat(QueryExecutionConverters.unwrap(option("string"))).isEqualTo("string");
|
||||
assertThat(QueryExecutionConverters.unwrap(javaslang.control.Option.of("string"))).isEqualTo("string");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
@@ -257,9 +255,9 @@ public class QueryExecutionConvertersUnitTests {
|
||||
@Test // DATACMNS-940
|
||||
public void unwrapsJavaslangCollectionsToJavaOnes() {
|
||||
|
||||
assertThat(unwrap(javaslangList(1, 2, 3))).isInstanceOf(List.class);
|
||||
assertThat(unwrap(javaslangSet(1, 2, 3))).isInstanceOf(Set.class);
|
||||
assertThat(unwrap(javaslangMap("key", "value"))).isInstanceOf(Map.class);
|
||||
assertThat(unwrap(javaslang.collection.List.of(1, 2, 3))).isInstanceOf(List.class);
|
||||
assertThat(unwrap(LinkedHashSet.of(1, 2, 3))).isInstanceOf(Set.class);
|
||||
assertThat(unwrap(LinkedHashMap.of("key", "value"))).isInstanceOf(Map.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1005
|
||||
@@ -268,40 +266,4 @@ public class QueryExecutionConvertersUnitTests {
|
||||
Set<Class<?>> allowedPageableTypes = QueryExecutionConverters.getAllowedPageableTypes();
|
||||
assertThat(allowedPageableTypes).contains(Page.class, Slice.class, List.class, Seq.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static javaslang.control.Option<Object> optionNone() {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(javaslang.control.Option.class, "none");
|
||||
return (javaslang.control.Option<Object>) ReflectionUtils.invokeMethod(method, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> javaslang.control.Option<T> option(T source) {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(javaslang.control.Option.class, "of", Object.class);
|
||||
return (javaslang.control.Option<T>) ReflectionUtils.invokeMethod(method, null, source);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> javaslang.collection.List<T> javaslangList(T... values) {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(javaslang.collection.List.class, "ofAll", Iterable.class);
|
||||
return (javaslang.collection.List<T>) ReflectionUtils.invokeMethod(method, null, Arrays.asList(values));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> javaslang.collection.Set<T> javaslangSet(T... values) {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(HashSet.class, "ofAll", Iterable.class);
|
||||
return (javaslang.collection.Set<T>) ReflectionUtils.invokeMethod(method, null, Arrays.asList(values));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <K, V> javaslang.collection.Map<K, V> javaslangMap(K key, V value) {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(HashMap.class, "ofAll", Map.class);
|
||||
return (javaslang.collection.Map<K, V>) ReflectionUtils.invokeMethod(method, null,
|
||||
Collections.singletonMap(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,7 +393,9 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
ClassTypeInformation<SampleTraversable> information = ClassTypeInformation.from(SampleTraversable.class);
|
||||
|
||||
assertThat(information.getComponentType().getType(), is(typeCompatibleWith(Integer.class)));
|
||||
assertThat(information.getComponentType()).hasValueSatisfying(it -> {
|
||||
assertThat(it.getType()).isAssignableFrom(Integer.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
@@ -401,8 +403,13 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
ClassTypeInformation<SampleMap> information = ClassTypeInformation.from(SampleMap.class);
|
||||
|
||||
assertThat(information.getComponentType().getType(), is(typeCompatibleWith(String.class)));
|
||||
assertThat(information.getMapValueType().getType(), is(typeCompatibleWith(Integer.class)));
|
||||
assertThat(information.getComponentType()).hasValueSatisfying(it -> {
|
||||
assertThat(it.getType()).isAssignableFrom(String.class);
|
||||
});
|
||||
|
||||
assertThat(information.getMapValueType()).hasValueSatisfying(it -> {
|
||||
assertThat(it.getType()).isAssignableFrom(Integer.class);
|
||||
});
|
||||
}
|
||||
|
||||
static class StringMapContainer extends MapContainer<String> {
|
||||
|
||||
Reference in New Issue
Block a user