@@ -167,7 +167,7 @@ public SimpleJpaRepository(Class<T> domainClass, EntityManager entityManager) {
167167 * Configures a custom {@link CrudMethodMetadata} to be used to detect {@link LockModeType}s and query hints to be
168168 * applied to queries.
169169 *
170- * @param metadata
170+ * @param metadata custom {@link CrudMethodMetadata} to be used, can be {@literal null}.
171171 */
172172 @ Override
173173 public void setRepositoryMethodMetadata (CrudMethodMetadata metadata ) {
@@ -203,7 +203,6 @@ public void deleteById(ID id) {
203203
204204 @ Override
205205 @ Transactional
206- @ SuppressWarnings ("unchecked" )
207206 public void delete (T entity ) {
208207
209208 Assert .notNull (entity , ENTITY_MUST_NOT_BE_NULL );
@@ -334,13 +333,13 @@ public Optional<T> findById(ID id) {
334333 Class <T > domainType = getDomainClass ();
335334
336335 if (metadata == null ) {
337- return Optional .ofNullable (entityManager .find (domainType , id ));
336+ return Optional .of (entityManager .find (domainType , id ));
338337 }
339338
340339 LockModeType type = metadata .getLockModeType ();
341340 Map <String , Object > hints = getHints ();
342341
343- return Optional .ofNullable (
342+ return Optional .of (
344343 type == null ? entityManager .find (domainType , id , hints ) : entityManager .find (domainType , id , type , hints ));
345344 }
346345
@@ -458,7 +457,7 @@ public Page<T> findAll(Pageable pageable) {
458457
459458 @ Override
460459 public Optional <T > findOne (Specification <T > spec ) {
461- return Optional .ofNullable (getQuery (spec , Sort .unsorted ()).setMaxResults (2 ).getSingleResultOrNull ());
460+ return Optional .of (getQuery (spec , Sort .unsorted ()).setMaxResults (2 ).getSingleResultOrNull ());
462461 }
463462
464463 @ Override
@@ -474,6 +473,8 @@ public Page<T> findAll(Specification<T> spec, Pageable pageable) {
474473 @ Override
475474 public Page <T > findAll (@ Nullable Specification <T > spec , @ Nullable Specification <T > countSpec , Pageable pageable ) {
476475
476+ spec = spec == null ? Specification .unrestricted () : spec ;
477+
477478 TypedQuery <T > query = getQuery (spec , pageable );
478479 return pageable .isUnpaged () ? new PageImpl <>(query .getResultList ())
479480 : readPage (query , getDomainClass (), pageable , countSpec );
@@ -752,7 +753,7 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, Class<S> domainCla
752753 * @param spec must not be {@literal null}.
753754 * @param pageable must not be {@literal null}.
754755 */
755- protected TypedQuery <T > getQuery (@ Nullable Specification <T > spec , Pageable pageable ) {
756+ protected TypedQuery <T > getQuery (Specification <T > spec , Pageable pageable ) {
756757 return getQuery (spec , getDomainClass (), pageable .getSort ());
757758 }
758759
@@ -784,7 +785,7 @@ protected TypedQuery<T> getQuery(Specification<T> spec, Sort sort) {
784785 * @param domainClass must not be {@literal null}.
785786 * @param sort must not be {@literal null}.
786787 */
787- protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass , Sort sort ) {
788+ protected <S extends T > TypedQuery <S > getQuery (Specification <S > spec , Class <S > domainClass , Sort sort ) {
788789 return getQuery (ReturnedType .of (domainClass , domainClass , projectionFactory ), spec , domainClass , sort ,
789790 Collections .emptySet (), null );
790791 }
0 commit comments