Browse Source

Add support for fluent queries returning a `Slice`.

Closes #1011
pull/3240/head
Mark Paluch 11 months ago
parent
commit
eefb1dc239
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 2
      src/main/antora/modules/ROOT/pages/query-by-example.adoc
  2. 32
      src/main/java/org/springframework/data/repository/query/FluentQuery.java

2
src/main/antora/modules/ROOT/pages/query-by-example.adoc

@ -207,7 +207,7 @@ You do so by invoking the various methods of the `FetchableFluentQuery` in the s @@ -207,7 +207,7 @@ You do so by invoking the various methods of the `FetchableFluentQuery` in the s
`sortBy` lets you specify an ordering for your result.
`as` lets you specify the type to which you want the result to be transformed.
`project` limits the queried attributes.
`first`, `firstValue`, `one`, `oneValue`, `all`, `page`, `stream`, `count`, and `exists` define what kind of result you get and how the query behaves when more than the expected number of results are available.
`first`, `firstValue`, `one`, `oneValue`, `all`, `page`, `slice`, `stream`, `count`, and `exists` define what kind of result you get and how the query behaves when more than the expected number of results are available.
.Use the fluent API to get the last of potentially many results, ordered by lastname.

32
src/main/java/org/springframework/data/repository/query/FluentQuery.java

@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.query;
import org.springframework.data.domain.Window;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@ -23,12 +22,15 @@ import java.util.Arrays; @@ -23,12 +22,15 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Window;
import org.springframework.lang.Nullable;
/**
@ -41,7 +43,7 @@ import org.springframework.lang.Nullable; @@ -41,7 +43,7 @@ import org.springframework.lang.Nullable;
public interface FluentQuery<T> {
/**
* Define the sort order.
* Define the sort order. Multiple calls will add {@link Sort#and(Sort) Sort} specifications.
*
* @param sort the {@link Sort} specification to sort the results by, may be {@link Sort#unsorted()}, must not be
* {@literal null}.
@ -189,6 +191,19 @@ public interface FluentQuery<T> { @@ -189,6 +191,19 @@ public interface FluentQuery<T> {
*/
Page<T> page(Pageable pageable);
/**
* Get a slice of matching elements for {@link Pageable}.
*
* @param pageable the pageable to request a sliced result, can be {@link Pageable#unpaged()}, must not be
* {@literal null}. The given {@link Pageable} will override any previously specified {@link Sort sort}.
* Any potentially specified {@link #limit(int)} will be overridden by {@link Pageable#getPageSize()}.
* @return
* @since 3.5
*/
default Slice<T> slice(Pageable pageable) {
return page(pageable);
}
/**
* Stream all matching elements.
*
@ -285,6 +300,19 @@ public interface FluentQuery<T> { @@ -285,6 +300,19 @@ public interface FluentQuery<T> {
*/
Mono<Page<T>> page(Pageable pageable);
/**
* Get a slice of matching elements for {@link Pageable}.
*
* @param pageable the pageable to request a sliced result, can be {@link Pageable#unpaged()}, must not be
* {@literal null}. The given {@link Pageable} will override any previously specified {@link Sort sort}.
* Any potentially specified {@link #limit(int)} will be overridden by {@link Pageable#getPageSize()}.
* @return
* @since 3.5
*/
default Mono<Slice<T>> slice(Pageable pageable) {
return page(pageable).map(Function.identity());
}
/**
* Get the number of matching elements.
*

Loading…
Cancel
Save