Skip to content

Commit 5fafaa4

Browse files
committed
Polishing.
Revise nullability requirements around non-nullable specifications. Original Pull Request: #3578
1 parent 6ae97f0 commit 5fafaa4

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
@@ -505,6 +505,7 @@ public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluent
505505
return doFindBy(spec, getDomainClass(), queryFunction);
506506
}
507507

508+
@SuppressWarnings("unchecked")
508509
private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
509510
Function<FetchableFluentQuery<S>, R> queryFunction) {
510511

@@ -594,6 +595,7 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
594595
}
595596

596597
@Override
598+
@SuppressWarnings("unchecked")
597599
public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQuery<S>, R> queryFunction) {
598600

599601
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
@@ -616,7 +618,7 @@ public long count() {
616618
}
617619

618620
@Override
619-
public long count(@Nullable Specification<T> spec) {
621+
public long count(Specification<T> spec) {
620622
return executeCountQuery(getCountQuery(spec, getDomainClass()));
621623
}
622624

@@ -685,7 +687,7 @@ public void flush() {
685687
* @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead
686688
*/
687689
@Deprecated
688-
protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Specification<T> spec) {
690+
protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, Specification<T> spec) {
689691
return readPage(query, getDomainClass(), pageable, spec);
690692
}
691693

@@ -695,11 +697,13 @@ protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Spe
695697
*
696698
* @param query must not be {@literal null}.
697699
* @param domainClass must not be {@literal null}.
698-
* @param spec can be {@literal null}.
700+
* @param spec must not be {@literal null}.
699701
* @param pageable can be {@literal null}.
700702
*/
701703
protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> domainClass, Pageable pageable,
702-
@Nullable Specification<S> spec) {
704+
Specification<S> spec) {
705+
706+
Assert.notNull(spec, "Specification must not be null");
703707

704708
if (pageable.isPaged()) {
705709
query.setFirstResult(PageableUtils.getOffsetAsInteger(pageable));
@@ -713,22 +717,22 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
713717
/**
714718
* Creates a new {@link TypedQuery} from the given {@link Specification}.
715719
*
716-
* @param spec can be {@literal null}.
720+
* @param spec must not be {@literal null}.
717721
* @param pageable must not be {@literal null}.
718722
*/
719-
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {
723+
protected TypedQuery<T> getQuery(Specification<T> spec, Pageable pageable) {
720724

721725
return getQuery(spec, getDomainClass(), pageable.getSort());
722726
}
723727

724728
/**
725729
* Creates a new {@link TypedQuery} from the given {@link Specification}.
726730
*
727-
* @param spec can be {@literal null}.
731+
* @param spec must not be {@literal null}.
728732
* @param domainClass must not be {@literal null}.
729733
* @param pageable must not be {@literal null}.
730734
*/
731-
protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass,
735+
protected <S extends T> TypedQuery<S> getQuery(Specification<S> spec, Class<S> domainClass,
732736
Pageable pageable) {
733737

734738
return getQuery(spec, domainClass, pageable.getSort());
@@ -856,21 +860,23 @@ protected <S> Query getDelete(DeleteSpecification<S> spec, Class<S> domainClass)
856860
/**
857861
* Creates a new count query for the given {@link Specification}.
858862
*
859-
* @param spec can be {@literal null}.
863+
* @param spec must not be {@literal null}.
860864
* @deprecated override {@link #getCountQuery(Specification, Class)} instead
861865
*/
862866
@Deprecated
863-
protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) {
867+
protected TypedQuery<Long> getCountQuery(Specification<T> spec) {
864868
return getCountQuery(spec, getDomainClass());
865869
}
866870

867871
/**
868872
* Creates a new count query for the given {@link Specification}.
869873
*
870-
* @param spec can be {@literal null}.
874+
* @param spec must not be {@literal null}.
871875
* @param domainClass must not be {@literal null}.
872876
*/
873-
protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S> spec, Class<S> domainClass) {
877+
protected <S extends T> TypedQuery<Long> getCountQuery(Specification<S> spec, Class<S> domainClass) {
878+
879+
Assert.notNull(spec, "Specification must not be null");
874880

875881
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
876882
CriteriaQuery<Long> query = builder.createQuery(Long.class);
@@ -1020,7 +1026,7 @@ private Map<String, Object> getHints() {
10201026
private void applyComment(CrudMethodMetadata metadata, BiConsumer<String, Object> consumer) {
10211027

10221028
if (metadata.getComment() != null && provider.getCommentHintKey() != null) {
1023-
consumer.accept(provider.getCommentHintKey(), provider.getCommentHintValue(this.metadata.getComment()));
1029+
consumer.accept(provider.getCommentHintKey(), provider.getCommentHintValue(metadata.getComment()));
10241030
}
10251031
}
10261032

0 commit comments

Comments
 (0)