Skip to content

Commit 871b1b6

Browse files
Update nullability annotations and javadoc.
Reflect allowed null arguments in both documentation as well as supporting annotations. See: #3036
1 parent 47ded39 commit 871b1b6

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ default Specification<T> or(@Nullable Specification<T> other) {
9696
* {@link Root} and {@link CriteriaQuery}.
9797
*
9898
* @param root must not be {@literal null}.
99-
* @param query must not be {@literal null}.
99+
* @param query can be {@literal null} to allow overrides that accept {@link jakarta.persistence.criteria.CriteriaDelete} which is an {@link jakarta.persistence.criteria.AbstractQuery} but no {@link CriteriaQuery}.
100100
* @param criteriaBuilder must not be {@literal null}.
101101
* @return a {@link Predicate}, may be {@literal null}.
102102
*/
103103
@Nullable
104-
Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);
104+
Predicate toPredicate(Root<T> root, @Nullable CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);
105105

106106
/**
107107
* Applies an AND operation to all the given {@link Specification}s.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static <T> Specification<T> composed(@Nullable Specification<T> lhs, @Nullable S
5757
}
5858

5959
@Nullable
60-
private static <T> Predicate toPredicate(@Nullable Specification<T> specification, Root<T> root, CriteriaQuery<?> query,
60+
private static <T> Predicate toPredicate(@Nullable Specification<T> specification, Root<T> root, @Nullable CriteriaQuery<?> query,
6161
CriteriaBuilder builder) {
6262
return specification == null ? null : specification.toPredicate(root, query, builder);
6363
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.data.domain.Sort;
2929
import org.springframework.data.jpa.domain.Specification;
3030
import org.springframework.data.repository.query.FluentQuery;
31+
import org.springframework.lang.Nullable;
3132

3233
/**
3334
* Interface to allow execution of {@link Specification}s based on the JPA criteria API.
@@ -50,37 +51,45 @@ public interface JpaSpecificationExecutor<T> {
5051

5152
/**
5253
* Returns all entities matching the given {@link Specification}.
54+
* <p>
55+
* If no {@link Specification} is given all entities matching {@code <T>} will be selected.
5356
*
54-
* @param spec must not be {@literal null}.
57+
* @param spec can be {@literal null}.
5558
* @return never {@literal null}.
5659
*/
57-
List<T> findAll(Specification<T> spec);
60+
List<T> findAll(@Nullable Specification<T> spec);
5861

5962
/**
6063
* Returns a {@link Page} of entities matching the given {@link Specification}.
64+
* <p>
65+
* If no {@link Specification} is given all entities matching {@code <T>} will be selected.
6166
*
62-
* @param spec must not be {@literal null}.
67+
* @param spec can be {@literal null}.
6368
* @param pageable must not be {@literal null}.
6469
* @return never {@literal null}.
6570
*/
66-
Page<T> findAll(Specification<T> spec, Pageable pageable);
71+
Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable);
6772

6873
/**
6974
* Returns all entities matching the given {@link Specification} and {@link Sort}.
75+
* <p>
76+
* If no {@link Specification} is given all entities matching {@code <T>} will be selected.
7077
*
71-
* @param spec must not be {@literal null}.
78+
* @param spec can be {@literal null}.
7279
* @param sort must not be {@literal null}.
7380
* @return never {@literal null}.
7481
*/
75-
List<T> findAll(Specification<T> spec, Sort sort);
82+
List<T> findAll(@Nullable Specification<T> spec, Sort sort);
7683

7784
/**
7885
* Returns the number of instances that the given {@link Specification} will return.
86+
* <p>
87+
* If no {@link Specification} is given all entities matching {@code <T>} will be counted.
7988
*
8089
* @param spec the {@link Specification} to count instances for, must not be {@literal null}.
8190
* @return the number of instances.
8291
*/
83-
long count(Specification<T> spec);
92+
long count(@Nullable Specification<T> spec);
8493

8594
/**
8695
* Checks whether the data store contains elements that match the given {@link Specification}.
@@ -101,12 +110,14 @@ public interface JpaSpecificationExecutor<T> {
101110
* {@link Specification#toPredicate(Root, CriteriaQuery, CriteriaBuilder)} will be {@literal null} because
102111
* {@link jakarta.persistence.criteria.CriteriaBuilder#createCriteriaDelete(Class)} does not implement
103112
* {@code CriteriaQuery}.
113+
* <p>
114+
* If no {@link Specification} is given all entities matching {@code <T>} will be deleted.
104115
*
105-
* @param spec the {@link Specification} to use for the existence check, must not be {@literal null}.
116+
* @param spec the {@link Specification} to use for the existence check, can not be {@literal null}.
106117
* @return the number of entities deleted.
107118
* @since 3.0
108119
*/
109-
long delete(Specification<T> spec);
120+
long delete(@Nullable Specification<T> spec);
110121

111122
/**
112123
* Returns entities matching the given {@link Specification} applying the {@code queryFunction} that defines the query

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public Page<T> findAll(Pageable pageable) {
431431
return new PageImpl<>(findAll());
432432
}
433433

434-
return findAll((root, query, criteriaBuilder) -> null, pageable);
434+
return findAll((Specification<T>) null, pageable);
435435
}
436436

437437
@Override
@@ -450,15 +450,15 @@ public List<T> findAll(Specification<T> spec) {
450450
}
451451

452452
@Override
453-
public Page<T> findAll(Specification<T> spec, Pageable pageable) {
453+
public Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable) {
454454

455455
TypedQuery<T> query = getQuery(spec, pageable);
456456
return pageable.isUnpaged() ? new PageImpl<>(query.getResultList())
457457
: readPage(query, getDomainClass(), pageable, spec);
458458
}
459459

460460
@Override
461-
public List<T> findAll(Specification<T> spec, Sort sort) {
461+
public List<T> findAll(@Nullable Specification<T> spec, Sort sort) {
462462
return getQuery(spec, sort).getResultList();
463463
}
464464

@@ -477,7 +477,7 @@ public boolean exists(Specification<T> spec) {
477477

478478
@Override
479479
@Transactional
480-
public long delete(Specification<T> spec) {
480+
public long delete(@Nullable Specification<T> spec) {
481481

482482
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
483483
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());

0 commit comments

Comments
 (0)