Skip to content

Commit ea95a61

Browse files
r-gruberRobert Gruber
authored andcommitted
Backport Specification.unrestricted() from main branch.
This would allow 3.5 users to rework their code ahead of the 4.0 release. 'where(null)' was deprecated and should be replaced with unrestricted()
1 parent 0e39197 commit ea95a61

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public interface Specification<T> extends Serializable {
4444

4545
@Serial long serialVersionUID = 1L;
4646

47+
/**
48+
* Simple static factory method to create a specification matching all objects.
49+
*
50+
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
51+
* @return guaranteed to be not {@literal null}.
52+
*/
53+
static <T> Specification<T> unrestricted() {
54+
return (root, query, builder) -> null;
55+
}
56+
4757
/**
4858
* Negates the given {@link Specification}.
4959
*
@@ -72,7 +82,8 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
7282
* @param spec can be {@literal null}.
7383
* @return guaranteed to be not {@literal null}.
7484
* @since 2.0
75-
* @deprecated since 3.5, to be removed with 4.0 as we no longer want to support {@literal null} specifications.
85+
* @deprecated since 3.5, to be removed with 4.0 as we no longer want to support {@literal null} specifications. Use
86+
* {@link #unrestricted()} instead.
7687
*/
7788
@Deprecated(since = "3.5.0", forRemoval = true)
7889
static <T> Specification<T> where(@Nullable Specification<T> spec) {

0 commit comments

Comments
 (0)