DATACMNS-1434 - Removed Javaslang support.
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -185,12 +185,6 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.javaslang</groupId>
|
||||
<artifactId>javaslang</artifactId>
|
||||
<version>${javaslang}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vavr</groupId>
|
||||
<artifactId>vavr</artifactId>
|
||||
|
||||
@@ -234,7 +234,6 @@ Besides that, Spring Data supports returning the following wrapper types on quer
|
||||
* `com.google.common.base.Optional`
|
||||
* `scala.Option`
|
||||
* `io.vavr.control.Option`
|
||||
* `javaslang.control.Option` (deprecated as Javaslang is deprecated)
|
||||
|
||||
Alternatively, query methods can choose not to use a wrapper type at all.
|
||||
The absence of a query result is then indicated by returning `null`.
|
||||
|
||||
@@ -19,7 +19,7 @@ NOTE: Geospatial types (such as `GeoResult`, `GeoResults`, and `GeoPage`) are av
|
||||
|`Collection<T>`|A `Collection`.
|
||||
|`List<T>`|A `List`.
|
||||
|`Optional<T>`|A Java 8 or Guava `Optional`. Expects the query method to return one result at most. If no result is found, `Optional.empty()` or `Optional.absent()` is returned. More than one result triggers an `IncorrectResultSizeDataAccessException`.
|
||||
|`Option<T>`|Either a Scala or Javaslang `Option` type. Semantically the same behavior as Java 8's `Optional`, described earlier.
|
||||
|`Option<T>`|Either a Scala or Vavr `Option` type. Semantically the same behavior as Java 8's `Optional`, described earlier.
|
||||
|`Stream<T>`|A Java 8 `Stream`.
|
||||
|`Future<T>`|A `Future`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
|
||||
|`CompletableFuture<T>`|A Java 8 `CompletableFuture`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.repository.util;
|
||||
|
||||
import javaslang.collection.LinkedHashMap;
|
||||
import javaslang.collection.LinkedHashSet;
|
||||
import javaslang.collection.Traversable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Converter implementations to map from and to Javaslang collections.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.13
|
||||
*/
|
||||
class JavaslangCollections {
|
||||
|
||||
public enum ToJavaConverter implements Converter<Object, Object> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
public WrapperType getWrapperType() {
|
||||
return WrapperType.multiValue(javaslang.collection.Traversable.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
*/
|
||||
@Nonnull
|
||||
@Override
|
||||
public Object convert(Object source) {
|
||||
|
||||
if (source instanceof javaslang.collection.Seq) {
|
||||
return ((javaslang.collection.Seq<?>) source).toJavaList();
|
||||
}
|
||||
|
||||
if (source instanceof javaslang.collection.Map) {
|
||||
return ((javaslang.collection.Map<?, ?>) source).toJavaMap();
|
||||
}
|
||||
|
||||
if (source instanceof javaslang.collection.Set) {
|
||||
return ((javaslang.collection.Set<?>) source).toJavaSet();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported Javaslang collection " + source.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
public enum FromJavaConverter implements ConditionalGenericConverter {
|
||||
|
||||
INSTANCE {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
|
||||
*/
|
||||
@Nonnull
|
||||
@Override
|
||||
public java.util.Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return CONVERTIBLE_PAIRS;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.ConditionalConverter#matches(org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
||||
// Prevent collections to be mapped to maps
|
||||
if (sourceType.isCollection() && javaslang.collection.Map.class.isAssignableFrom(targetType.getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prevent maps to be mapped to collections
|
||||
if (sourceType.isMap() && !(javaslang.collection.Map.class.isAssignableFrom(targetType.getType())
|
||||
|| targetType.getType().equals(Traversable.class))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
||||
if (source instanceof List) {
|
||||
return javaslang.collection.List.ofAll((Iterable<?>) source);
|
||||
}
|
||||
|
||||
if (source instanceof java.util.Set) {
|
||||
return LinkedHashSet.ofAll((Iterable<?>) source);
|
||||
}
|
||||
|
||||
if (source instanceof java.util.Map) {
|
||||
return LinkedHashMap.ofAll((java.util.Map<?, ?>) source);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Set<ConvertiblePair> CONVERTIBLE_PAIRS;
|
||||
|
||||
static {
|
||||
|
||||
Set<ConvertiblePair> pairs = new HashSet<>();
|
||||
pairs.add(new ConvertiblePair(Collection.class, javaslang.collection.Traversable.class));
|
||||
pairs.add(new ConvertiblePair(Map.class, javaslang.collection.Traversable.class));
|
||||
|
||||
CONVERTIBLE_PAIRS = Collections.unmodifiableSet(pairs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.repository.util;
|
||||
|
||||
import javaslang.collection.Seq;
|
||||
import javaslang.collection.Traversable;
|
||||
import javaslang.control.Try;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
@@ -97,8 +94,6 @@ public abstract class QueryExecutionConverters {
|
||||
QueryExecutionConverters.class.getClassLoader());
|
||||
private static final boolean SCALA_PRESENT = ClassUtils.isPresent("scala.Option",
|
||||
QueryExecutionConverters.class.getClassLoader());
|
||||
private static final boolean JAVASLANG_PRESENT = ClassUtils.isPresent("javaslang.control.Option",
|
||||
QueryExecutionConverters.class.getClassLoader());
|
||||
private static final boolean VAVR_PRESENT = ClassUtils.isPresent("io.vavr.control.Option",
|
||||
QueryExecutionConverters.class.getClassLoader());
|
||||
|
||||
@@ -142,20 +137,6 @@ public abstract class QueryExecutionConverters {
|
||||
UNWRAPPERS.add(ScalOptionUnwrapper.INSTANCE);
|
||||
}
|
||||
|
||||
if (JAVASLANG_PRESENT) {
|
||||
|
||||
WRAPPER_TYPES.add(NullableWrapperToJavaslangOptionConverter.getWrapperType());
|
||||
WRAPPER_TYPES.add(JavaslangCollections.ToJavaConverter.INSTANCE.getWrapperType());
|
||||
|
||||
UNWRAPPERS.add(JavaslangOptionUnwrapper.INSTANCE);
|
||||
|
||||
// Try support
|
||||
WRAPPER_TYPES.add(WrapperType.singleValue(Try.class));
|
||||
EXECUTION_ADAPTER.put(Try.class, it -> Try.of(it::get));
|
||||
|
||||
ALLOWED_PAGEABLE_TYPES.add(Seq.class);
|
||||
}
|
||||
|
||||
if (VAVR_PRESENT) {
|
||||
|
||||
WRAPPER_TYPES.add(NullableWrapperToVavrOptionConverter.getWrapperType());
|
||||
@@ -265,11 +246,6 @@ public abstract class QueryExecutionConverters {
|
||||
conversionService.addConverter(new NullableWrapperToScalaOptionConverter(conversionService));
|
||||
}
|
||||
|
||||
if (JAVASLANG_PRESENT) {
|
||||
conversionService.addConverter(new NullableWrapperToJavaslangOptionConverter(conversionService));
|
||||
conversionService.addConverter(JavaslangCollections.FromJavaConverter.INSTANCE);
|
||||
}
|
||||
|
||||
if (VAVR_PRESENT) {
|
||||
conversionService.addConverter(new NullableWrapperToVavrOptionConverter(conversionService));
|
||||
conversionService.addConverter(VavrCollections.FromJavaConverter.INSTANCE);
|
||||
@@ -559,37 +535,6 @@ public abstract class QueryExecutionConverters {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converter to convert from {@link NullableWrapper} into JavaSlang's {@link javaslang.control.Option}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 1.13
|
||||
*/
|
||||
private static class NullableWrapperToJavaslangOptionConverter extends AbstractWrapperTypeConverter {
|
||||
|
||||
/**
|
||||
* Creates a new {@link NullableWrapperToJavaslangOptionConverter} using the given {@link ConversionService}.
|
||||
*
|
||||
* @param conversionService must not be {@literal null}.
|
||||
*/
|
||||
public NullableWrapperToJavaslangOptionConverter(ConversionService conversionService) {
|
||||
super(conversionService, javaslang.control.Option.none(), Collections.singleton(javaslang.control.Option.class));
|
||||
}
|
||||
|
||||
public static WrapperType getWrapperType() {
|
||||
return WrapperType.singleValue(javaslang.control.Option.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.util.QueryExecutionConverters.AbstractWrapperTypeConverter#wrap(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Object wrap(Object source) {
|
||||
return javaslang.control.Option.of(source);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converter to convert from {@link NullableWrapper} into JavaSlang's {@link io.vavr.control.Option}.
|
||||
*
|
||||
@@ -698,37 +643,6 @@ public abstract class QueryExecutionConverters {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converter to unwrap Javaslang {@link javaslang.control.Option} instances.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @since 1.13
|
||||
*/
|
||||
private enum JavaslangOptionUnwrapper implements Converter<Object, Object> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(Object source) {
|
||||
|
||||
if (source instanceof javaslang.control.Option) {
|
||||
return ((javaslang.control.Option<Object>) source).getOrElse(() -> null);
|
||||
}
|
||||
|
||||
if (source instanceof Traversable) {
|
||||
return JavaslangCollections.ToJavaConverter.INSTANCE.convert(source);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converter to unwrap Vavr {@link io.vavr.control.Option} instances.
|
||||
*
|
||||
|
||||
@@ -28,16 +28,7 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -67,7 +58,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
mapTypes.add(Map.class);
|
||||
|
||||
try {
|
||||
mapTypes.add(ClassUtils.forName("javaslang.collection.Map", classLoader));
|
||||
mapTypes.add(ClassUtils.forName("io.vavr.collection.Map", classLoader));
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
|
||||
MAP_TYPES = mapTypes.toArray(new Class[0]);
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.springframework.data.repository.core.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import io.vavr.control.Option;
|
||||
import io.vavr.control.Try;
|
||||
import javaslang.control.Option;
|
||||
import lombok.Value;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import javaslang.collection.Seq;
|
||||
import javaslang.control.Option;
|
||||
import io.vavr.collection.Seq;
|
||||
import io.vavr.control.Option;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -18,12 +18,9 @@ package org.springframework.data.repository.util;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.repository.util.QueryExecutionConverters.*;
|
||||
|
||||
import javaslang.collection.LinkedHashMap;
|
||||
import javaslang.collection.LinkedHashSet;
|
||||
import javaslang.collection.Seq;
|
||||
import javaslang.collection.Traversable;
|
||||
import javaslang.control.Try;
|
||||
import javaslang.control.Try.Failure;
|
||||
import io.vavr.collection.Seq;
|
||||
import io.vavr.control.Try;
|
||||
import io.vavr.control.Try.Failure;
|
||||
import lombok.Value;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -82,7 +79,7 @@ public class QueryExecutionConvertersUnitTests {
|
||||
assertThat(QueryExecutionConverters.supports(Future.class)).isTrue();
|
||||
assertThat(QueryExecutionConverters.supports(ListenableFuture.class)).isTrue();
|
||||
assertThat(QueryExecutionConverters.supports(Option.class)).isTrue();
|
||||
assertThat(QueryExecutionConverters.supports(javaslang.control.Option.class)).isTrue();
|
||||
assertThat(QueryExecutionConverters.supports(io.vavr.control.Option.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-836
|
||||
@@ -189,86 +186,6 @@ public class QueryExecutionConvertersUnitTests {
|
||||
assertThat(QueryExecutionConverters.unwrap(Option.empty())).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-937
|
||||
@SuppressWarnings("unchecked")
|
||||
public void turnsNullIntoJavaslangOption() {
|
||||
assertThat(conversionService.convert(new NullableWrapper(null), javaslang.control.Option.class))
|
||||
.isEqualTo(javaslang.control.Option.none());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-937
|
||||
public void wrapsValueIntoJavaslangOption() {
|
||||
|
||||
javaslang.control.Option<?> result = conversionService.convert(new NullableWrapper("string"),
|
||||
javaslang.control.Option.class);
|
||||
|
||||
assertThat(result.isEmpty()).isFalse();
|
||||
assertThat(result.get()).isEqualTo("string");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-937
|
||||
public void unwrapsEmptyJavaslangOption() {
|
||||
assertThat(QueryExecutionConverters.unwrap(javaslang.control.Option.none())).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-937
|
||||
public void unwrapsJavaslangOption() {
|
||||
assertThat(QueryExecutionConverters.unwrap(javaslang.control.Option.of("string"))).isEqualTo("string");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
public void conversListToJavaslang() {
|
||||
|
||||
assertThat(conversionService.canConvert(List.class, javaslang.collection.Traversable.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(List.class, javaslang.collection.List.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(List.class, javaslang.collection.Set.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(List.class, javaslang.collection.Map.class)).isFalse();
|
||||
|
||||
List<Integer> integers = Arrays.asList(1, 2, 3);
|
||||
|
||||
Traversable<?> result = conversionService.convert(integers, Traversable.class);
|
||||
|
||||
assertThat(result).isInstanceOf(javaslang.collection.List.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
public void convertsSetToJavaslang() {
|
||||
|
||||
assertThat(conversionService.canConvert(Set.class, javaslang.collection.Traversable.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(Set.class, javaslang.collection.Set.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(Set.class, javaslang.collection.List.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(Set.class, javaslang.collection.Map.class)).isFalse();
|
||||
|
||||
Set<Integer> integers = Collections.singleton(1);
|
||||
|
||||
Traversable<?> result = conversionService.convert(integers, Traversable.class);
|
||||
|
||||
assertThat(result).isInstanceOf(javaslang.collection.Set.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
public void convertsMapToJavaslang() {
|
||||
|
||||
assertThat(conversionService.canConvert(Map.class, javaslang.collection.Traversable.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(Map.class, javaslang.collection.Map.class)).isTrue();
|
||||
assertThat(conversionService.canConvert(Map.class, javaslang.collection.Set.class)).isFalse();
|
||||
assertThat(conversionService.canConvert(Map.class, javaslang.collection.List.class)).isFalse();
|
||||
|
||||
Map<String, String> map = Collections.singletonMap("key", "value");
|
||||
|
||||
Traversable<?> result = conversionService.convert(map, Traversable.class);
|
||||
|
||||
assertThat(result).isInstanceOf(javaslang.collection.Map.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
public void unwrapsJavaslangCollectionsToJavaOnes() {
|
||||
|
||||
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
|
||||
public void registersAllowedPageabletypes() {
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.util;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.util.ClassTypeInformation.from;
|
||||
|
||||
import javaslang.collection.Traversable;
|
||||
import io.vavr.collection.Traversable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Calendar;
|
||||
@@ -382,7 +382,7 @@ public class ClassTypeInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
public void detectsJavaslangTraversableComponentType() {
|
||||
public void detectsVavrTraversableComponentType() {
|
||||
|
||||
ClassTypeInformation<SampleTraversable> information = ClassTypeInformation.from(SampleTraversable.class);
|
||||
|
||||
@@ -390,7 +390,7 @@ public class ClassTypeInformationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-940
|
||||
public void detectsJavaslangMapComponentAndValueType() {
|
||||
public void detectsVavrMapComponentAndValueType() {
|
||||
|
||||
ClassTypeInformation<SampleMap> information = ClassTypeInformation.from(SampleMap.class);
|
||||
|
||||
@@ -611,7 +611,7 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
static interface SampleTraversable extends Traversable<Integer> {}
|
||||
|
||||
static interface SampleMap extends javaslang.collection.Map<String, Integer> {}
|
||||
static interface SampleMap extends io.vavr.collection.Map<String, Integer> {}
|
||||
|
||||
// DATACMNS-1138
|
||||
|
||||
|
||||
Reference in New Issue
Block a user