Skip to content

Commit 5ad3392

Browse files
committed
Backport Specification.unrestricted() to 3.5.x.
Introducing a replacement method for the deprecated `where(…)` method. Closes #3942
1 parent 0e39197 commit 5ad3392

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
6464
};
6565
}
6666

67+
/**
68+
* Simple static factory method to create a specification matching all objects.
69+
*
70+
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
71+
* @return guaranteed to be not {@literal null}.
72+
* @since 3.5.2
73+
*/
74+
static <T> Specification<T> unrestricted() {
75+
return (root, query, builder) -> null;
76+
}
77+
6778
/**
6879
* Simple static factory method to add some syntactic sugar around a {@link Specification}.
6980
*
@@ -72,11 +83,12 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
7283
* @param spec can be {@literal null}.
7384
* @return guaranteed to be not {@literal null}.
7485
* @since 2.0
75-
* @deprecated since 3.5, to be removed with 4.0 as we no longer want to support {@literal null} specifications.
86+
* @deprecated since 3.5, to be removed with 4.0 as we no longer want to support {@literal null} specifications. Use
87+
* {@link #unrestricted()} instead.
7688
*/
7789
@Deprecated(since = "3.5.0", forRemoval = true)
7890
static <T> Specification<T> where(@Nullable Specification<T> spec) {
79-
return spec == null ? (root, query, builder) -> null : spec;
91+
return spec == null ? unrestricted() : spec;
8092
}
8193

8294
/**

0 commit comments

Comments
 (0)