16
16
package org .springframework .data .jpa .domain ;
17
17
18
18
import jakarta .persistence .criteria .CriteriaBuilder ;
19
+ import jakarta .persistence .criteria .From ;
19
20
import jakarta .persistence .criteria .Predicate ;
20
- import jakarta .persistence .criteria .Root ;
21
21
22
22
import java .io .Serializable ;
23
23
import java .util .Arrays ;
34
34
* <p>
35
35
* Specifications can be composed into higher order functions from other specifications using
36
36
* {@link #and(PredicateSpecification)}, {@link #or(PredicateSpecification)} or factory methods such as
37
- * {@link #allOf(Iterable)}.
37
+ * {@link #allOf(Iterable)} with reduced type interference of the query source type.
38
+ * <p>
39
+ * PredicateSpecifications are building blocks for composition and do not express their type opinion towards a specific
40
+ * entity source or join source type for improved reuse.
38
41
* <p>
39
42
* Composition considers whether one or more specifications contribute to the overall predicate by returning a
40
43
* {@link Predicate} or {@literal null}. Specifications returning {@literal null}, such as {@link #unrestricted()}, are
41
44
* considered to not contribute to the overall predicate, and their result is not considered in the final predicate.
42
45
*
46
+ * @param <T> the type of the {@link From From target} to which the specification is applied.
43
47
* @author Mark Paluch
44
48
* @author Peter Aisher
45
49
* @since 4.0
@@ -57,17 +61,17 @@ public interface PredicateSpecification<T> extends Serializable {
57
61
* not(unrestricted()) // equivalent to `unrestricted()`
58
62
* </pre>
59
63
*
60
- * @param <T> the type of the {@link Root } the resulting {@literal PredicateSpecification} operates on.
64
+ * @param <T> the type of the {@link From } the resulting {@literal PredicateSpecification} operates on.
61
65
* @return guaranteed to be not {@literal null}.
62
66
*/
63
67
static <T > PredicateSpecification <T > unrestricted () {
64
- return (root , builder ) -> null ;
68
+ return (from , builder ) -> null ;
65
69
}
66
70
67
71
/**
68
72
* Simple static factory method to add some syntactic sugar around a {@literal PredicateSpecification}.
69
73
*
70
- * @param <T> the type of the {@link Root } the resulting {@literal PredicateSpecification} operates on.
74
+ * @param <T> the type of the {@link From } the resulting {@literal PredicateSpecification} operates on.
71
75
* @param spec must not be {@literal null}.
72
76
* @return guaranteed to be not {@literal null}.
73
77
* @since 2.0
@@ -112,17 +116,17 @@ default PredicateSpecification<T> or(PredicateSpecification<T> other) {
112
116
/**
113
117
* Negates the given {@link PredicateSpecification}.
114
118
*
115
- * @param <T> the type of the {@link Root } the resulting {@literal PredicateSpecification} operates on.
119
+ * @param <T> the type of the {@link From } the resulting {@literal PredicateSpecification} operates on.
116
120
* @param spec can be {@literal null}.
117
121
* @return guaranteed to be not {@literal null}.
118
122
*/
119
123
static <T > PredicateSpecification <T > not (PredicateSpecification <T > spec ) {
120
124
121
125
Assert .notNull (spec , "Specification must not be null" );
122
126
123
- return (root , builder ) -> {
127
+ return (from , builder ) -> {
124
128
125
- Predicate predicate = spec .toPredicate (root , builder );
129
+ Predicate predicate = spec .toPredicate (from , builder );
126
130
return predicate != null ? builder .not (predicate ) : null ;
127
131
};
128
132
}
@@ -187,13 +191,13 @@ static <T> PredicateSpecification<T> anyOf(Iterable<PredicateSpecification<T>> s
187
191
188
192
/**
189
193
* Creates a WHERE clause for a query of the referenced entity in form of a {@link Predicate} for the given
190
- * {@link Root } and {@link CriteriaBuilder}.
194
+ * {@link From } and {@link CriteriaBuilder}.
191
195
*
192
- * @param root must not be {@literal null}.
196
+ * @param from must not be {@literal null}.
193
197
* @param criteriaBuilder must not be {@literal null}.
194
198
* @return a {@link Predicate}, may be {@literal null}.
195
199
*/
196
200
@ Nullable
197
- Predicate toPredicate (Root < T > root , CriteriaBuilder criteriaBuilder );
201
+ Predicate toPredicate (From <?, T > from , CriteriaBuilder criteriaBuilder );
198
202
199
203
}
0 commit comments