File tree Expand file tree Collapse file tree 2 files changed +14
-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 +14
-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 {@code where(null)}, 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 {
@@ -59,7 +67,7 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
59
67
: (root , query , builder ) -> {
60
68
61
69
Predicate predicate = spec .toPredicate (root , query , builder );
62
- return predicate != null ? builder .not (predicate ) : builder . disjunction () ;
70
+ return predicate != null ? builder .not (predicate ) : null ;
63
71
};
64
72
}
65
73
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 ("removal" )
50
51
@ ExtendWith (MockitoExtension .class )
@@ -213,15 +214,13 @@ void orCombinesSpecificationsInOrder() {
213
214
verify (builder ).or (firstPredicate , secondPredicate );
214
215
}
215
216
216
- @ Test // GH-3849
217
+ @ Test // GH-3849, GH-4023
217
218
void notWithNullPredicate () {
218
219
219
- when ( builder . disjunction ()). thenReturn ( mock ( Predicate . class ));
220
+ Specification < Object > notSpec = Specification . not ( Specification . unrestricted ( ));
220
221
221
- Specification <Object > notSpec = Specification .not ((r , q , cb ) -> null );
222
-
223
- assertThat (notSpec .toPredicate (root , query , builder )).isNotNull ();
224
- verify (builder ).disjunction ();
222
+ assertThat (notSpec .toPredicate (root , query , builder )).isNull ();
223
+ verifyNoInteractions (builder );
225
224
}
226
225
227
226
static class SerializableSpecification implements Serializable , Specification <Object > {
You can’t perform that action at this time.
0 commit comments