Skip to content

Commit 47e2423

Browse files
committed
Polishing.
Fixed import formatting. Removed (non-Javadoc) comment, since we don't use them anymore. Simplified some code and removed superfluous or wrong Javadoc in touched files. Formatting. See #2388 Original pull request #2449
1 parent 7b3dd77 commit 47e2423

File tree

3 files changed

+12
-44
lines changed

3 files changed

+12
-44
lines changed

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
import jakarta.persistence.criteria.Root;
4141

4242
import org.springframework.dao.EmptyResultDataAccessException;
43-
import org.springframework.data.domain.*;
43+
import org.springframework.data.domain.Example;
44+
import org.springframework.data.domain.Page;
45+
import org.springframework.data.domain.PageImpl;
46+
import org.springframework.data.domain.Pageable;
47+
import org.springframework.data.domain.Sort;
4448
import org.springframework.data.jpa.convert.QueryByExamplePredicateBuilder;
4549
import org.springframework.data.jpa.domain.Specification;
4650
import org.springframework.data.jpa.provider.PersistenceProvider;
@@ -287,7 +291,6 @@ public Optional<T> findById(ID id) {
287291
/**
288292
* Returns {@link QueryHints} with the query hints based on the current {@link CrudMethodMetadata} and potential
289293
* {@link EntityGraph} information.
290-
*
291294
*/
292295
protected QueryHints getQueryHints() {
293296
return metadata == null ? NoHints.INSTANCE : DefaultQueryHints.of(entityInformation, metadata);
@@ -461,10 +464,6 @@ public <S extends T> boolean exists(Example<S> example) {
461464
return query.setMaxResults(1).getResultList().size() == 1;
462465
}
463466

464-
/*
465-
* (non-Javadoc)
466-
* @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#exists(org.springframework.data.jpa.domain.Specification)
467-
*/
468467
@Override
469468
public boolean exists(Specification<T> spec) {
470469

@@ -483,8 +482,7 @@ public <S extends T> List<S> findAll(Example<S> example) {
483482

484483
@Override
485484
public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
486-
return getQuery(new ExampleSpecification<>(example, escapeCharacter), example.getProbeType(), sort)
487-
.getResultList();
485+
return getQuery(new ExampleSpecification<>(example, escapeCharacter), example.getProbeType(), sort).getResultList();
488486
}
489487

490488
@Override

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/UserSpecifications.java

+5-36
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public class UserSpecifications {
3232

3333
/**
3434
* A {@link Specification} to match on a {@link User}'s firstname.
35-
*
36-
* @param firstname
37-
* @return
3835
*/
3936
public static Specification<User> userHasFirstname(final String firstname) {
4037

@@ -43,9 +40,6 @@ public static Specification<User> userHasFirstname(final String firstname) {
4340

4441
/**
4542
* A {@link Specification} to match on a {@link User}'s lastname.
46-
*
47-
* @param firstname
48-
* @return
4943
*/
5044
public static Specification<User> userHasLastname(final String lastname) {
5145

@@ -54,27 +48,16 @@ public static Specification<User> userHasLastname(final String lastname) {
5448

5549
/**
5650
* A {@link Specification} to do a like-match on a {@link User}'s firstname.
57-
*
58-
* @param firstname
59-
* @return
6051
*/
6152
public static Specification<User> userHasFirstnameLike(final String expression) {
6253

63-
return new Specification<User>() {
64-
65-
@Override
66-
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
67-
68-
return cb.like(root.get("firstname").as(String.class), String.format("%%%s%%", expression));
69-
}
70-
};
54+
return (root, query, cb) -> cb.like(root.get("firstname").as(String.class), String.format("%%%s%%", expression));
7155
}
7256

7357
/**
7458
* A {@link Specification} to do an age check.
7559
*
7660
* @param age upper (exclusive) bound of the age
77-
* @return
7861
*/
7962
public static Specification<User> userHasAgeLess(final Integer age) {
8063

@@ -84,33 +67,19 @@ public static Specification<User> userHasAgeLess(final Integer age) {
8467
/**
8568
* A {@link Specification} to do a like-match on a {@link User}'s lastname but also adding a sort order on the
8669
* firstname.
87-
*
88-
* @param firstname
89-
* @return
9070
*/
9171
public static Specification<User> userHasLastnameLikeWithSort(final String expression) {
9272

93-
return new Specification<User>() {
94-
95-
@Override
96-
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
73+
return (root, query, cb) -> {
9774

98-
query.orderBy(cb.asc(root.get("firstname")));
75+
query.orderBy(cb.asc(root.get("firstname")));
9976

100-
return cb.like(root.get("lastname").as(String.class), String.format("%%%s%%", expression));
101-
}
77+
return cb.like(root.get("lastname").as(String.class), String.format("%%%s%%", expression));
10278
};
10379
}
10480

10581
private static <T> Specification<T> simplePropertySpec(final String property, final Object value) {
10682

107-
return new Specification<T>() {
108-
109-
@Override
110-
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
111-
112-
return builder.equal(root.get(property), value);
113-
}
114-
};
83+
return (root, query, builder) -> builder.equal(root.get(property), value);
11584
}
11685
}

Diff for: spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,7 @@ void readsDerivedInterfaceProjections() {
26432643

26442644
@Test // GH-2388
26452645
void existsWithSpec() {
2646+
26462647
flushTestUsers();
26472648

26482649
Specification<User> minorSpec = userHasAgeLess(18);

0 commit comments

Comments
 (0)