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 2929
3030/**
3131 * 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.
3239 *
3340 * @author Oliver Gierke
3441 * @author Thomas Darimont
3845 * @author Jens Schauder
3946 * @author Daniel Shuy
4047 * @author Sergey Rukin
48+ * @author Peter Aisher
4149 */
4250@ FunctionalInterface
4351public interface Specification <T > extends Serializable {
@@ -59,7 +67,7 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
5967 : (root , query , builder ) -> {
6068
6169 Predicate predicate = spec .toPredicate (root , query , builder );
62- return predicate != null ? builder .not (predicate ) : builder . disjunction () ;
70+ return predicate != null ? builder .not (predicate ) : null ;
6371 };
6472 }
6573
Original file line number Diff line number Diff line change 4545 * @author Jens Schauder
4646 * @author Mark Paluch
4747 * @author Daniel Shuy
48+ * @author Peter Aisher
4849 */
4950@ SuppressWarnings ("removal" )
5051@ ExtendWith (MockitoExtension .class )
@@ -213,15 +214,13 @@ void orCombinesSpecificationsInOrder() {
213214 verify (builder ).or (firstPredicate , secondPredicate );
214215 }
215216
216- @ Test // GH-3849
217+ @ Test // GH-3849, GH-4023
217218 void notWithNullPredicate () {
218219
219- when ( builder . disjunction ()). thenReturn ( mock ( Predicate . class ));
220+ Specification < Object > notSpec = Specification . not ( Specification . unrestricted ( ));
220221
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 );
225224 }
226225
227226 static class SerializableSpecification implements Serializable , Specification <Object > {
You can’t perform that action at this time.
0 commit comments