File tree Expand file tree Collapse file tree 2 files changed +23
-7
lines changed
main/java/org/springframework/data/jpa/domain
test/java/org/springframework/data/jpa/domain Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 29
29
30
30
/**
31
31
* Specification in the sense of Domain Driven Design.
32
+ * <p>
33
+ * Specifications can be composed into higher order functions from other specifications using
34
+ * {@link #and(Specification)}, {@link #or(Specification)} or factory methods such as {@link #allOf(Iterable)}.
35
+ * <p>
36
+ * Composition considers whether one or more specifications contribute to the overall predicate by returning a
37
+ * {@link Predicate} or {@literal null}. Specifications returning {@literal null}, such as {@link #unrestricted()}, are
38
+ * considered to not contribute to the overall predicate, and their result is not considered in the final predicate.
32
39
*
33
40
* @author Oliver Gierke
34
41
* @author Thomas Darimont
38
45
* @author Jens Schauder
39
46
* @author Daniel Shuy
40
47
* @author Sergey Rukin
48
+ * @author Peter Aisher
41
49
*/
42
50
@ FunctionalInterface
43
51
public interface Specification <T > extends Serializable {
@@ -65,7 +73,16 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
65
73
}
66
74
67
75
/**
68
- * Simple static factory method to create a specification matching all objects.
76
+ * Simple static factory method to create a specification which does not participate in matching. The specification
77
+ * returned is {@code null}-like, and is elided in all operations.
78
+ *
79
+ * <pre>
80
+ * {@code
81
+ * unrestricted().and(other) // consider only `other`
82
+ * unrestricted().or(other) // consider only `other`
83
+ * not(unrestricted()) // equivalent to `unrestricted()`
84
+ * }
85
+ * </pre>
69
86
*
70
87
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
71
88
* @return guaranteed to be not {@literal null}.
Original file line number Diff line number Diff line change 45
45
* @author Jens Schauder
46
46
* @author Mark Paluch
47
47
* @author Daniel Shuy
48
+ * @author Peter Aisher
48
49
*/
49
50
@ SuppressWarnings ({ "unchecked" , "deprecation" , "removal" })
50
51
@ ExtendWith (MockitoExtension .class )
@@ -209,15 +210,13 @@ void orCombinesSpecificationsInOrder() {
209
210
verify (builder ).or (firstPredicate , secondPredicate );
210
211
}
211
212
212
- @ Test // GH-3849
213
+ @ Test // GH-3849, GH-4023
213
214
void notWithNullPredicate () {
214
215
215
- when ( builder . disjunction ()). thenReturn ( mock ( Predicate . class ));
216
+ Specification < Object > notSpec = Specification . not ( Specification . unrestricted ( ));
216
217
217
- Specification <Object > notSpec = Specification .not ((r , q , cb ) -> null );
218
-
219
- assertThat (notSpec .toPredicate (root , query , builder )).isNotNull ();
220
- verify (builder ).disjunction ();
218
+ assertThat (notSpec .toPredicate (root , query , builder )).isNull ();
219
+ verifyNoInteractions (builder );
221
220
}
222
221
223
222
static class SerializableSpecification implements Serializable , Specification <Object > {
You can’t perform that action at this time.
0 commit comments