Skip to content

Commit 108cb48

Browse files
mp911dechristophstrobl
authored andcommitted
Polishing.
Revise nullability requirements around non-nullable specifications. Original Pull Request: #3578
1 parent 804af4b commit 108cb48

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

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

+19-13
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluent
498498
return doFindBy(spec, getDomainClass(), queryFunction);
499499
}
500500

501+
@SuppressWarnings("unchecked")
501502
private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
502503
Function<FetchableFluentQuery<S>, R> queryFunction) {
503504

@@ -586,6 +587,7 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
586587
}
587588

588589
@Override
590+
@SuppressWarnings("unchecked")
589591
public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQuery<S>, R> queryFunction) {
590592

591593
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
@@ -608,7 +610,7 @@ public long count() {
608610
}
609611

610612
@Override
611-
public long count(@Nullable Specification<T> spec) {
613+
public long count(Specification<T> spec) {
612614
return executeCountQuery(getCountQuery(spec, getDomainClass()));
613615
}
614616

@@ -677,7 +679,7 @@ public void flush() {
677679
* @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead
678680
*/
679681
@Deprecated
680-
protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Specification<T> spec) {
682+
protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, Specification<T> spec) {
681683
return readPage(query, getDomainClass(), pageable, spec);
682684
}
683685

@@ -687,11 +689,13 @@ protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Spe
687689
*
688690
* @param query must not be {@literal null}.
689691
* @param domainClass must not be {@literal null}.
690-
* @param spec can be {@literal null}.
692+
* @param spec must not be {@literal null}.
691693
* @param pageable can be {@literal null}.
692694
*/
693695
protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> domainClass, Pageable pageable,
694-
@Nullable Specification<S> spec) {
696+
Specification<S> spec) {
697+
698+
Assert.notNull(spec, "Specification must not be null");
695699

696700
if (pageable.isPaged()) {
697701
query.setFirstResult(PageableUtils.getOffsetAsInteger(pageable));
@@ -705,22 +709,22 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
705709
/**
706710
* Creates a new {@link TypedQuery} from the given {@link Specification}.
707711
*
708-
* @param spec can be {@literal null}.
712+
* @param spec must not be {@literal null}.
709713
* @param pageable must not be {@literal null}.
710714
*/
711-
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {
715+
protected TypedQuery<T> getQuery(Specification<T> spec, Pageable pageable) {
712716

713717
return getQuery(spec, getDomainClass(), pageable.getSort());
714718
}
715719

716720
/**
717721
* Creates a new {@link TypedQuery} from the given {@link Specification}.
718722
*
719-
* @param spec can be {@literal null}.
723+
* @param spec must not be {@literal null}.
720724
* @param domainClass must not be {@literal null}.
721725
* @param pageable must not be {@literal null}.
722726
*/
723-
protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass,
727+
protected <S extends T> TypedQuery<S> getQuery(Specification<S> spec, Class<S> domainClass,
724728
Pageable pageable) {
725729

726730
return getQuery(spec, domainClass, pageable.getSort());
@@ -799,21 +803,23 @@ protected <S> Query getDelete(DeleteSpecification<S> spec, Class<S> domainClass)
799803
/**
800804
* Creates a new count query for the given {@link Specification}.
801805
*
802-
* @param spec can be {@literal null}.
806+
* @param spec must not be {@literal null}.
803807
* @deprecated override {@link #getCountQuery(Specification, Class)} instead
804808
*/
805809
@Deprecated
806-
protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) {
810+
protected TypedQuery<Long> getCountQuery(Specification<T> spec) {
807811
return getCountQuery(spec, getDomainClass());
808812
}
809813

810814
/**
811815
* Creates a new count query for the given {@link Specification}.
812816
*
813-
* @param spec can be {@literal null}.
817+
* @param spec must not be {@literal null}.
814818
* @param domainClass must not be {@literal null}.
815819
*/
816-
protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S> spec, Class<S> domainClass) {
820+
protected <S extends T> TypedQuery<Long> getCountQuery(Specification<S> spec, Class<S> domainClass) {
821+
822+
Assert.notNull(spec, "Specification must not be null");
817823

818824
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
819825
CriteriaQuery<Long> query = builder.createQuery(Long.class);
@@ -963,7 +969,7 @@ private Map<String, Object> getHints() {
963969
private void applyComment(CrudMethodMetadata metadata, BiConsumer<String, Object> consumer) {
964970

965971
if (metadata.getComment() != null && provider.getCommentHintKey() != null) {
966-
consumer.accept(provider.getCommentHintKey(), provider.getCommentHintValue(this.metadata.getComment()));
972+
consumer.accept(provider.getCommentHintKey(), provider.getCommentHintValue(metadata.getComment()));
967973
}
968974
}
969975

0 commit comments

Comments
 (0)