Skip to content

Commit af28245

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 36c9b4d commit af28245

File tree

3 files changed

+31
-47
lines changed

3 files changed

+31
-47
lines changed

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

+25-11
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,34 @@
1717

1818
import static org.springframework.data.jpa.repository.query.QueryUtils.*;
1919

20-
import java.util.*;
20+
import java.util.ArrayList;
21+
import java.util.Collection;
22+
import java.util.Collections;
23+
import java.util.HashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Optional;
2127
import java.util.function.Function;
2228

23-
import javax.persistence.*;
24-
import javax.persistence.criteria.*;
29+
import javax.persistence.EntityManager;
30+
import javax.persistence.LockModeType;
31+
import javax.persistence.NoResultException;
32+
import javax.persistence.Parameter;
33+
import javax.persistence.Query;
34+
import javax.persistence.TypedQuery;
35+
import javax.persistence.criteria.CriteriaBuilder;
36+
import javax.persistence.criteria.CriteriaQuery;
37+
import javax.persistence.criteria.ParameterExpression;
38+
import javax.persistence.criteria.Path;
39+
import javax.persistence.criteria.Predicate;
40+
import javax.persistence.criteria.Root;
2541

2642
import org.springframework.dao.EmptyResultDataAccessException;
27-
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;
2848
import org.springframework.data.jpa.convert.QueryByExamplePredicateBuilder;
2949
import org.springframework.data.jpa.domain.Specification;
3050
import org.springframework.data.jpa.provider.PersistenceProvider;
@@ -307,7 +327,6 @@ public Optional<T> findById(ID id) {
307327
/**
308328
* Returns {@link QueryHints} with the query hints based on the current {@link CrudMethodMetadata} and potential
309329
* {@link EntityGraph} information.
310-
*
311330
*/
312331
protected QueryHints getQueryHints() {
313332
return metadata == null ? NoHints.INSTANCE : DefaultQueryHints.of(entityInformation, metadata);
@@ -537,10 +556,6 @@ public <S extends T> boolean exists(Example<S> example) {
537556
return query.setMaxResults(1).getResultList().size() == 1;
538557
}
539558

540-
/*
541-
* (non-Javadoc)
542-
* @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#exists(org.springframework.data.jpa.domain.Specification)
543-
*/
544559
@Override
545560
public boolean exists(Specification<T> spec) {
546561

@@ -567,8 +582,7 @@ public <S extends T> List<S> findAll(Example<S> example) {
567582
*/
568583
@Override
569584
public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
570-
return getQuery(new ExampleSpecification<>(example, escapeCharacter), example.getProbeType(), sort)
571-
.getResultList();
585+
return getQuery(new ExampleSpecification<>(example, escapeCharacter), example.getProbeType(), sort).getResultList();
572586
}
573587

574588
/*

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
}

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)