Skip to content

Commit 30511fe

Browse files
committed
Polishing.
See #2878 Original pull request #2885
1 parent 1b5dabb commit 30511fe

15 files changed

+33
-54
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/CollectionUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CollectionUtils {
3030
* @param count the number of first elements to be included in the returned list.
3131
* @param list must not be {@literal null}
3232
* @return the returned sublist if the {@code list} is greater {@code count}.
33-
* @param <T>
33+
* @param <T> the element type of the lists.
3434
*/
3535
public static <T> List<T> getFirst(int count, List<T> list) {
3636

@@ -47,7 +47,7 @@ public static <T> List<T> getFirst(int count, List<T> list) {
4747
* @param count the number of last elements to be included in the returned list.
4848
* @param list must not be {@literal null}
4949
* @return the returned sublist if the {@code list} is greater {@code count}.
50-
* @param <T>
50+
* @param <T> the element type of the lists.
5151
*/
5252
public static <T> List<T> getLast(int count, List<T> list) {
5353

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaKeysetScrollQueryCreator.java

+2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class JpaKeysetScrollQueryCreator extends JpaQueryCreator {
4545
public JpaKeysetScrollQueryCreator(PartTree tree, ReturnedType type, CriteriaBuilder builder,
4646
ParameterMetadataProvider provider, JpaEntityInformation<?, ?> entityInformation,
4747
KeysetScrollPosition scrollPosition) {
48+
4849
super(tree, type, builder, provider);
50+
4951
this.entityInformation = entityInformation;
5052
this.scrollPosition = scrollPosition;
5153
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static class ScrollExecution extends JpaQueryExecution {
142142
private final ScrollDelegate<?> delegate;
143143

144144
ScrollExecution(Sort sort, ScrollDelegate<?> delegate) {
145+
145146
this.sort = sort;
146147
this.delegate = delegate;
147148
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/KeysetScrollDelegate.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public class KeysetScrollDelegate {
4040
/**
4141
* Factory method to obtain the right {@link KeysetScrollDelegate}.
4242
*
43-
* @param direction
44-
* @return
43+
* @param direction the direction of scrolling.
44+
* @return a {@link KeysetScrollDelegate} matching the requested direction.
4545
*/
4646
public static KeysetScrollDelegate of(Direction direction) {
4747
return direction == Direction.Forward ? forward : reverse;
@@ -104,7 +104,6 @@ protected Sort getSortOrders(Sort sort) {
104104
return sort;
105105
}
106106

107-
@SuppressWarnings("unchecked")
108107
protected <T> List<T> postProcessResults(List<T> result) {
109108
return result;
110109
}
@@ -154,7 +153,6 @@ public interface QueryStrategy<E, P> {
154153
* Create an expression object from the given {@code property} path.
155154
*
156155
* @param property must not be {@literal null}.
157-
* @return
158156
*/
159157
E createExpression(String property);
160158

@@ -163,33 +161,33 @@ public interface QueryStrategy<E, P> {
163161
*
164162
* @param order must not be {@literal null}.
165163
* @param propertyExpression must not be {@literal null}.
166-
* @param value
167-
* @return
164+
* @param value the value to compare with. Must not be {@literal null}.
165+
* @return an object representing the comparison predicate.
168166
*/
169167
P compare(Order order, E propertyExpression, Object value);
170168

171169
/**
172170
* Create an equals-comparison object.
173171
*
174172
* @param propertyExpression must not be {@literal null}.
175-
* @param value
176-
* @return
173+
* @param value the value to compare with. Must not be {@literal null}.
174+
* @return an object representing the comparison predicate.
177175
*/
178176
P compare(E propertyExpression, @Nullable Object value);
179177

180178
/**
181179
* AND-combine the {@code intermediate} predicates.
182180
*
183-
* @param intermediate
184-
* @return
181+
* @param intermediate the predicates to combine. Must not be {@literal null}.
182+
* @return a single predicate.
185183
*/
186184
P and(List<P> intermediate);
187185

188186
/**
189187
* OR-combine the {@code intermediate} predicates.
190188
*
191-
* @param intermediate
192-
* @return
189+
* @param intermediate the predicates to combine. Must not be {@literal null}.
190+
* @return a single predicate.
193191
*/
194192
P or(List<P> intermediate);
195193
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/KeysetScrollSpecification.java

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public KeysetScrollSpecification(KeysetScrollPosition position, Sort sort, JpaEn
5656
* @param position must not be {@literal null}.
5757
* @param sort must not be {@literal null}.
5858
* @param entity must not be {@literal null}.
59-
* @return
6059
*/
6160
public static Sort createSort(KeysetScrollPosition position, Sort sort, JpaEntityInformation<?, ?> entity) {
6261

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ final class NamedQuery extends AbstractJpaQuery {
4949
private final String queryName;
5050
private final String countQueryName;
5151
private final @Nullable String countProjection;
52-
private final QueryExtractor extractor;
5352
private final boolean namedCountQueryIsPresent;
5453
private final DeclaredQuery declaredQuery;
5554
private final QueryParameterSetter.QueryMetadataCache metadataCache;
@@ -63,7 +62,7 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) {
6362

6463
this.queryName = method.getNamedQueryName();
6564
this.countQueryName = method.getNamedCountQueryName();
66-
this.extractor = method.getQueryExtractor();
65+
QueryExtractor extractor = method.getQueryExtractor();
6766
this.countProjection = method.getCountQueryProjection();
6867

6968
Parameters<?, ?> parameters = method.getParameters();
@@ -81,7 +80,7 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) {
8180
this.declaredQuery = DeclaredQuery.of(queryString, false);
8281

8382
boolean weNeedToCreateCountQuery = !namedCountQueryIsPresent && method.getParameters().hasPageableParameter();
84-
boolean cantExtractQuery = !this.extractor.canExtractQuery();
83+
boolean cantExtractQuery = !extractor.canExtractQuery();
8584

8685
if (weNeedToCreateCountQuery && cantExtractQuery) {
8786
throw QueryCreationException.create(method, CANNOT_EXTRACT_QUERY);
@@ -99,9 +98,8 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) {
9998
/**
10099
* Returns whether the named query with the given name exists.
101100
*
102-
* @param em must not be {@literal null}.
101+
* @param em must not be {@literal null}.
103102
* @param queryName must not be {@literal null}.
104-
* @return
105103
*/
106104
static boolean hasNamedQuery(EntityManager em, String queryName) {
107105

@@ -129,8 +127,7 @@ static boolean hasNamedQuery(EntityManager em, String queryName) {
129127
* Looks up a named query for the given {@link org.springframework.data.repository.query.QueryMethod}.
130128
*
131129
* @param method must not be {@literal null}.
132-
* @param em must not be {@literal null}.
133-
* @return
130+
* @param em must not be {@literal null}.
134131
*/
135132
@Nullable
136133
public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em) {

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FetchableFluentQueryByPredicate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ private Function<Object, R> getConversionFunction() {
233233

234234
static class PredicateScrollDelegate<T> extends ScrollDelegate<T> {
235235

236-
private final ScrollQueryFactory<T> scrollFunction;
236+
private final ScrollQueryFactory scrollFunction;
237237

238-
PredicateScrollDelegate(ScrollQueryFactory<T> scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
238+
PredicateScrollDelegate(ScrollQueryFactory scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
239239
super(entity);
240240
this.scrollFunction = scrollQueryFactory;
241241
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FetchableFluentQueryBySpecification.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ private Function<Object, R> getConversionFunction() {
224224

225225
static class SpecificationScrollDelegate<T> extends ScrollDelegate<T> {
226226

227-
private final ScrollQueryFactory<T> scrollFunction;
227+
private final ScrollQueryFactory scrollFunction;
228228

229-
SpecificationScrollDelegate(ScrollQueryFactory<T> scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
229+
SpecificationScrollDelegate(ScrollQueryFactory scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
230230
super(entity);
231231
this.scrollFunction = scrollQueryFactory;
232232
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/FluentQuerySupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ final Function<Object, R> getConversionFunction(Class<S> inputType, Class<R> tar
8686
return o -> DefaultConversionService.getSharedInstance().convert(o, targetType);
8787
}
8888

89-
interface ScrollQueryFactory<T> {
89+
interface ScrollQueryFactory {
9090
Query createQuery(Sort sort, ScrollPosition scrollPosition);
9191
}
9292

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/JpaEntityInformation.java

+5-12
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public interface JpaEntityInformation<T, ID> extends EntityInformation<T, ID>, J
3535

3636
/**
3737
* Returns the id attribute of the entity.
38-
*
39-
* @return
4038
*/
4139
@Nullable
4240
SingularAttribute<? super T, ?> getIdAttribute();
@@ -62,35 +60,30 @@ public interface JpaEntityInformation<T, ID> extends EntityInformation<T, ID>, J
6260

6361
/**
6462
* Returns {@literal true} if the entity has a composite id.
65-
*
66-
* @return
6763
*/
6864
boolean hasCompositeId();
6965

7066
/**
7167
* Returns the attribute names of the id attributes. If the entity has a composite id, then all id attribute names are
7268
* returned. If the entity has a single id attribute then this single attribute name is returned.
73-
*
74-
* @return
7569
*/
7670
Collection<String> getIdAttributeNames();
7771

7872
/**
7973
* Extracts the value for the given id attribute from a composite id
8074
*
81-
* @param id
82-
* @param idAttribute
83-
* @return
75+
* @param id the composite id from which to extract the attribute.
76+
* @param idAttribute the attribute name to extract.
8477
*/
8578
@Nullable
8679
Object getCompositeIdAttributeValue(Object id, String idAttribute);
8780

8881
/**
8982
* Extract a keyset for {@code propertyPaths} and the primary key (including composite key components if applicable).
9083
*
91-
* @param propertyPaths
92-
* @param entity
93-
* @return
84+
* @param propertyPaths the property paths that make up the keyset in combination with the composite key components.
85+
* @param entity the entity to extract values from
86+
* @return a map mapping String representations of the paths to values from the entity.
9487
* @since 3.1
9588
*/
9689
Map<String, Object> getKeyset(Iterable<String> propertyPaths, T entity);

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformation.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ public JpaMetamodelEntityInformation(Class<T> domainClass, Metamodel metamodel,
8585

8686
this.entityName = type instanceof EntityType ? ((EntityType<?>) type).getName() : null;
8787

88-
if (!(type instanceof IdentifiableType)) {
88+
if (!(type instanceof IdentifiableType<T> identifiableType)) {
8989
throw new IllegalArgumentException("The given domain class does not contain an id attribute");
9090
}
9191

92-
IdentifiableType<T> identifiableType = (IdentifiableType<T>) type;
93-
9492
this.idMetadata = new IdMetadata<>(identifiableType, PersistenceProvider.fromMetamodel(metamodel));
9593
this.versionAttribute = findVersionAttribute(identifiableType, metamodel);
9694

@@ -108,7 +106,6 @@ public String getEntityName() {
108106
*
109107
* @param type must not be {@literal null}.
110108
* @param metamodel must not be {@literal null}.
111-
* @return
112109
*/
113110
@SuppressWarnings("unchecked")
114111
private static <T> Optional<SingularAttribute<? super T, ?>> findVersionAttribute(IdentifiableType<T> type,
@@ -262,7 +259,6 @@ private static class IdMetadata<T> implements Iterable<SingularAttribute<? super
262259
private final Set<SingularAttribute<? super T, ?>> attributes;
263260
private @Nullable Class<?> idType;
264261

265-
@SuppressWarnings("unchecked")
266262
IdMetadata(IdentifiableType<T> source, PersistenceProvider persistenceProvider) {
267263

268264
this.type = source;

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java

-8
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ public Querydsl(EntityManager em, PathBuilder<?> builder) {
7373

7474
/**
7575
* Creates the {@link JPQLQuery} instance based on the configured {@link EntityManager}.
76-
*
77-
* @return
7876
*/
7977
public <T> AbstractJPAQuery<T, JPAQuery<T>> createQuery() {
8078

@@ -93,7 +91,6 @@ public <T> AbstractJPAQuery<T, JPAQuery<T>> createQuery() {
9391
* Creates the {@link JPQLQuery} instance based on the configured {@link EntityManager}.
9492
*
9593
* @param paths must not be {@literal null}.
96-
* @return
9794
*/
9895
public AbstractJPAQuery<Object, JPAQuery<Object>> createQuery(EntityPath<?>... paths) {
9996

@@ -167,7 +164,6 @@ private <T> JPQLQuery<T> addOrderByFrom(QSort qsort, JPQLQuery<T> query) {
167164
*
168165
* @param sort must not be {@literal null}.
169166
* @param query must not be {@literal null}.
170-
* @return
171167
*/
172168
private <T> JPQLQuery<T> addOrderByFrom(Sort sort, JPQLQuery<T> query) {
173169

@@ -185,7 +181,6 @@ private <T> JPQLQuery<T> addOrderByFrom(Sort sort, JPQLQuery<T> query) {
185181
* Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}.
186182
*
187183
* @param order must not be {@literal null}.
188-
* @return
189184
*/
190185
@SuppressWarnings({ "rawtypes", "unchecked" })
191186
private OrderSpecifier<?> toOrderSpecifier(Order order) {
@@ -200,7 +195,6 @@ private OrderSpecifier<?> toOrderSpecifier(Order order) {
200195
* {@link NullHandling}.
201196
*
202197
* @param nullHandling must not be {@literal null}.
203-
* @return
204198
* @since 1.6
205199
*/
206200
private NullHandling toQueryDslNullHandling(org.springframework.data.domain.Sort.NullHandling nullHandling) {
@@ -225,7 +219,6 @@ private NullHandling toQueryDslNullHandling(org.springframework.data.domain.Sort
225219
* Creates an {@link Expression} for the given {@link Order} property.
226220
*
227221
* @param order must not be {@literal null}.
228-
* @return
229222
*/
230223
private Expression<?> buildOrderPropertyPathFrom(Order order) {
231224

@@ -250,7 +243,6 @@ private Expression<?> buildOrderPropertyPathFrom(Order order) {
250243
* Creates an {@link Expression} for the given {@code property} property.
251244
*
252245
* @param property must not be {@literal null}.
253-
* @return
254246
*/
255247
Expression<?> createExpression(String property) {
256248

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public <S extends T, R> R findBy(Predicate predicate, Function<FetchableFluentQu
175175
return select;
176176
};
177177

178-
ScrollQueryFactory<T> scroll = (sort, scrollPosition) -> {
178+
ScrollQueryFactory scroll = (sort, scrollPosition) -> {
179179

180180
Predicate predicateToUse = predicate;
181181

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
521521
Assert.notNull(spec, "Specification must not be null");
522522
Assert.notNull(queryFunction, "Query function must not be null");
523523

524-
ScrollQueryFactory<T> scrollFunction = (sort, scrollPosition) -> {
524+
ScrollQueryFactory scrollFunction = (sort, scrollPosition) -> {
525525

526526
Specification<T> specToUse = spec;
527527

spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/Item.java

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public Item(Integer id, Integer manufacturerId) {
5050
}
5151

5252
public Item(Integer id, Integer manufacturerId, String name) {
53+
5354
this.id = id;
5455
this.manufacturerId = manufacturerId;
5556
this.name = name;

0 commit comments

Comments
 (0)