Skip to content

Commit 42dadd8

Browse files
committed
Use CompletableFuture instead of deprecated ListenableFuture.
Closes #2669
1 parent 7e1712a commit 42dadd8

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

src/main/asciidoc/repositories.adoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,9 @@ Future<User> findByFirstname(String firstname); <1>
873873
874874
@Async
875875
CompletableFuture<User> findOneByFirstname(String firstname); <2>
876-
877-
@Async
878-
ListenableFuture<User> findOneByLastname(String lastname); <3>
879876
----
880877
<1> Use `java.util.concurrent.Future` as the return type.
881878
<2> Use a Java 8 `java.util.concurrent.CompletableFuture` as the return type.
882-
<3> Use a `org.springframework.util.concurrent.ListenableFuture` as the return type.
883879
====
884880

885881
[[repositories.create-instances]]

src/main/asciidoc/repository-query-return-types-reference.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Some store modules may define their own result wrapper types.
3030
|Vavr `Seq`, `List`, `Map`, `Set`|Vavr collection types. See <<repositories.collections-and-iterables.vavr>> for details.
3131
|`Future<T>`|A `Future`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
3232
|`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.
33-
|`ListenableFuture`|A `org.springframework.util.concurrent.ListenableFuture`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
3433
|`Slice<T>`|A sized chunk of data with an indication of whether there is more data available. Requires a `Pageable` method parameter.
3534
|`Page<T>`|A `Slice` with additional information, such as the total number of results. Requires a `Pageable` method parameter.
3635
|`GeoResult<T>`|A result entry with additional information, such as the distance to a reference location.

src/main/java/org/springframework/data/repository/util/QueryExecutionConverters.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.repository.util;
1717

18-
import java.util.Arrays;
1918
import java.util.Collection;
2019
import java.util.Collections;
2120
import java.util.HashMap;
@@ -45,7 +44,6 @@
4544
import org.springframework.data.util.StreamUtils;
4645
import org.springframework.data.util.Streamable;
4746
import org.springframework.data.util.TypeInformation;
48-
import org.springframework.lang.NonNull;
4947
import org.springframework.lang.Nullable;
5048
import org.springframework.scheduling.annotation.AsyncResult;
5149
import org.springframework.util.Assert;
@@ -92,7 +90,9 @@ public abstract class QueryExecutionConverters {
9290
WRAPPER_TYPES.add(WrapperType.singleValue(Future.class));
9391
UNWRAPPER_TYPES.add(WrapperType.singleValue(Future.class));
9492
WRAPPER_TYPES.add(WrapperType.singleValue(ListenableFuture.class));
93+
WRAPPER_TYPES.add(WrapperType.singleValue(CompletableFuture.class));
9594
UNWRAPPER_TYPES.add(WrapperType.singleValue(ListenableFuture.class));
95+
UNWRAPPER_TYPES.add(WrapperType.singleValue(CompletableFuture.class));
9696

9797
ALLOWED_PAGEABLE_TYPES.add(Slice.class);
9898
ALLOWED_PAGEABLE_TYPES.add(Page.class);
@@ -102,9 +102,7 @@ public abstract class QueryExecutionConverters {
102102

103103
UNWRAPPERS.addAll(CustomCollections.getUnwrappers());
104104

105-
CustomCollections.getCustomTypes().stream()
106-
.map(WrapperType::multiValue)
107-
.forEach(WRAPPER_TYPES::add);
105+
CustomCollections.getCustomTypes().stream().map(WrapperType::multiValue).forEach(WRAPPER_TYPES::add);
108106

109107
CustomCollections.getPaginationReturnTypes().forEach(ALLOWED_PAGEABLE_TYPES::add);
110108

@@ -302,8 +300,7 @@ private static abstract class AbstractWrapperTypeConverter implements GenericCon
302300
this.wrapperTypes = Collections.singleton(nullValue.getClass());
303301
}
304302

305-
AbstractWrapperTypeConverter(Object nullValue,
306-
Iterable<Class<?>> wrapperTypes) {
303+
AbstractWrapperTypeConverter(Object nullValue, Iterable<Class<?>> wrapperTypes) {
307304
this.nullValue = nullValue;
308305
this.wrapperTypes = wrapperTypes;
309306
}
@@ -345,13 +342,14 @@ public final Object convert(@Nullable Object source, TypeDescriptor sourceType,
345342
*
346343
* @author Oliver Gierke
347344
*/
345+
@Deprecated(since = "3.0")
348346
private static class NullableWrapperToFutureConverter extends AbstractWrapperTypeConverter {
349347

350348
/**
351349
* Creates a new {@link NullableWrapperToFutureConverter} using the given {@link ConversionService}.
352350
*/
353351
NullableWrapperToFutureConverter() {
354-
super(new AsyncResult<>(null), Arrays.asList(Future.class, ListenableFuture.class));
352+
super(new AsyncResult<>(null), List.of(ListenableFuture.class));
355353
}
356354

357355
@Override
@@ -371,7 +369,7 @@ private static class NullableWrapperToCompletableFutureConverter extends Abstrac
371369
* Creates a new {@link NullableWrapperToCompletableFutureConverter} using the given {@link ConversionService}.
372370
*/
373371
NullableWrapperToCompletableFutureConverter() {
374-
super(CompletableFuture.completedFuture(null));
372+
super(CompletableFuture.completedFuture(null), List.of(Future.class));
375373
}
376374

377375
@Override

src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void registersWrapperTypes() {
7575
assertThat(QueryExecutionConverters.supports(java.util.Optional.class)).isTrue();
7676
assertThat(QueryExecutionConverters.supports(Future.class)).isTrue();
7777
assertThat(QueryExecutionConverters.supports(ListenableFuture.class)).isTrue();
78+
assertThat(QueryExecutionConverters.supports(CompletableFuture.class)).isTrue();
7879
assertThat(QueryExecutionConverters.supports(Option.class)).isTrue();
7980
assertThat(QueryExecutionConverters.supports(io.vavr.control.Option.class)).isTrue();
8081
}
@@ -85,6 +86,7 @@ void registersUnwrapperTypes() {
8586
assertThat(QueryExecutionConverters.supportsUnwrapping(Optional.class)).isTrue();
8687
assertThat(QueryExecutionConverters.supportsUnwrapping(java.util.Optional.class)).isTrue();
8788
assertThat(QueryExecutionConverters.supportsUnwrapping(Future.class)).isTrue();
89+
assertThat(QueryExecutionConverters.supportsUnwrapping(CompletableFuture.class)).isTrue();
8890
assertThat(QueryExecutionConverters.supportsUnwrapping(ListenableFuture.class)).isTrue();
8991
assertThat(QueryExecutionConverters.supportsUnwrapping(Option.class)).isTrue();
9092
}

src/test/java/org/springframework/data/util/NullableWrapperConvertersUnitTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import scala.Option;
2121

22+
import java.util.concurrent.CompletableFuture;
2223
import java.util.concurrent.Future;
2324

2425
import org.junit.jupiter.api.BeforeEach;
@@ -54,6 +55,7 @@ void registersWrapperTypes() {
5455
assertThat(NullableWrapperConverters.supports(java.util.Optional.class)).isTrue();
5556
assertThat(NullableWrapperConverters.supports(Future.class)).isFalse();
5657
assertThat(NullableWrapperConverters.supports(ListenableFuture.class)).isFalse();
58+
assertThat(NullableWrapperConverters.supports(CompletableFuture.class)).isFalse();
5759
assertThat(NullableWrapperConverters.supports(Option.class)).isTrue();
5860
assertThat(NullableWrapperConverters.supports(io.vavr.control.Option.class)).isTrue();
5961
}
@@ -65,6 +67,7 @@ void registersUnwrapperTypes() {
6567
assertThat(NullableWrapperConverters.supportsUnwrapping(java.util.Optional.class)).isTrue();
6668
assertThat(NullableWrapperConverters.supportsUnwrapping(Future.class)).isFalse();
6769
assertThat(NullableWrapperConverters.supportsUnwrapping(ListenableFuture.class)).isFalse();
70+
assertThat(NullableWrapperConverters.supportsUnwrapping(CompletableFuture.class)).isFalse();
6871
assertThat(NullableWrapperConverters.supportsUnwrapping(Option.class)).isTrue();
6972
}
7073

0 commit comments

Comments
 (0)