diff --git a/src/main/asciidoc/repositories-paging-sorting.adoc b/src/main/asciidoc/repositories-paging-sorting.adoc
index 9f372c652..85e5172ab 100644
--- a/src/main/asciidoc/repositories-paging-sorting.adoc
+++ b/src/main/asciidoc/repositories-paging-sorting.adoc
@@ -64,23 +64,23 @@ By default, this query is derived from the query you actually trigger.
[IMPORTANT]
====
Special parameters may only be used once within a query method. +
-Some of the special parameters described above are mutually exclusive.
+Some special parameters described above are mutually exclusive.
Please consider the following list of invalid parameter combinations.
|===
| Parameters | Example | Reason
-| `Pageable` & `Sort`
+| `Pageable` and `Sort`
| `findBy...(Pageable page, Sort sort)`
| `Pageable` already defines `Sort`
-| `Pageable` & `Limit`
+| `Pageable` and `Limit`
| `findBy...(Pageable page, Limit limit)`
| `Pageable` already defines a limit.
|===
-The `Top` keyword used to limit results can be used to along with `Pageable` whereas `Top` defines the total maximum of results, whereas the Pageable parameter may reduce this this number.
+The `Top` keyword used to limit results can be used to along with `Pageable` whereas `Top` defines the total maximum of results, whereas the Pageable parameter may reduce this number.
====
[[repositories.scrolling.guidance]]
diff --git a/src/main/asciidoc/repository-query-return-types-reference.adoc b/src/main/asciidoc/repository-query-return-types-reference.adoc
index a64027e21..7a33e30d8 100644
--- a/src/main/asciidoc/repository-query-return-types-reference.adoc
+++ b/src/main/asciidoc/repository-query-return-types-reference.adoc
@@ -25,7 +25,7 @@ Some store modules may define their own result wrapper types.
|`Optional`|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`|Either a Scala or Vavr `Option` type. Semantically the same behavior as Java 8's `Optional`, described earlier.
|`Stream`|A Java 8 `Stream`.
-|`Streamable`|A convenience extension of `Iterable` that directy exposes methods to stream, map and filter results, concatenate them etc.
+|`Streamable`|A convenience extension of `Iterable` that directly exposes methods to stream, map and filter results, concatenate them etc.
|Types that implement `Streamable` and take a `Streamable` constructor or factory method argument|Types that expose a constructor or `….of(…)`/`….valueOf(…)` factory method taking a `Streamable` as argument. See <> for details.
|Vavr `Seq`, `List`, `Map`, `Set`|Vavr collection types. See <> for details.
|`Future`|A `Future`. Expects a method to be annotated with `@Async` and requires Spring's asynchronous method execution capability to be enabled.
diff --git a/src/main/java/org/springframework/data/domain/Limit.java b/src/main/java/org/springframework/data/domain/Limit.java
index 9cd68cf50..48719eb0a 100644
--- a/src/main/java/org/springframework/data/domain/Limit.java
+++ b/src/main/java/org/springframework/data/domain/Limit.java
@@ -28,25 +28,12 @@ import org.springframework.util.ClassUtils;
* over using {@literal null} or {@link java.util.Optional#empty()} to indicate the absence of an actual {@link Limit}.
*
* {@link Limit} itself does not make assumptions about the actual {@link #max()} value sign. This means that a negative
- * value may be valid within a defined context. Implementations should override {@link #isUnlimited()} to fit their
- * needs and enforce restrictions if needed.
- *
+ * value may be valid within a defined context.
+ *
* @author Christoph Strobl
* @since 3.2
*/
-public sealed interface Limit permits Limited, Unlimited {
-
- /**
- * @return the max number of potential results.
- */
- int max();
-
- /**
- * @return {@literal true} if no limiting (maximum value) should be applied.
- */
- default boolean isUnlimited() {
- return Unlimited.INSTANCE.equals(this);
- }
+public sealed interface Limit permits Limited,Unlimited {
/**
* @return a {@link Limit} instance that does not define {@link #max()} and answers {@link #isUnlimited()} with
@@ -66,6 +53,23 @@ public sealed interface Limit permits Limited, Unlimited {
return new Limited(max);
}
+ /**
+ * @return the max number of potential results.
+ */
+ int max();
+
+ /**
+ * @return {@literal true} if limiting (maximum value) should be applied.
+ */
+ boolean isLimited();
+
+ /**
+ * @return {@literal true} if no limiting (maximum value) should be applied.
+ */
+ default boolean isUnlimited() {
+ return !isLimited();
+ }
+
final class Limited implements Limit {
private final int max;
@@ -79,6 +83,11 @@ public sealed interface Limit permits Limited, Unlimited {
return max;
}
+ @Override
+ public boolean isLimited() {
+ return true;
+ }
+
@Override
public boolean equals(Object obj) {
@@ -97,7 +106,7 @@ public sealed interface Limit permits Limited, Unlimited {
@Override
public int hashCode() {
- return (int) (max ^ (max >>> 32));
+ return max ^ (max >>> 32);
}
}
@@ -110,12 +119,13 @@ public sealed interface Limit permits Limited, Unlimited {
@Override
public int max() {
throw new IllegalStateException(
- "Unlimited does not define 'max'. Please check 'isUnlimited' before attempting to read 'max'");
+ "Unlimited does not define 'max'. Please check 'isLimited' before attempting to read 'max'");
}
@Override
- public boolean isUnlimited() {
- return true;
+ public boolean isLimited() {
+ return false;
}
+
}
}
diff --git a/src/main/java/org/springframework/data/domain/Pageable.java b/src/main/java/org/springframework/data/domain/Pageable.java
index 08f1dca73..2d84b3f76 100644
--- a/src/main/java/org/springframework/data/domain/Pageable.java
+++ b/src/main/java/org/springframework/data/domain/Pageable.java
@@ -173,6 +173,22 @@ public interface Pageable {
return isUnpaged() ? Optional.empty() : Optional.of(this);
}
+ /**
+ * Returns an {@link Limit} from this pageable if the page request {@link #isPaged() is paged} or
+ * {@link Limit#unlimited()} otherwise.
+ *
+ * @return
+ * @since 3.2
+ */
+ default Limit toLimit() {
+
+ if (isUnpaged()) {
+ return Limit.unlimited();
+ }
+
+ return Limit.of(getPageSize());
+ }
+
/**
* Returns an {@link OffsetScrollPosition} from this pageable if the page request {@link #isPaged() is paged}.
*
diff --git a/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java b/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java
index c009dda68..4dbdb6d2a 100644
--- a/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java
+++ b/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java
@@ -60,15 +60,11 @@ public interface ParameterAccessor extends Iterable