Skip to content

Commit a7e28aa

Browse files
christophstroblmp911de
authored andcommitted
Polishing.
A round of minor code style improvements. Original Pull Request: #3695
1 parent 9f36e39 commit a7e28aa

14 files changed

+46
-67
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
5757

5858
static {
5959

60-
Set<Class<? extends Annotation>> annotations = new HashSet<>();
61-
annotations.add(OneToMany.class);
62-
annotations.add(OneToOne.class);
63-
annotations.add(ManyToMany.class);
64-
annotations.add(ManyToOne.class);
60+
Set<Class<? extends Annotation>> annotations;
6561

66-
ASSOCIATION_ANNOTATIONS = Collections.unmodifiableSet(annotations);
62+
ASSOCIATION_ANNOTATIONS = Set.of(OneToMany.class, OneToOne.class, ManyToMany.class, ManyToOne.class);
6763

6864
annotations = new HashSet<>();
6965
annotations.add(Id.class);
@@ -107,7 +103,7 @@ public JpaPersistentPropertyImpl(JpaMetamodel metamodel, Property property,
107103
this.associationTargetType = detectAssociationTargetType();
108104
this.updateable = detectUpdatability();
109105

110-
this.isIdProperty = Lazy.of(() -> ID_ANNOTATIONS.stream().anyMatch(it -> isAnnotationPresent(it)) //
106+
this.isIdProperty = Lazy.of(() -> ID_ANNOTATIONS.stream().anyMatch(this::isAnnotationPresent) //
111107
|| metamodel.isSingleIdAttribute(getOwner().getType(), getName(), getType()));
112108
this.isEntity = Lazy.of(() -> metamodel.isMappedType(getActualType()));
113109
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* JPA specific support projection support.
3+
*/
4+
@org.springframework.lang.NonNullApi
5+
package org.springframework.data.jpa.projection;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ public AbstractStringBasedJpaQuery(JpaQueryMethod method, EntityManager em, Stri
9898
return query.deriveCountQuery(method.getCountQueryProjection());
9999
});
100100

101-
this.countParameterBinder = Lazy.of(() -> {
102-
return this.createBinder(this.countQuery.get());
103-
});
101+
this.countParameterBinder = Lazy.of(() -> this.createBinder(this.countQuery.get()));
104102

105103
this.queryRewriter = queryRewriter;
106104

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public JSqlParserQueryEnhancer(DeclaredQuery query) {
102102
/**
103103
* Parses a query string with JSqlParser.
104104
*
105-
* @param query the query to parse
105+
* @param sql the query to parse
106+
* @param classOfT the query to parse
106107
* @return the parsed query
107108
*/
108109
static <T extends Statement> T parseStatement(String sql, Class<T> classOfT) {
@@ -560,7 +561,7 @@ private static boolean onlyASingleColumnProjection(List<SelectItem<?>> projectio
560561
* </ul>
561562
*/
562563
enum ParsedType {
563-
DELETE, UPDATE, SELECT, INSERT, MERGE, OTHER;
564+
DELETE, UPDATE, SELECT, INSERT, MERGE, OTHER
564565
}
565566

566567
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ private static class DeclaredQueryLookupStrategy extends AbstractQueryLookupStra
143143
*
144144
* @param em must not be {@literal null}.
145145
* @param queryMethodFactory must not be {@literal null}.
146-
* @param evaluationContextProvider must not be {@literal null}.
146+
* @param delegate must not be {@literal null}.
147+
* @param queryRewriterProvider must not be {@literal null}.
147148
*/
148149
public DeclaredQueryLookupStrategy(EntityManager em, JpaQueryMethodFactory queryMethodFactory,
149150
ValueExpressionDelegate delegate, QueryRewriterProvider queryRewriterProvider) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,7 @@ public String getAlias(Origin source) {
848848
*/
849849
public String getAlias(Origin source) {
850850

851-
return aliases.computeIfAbsent(source, it -> JpqlQueryBuilder.getAlias(source.getName(), s -> {
852-
return !aliases.containsValue(s);
853-
}, () -> "join_" + (counter++)));
851+
return aliases.computeIfAbsent(source, it -> JpqlQueryBuilder.getAlias(source.getName(), s -> !aliases.containsValue(s), () -> "join_" + (counter++)));
854852
}
855853

856854
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public Sort createSort(Sort sort, JpaEntityInformation<?, ?> entity) {
158158
}
159159

160160
/**
161-
* Reverse scrolling variant applying {@link Direction#Backward}. In reverse scrolling, we need to flip directions for
161+
* Reverse scrolling variant applying {@link Direction#BACKWARD}. In reverse scrolling, we need to flip directions for
162162
* the actual query so that we do not get everything from the top position and apply the limit but rather flip the
163163
* sort direction, apply the limit and then reverse the result to restore the actual sort order.
164164
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ static MethodInvocationArgument ofParameter(@Nullable String name, @Nullable Int
667667
/**
668668
* Creates a {@link MethodInvocationArgument} object for {@code position}.
669669
*
670-
* @param position the parameter position (1-based) from the method invocation.
670+
* @param parameter the parameter from the method invocation.
671671
* @return {@link MethodInvocationArgument} object for {@code position}.
672672
*/
673673
static MethodInvocationArgument ofParameter(Parameter parameter) {

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,12 @@ public Object prepare(@Nullable Object value) {
273273

274274
if (String.class.equals(parameterType) && !noWildcards) {
275275

276-
switch (type) {
277-
case STARTING_WITH:
278-
return String.format("%s%%", escape.escape(value.toString()));
279-
case ENDING_WITH:
280-
return String.format("%%%s", escape.escape(value.toString()));
281-
case CONTAINING:
282-
case NOT_CONTAINING:
283-
return String.format("%%%s%%", escape.escape(value.toString()));
284-
default:
285-
return value;
286-
}
276+
return switch (type) {
277+
case STARTING_WITH -> String.format("%s%%", escape.escape(value.toString()));
278+
case ENDING_WITH -> String.format("%%%s", escape.escape(value.toString()));
279+
case CONTAINING, NOT_CONTAINING -> String.format("%%%s%%", escape.escape(value.toString()));
280+
default -> value;
281+
};
287282
}
288283

289284
return Collection.class.isAssignableFrom(parameterType) //

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ static QueryParameterSetterFactory forSynthetic() {
9393
*
9494
* @param parser must not be {@literal null}.
9595
* @param evaluationContextProvider must not be {@literal null}.
96-
* @param parameters must not be {@literal null}.
9796
* @return a {@link QueryParameterSetterFactory} that can handle
9897
* {@link org.springframework.expression.spel.standard.SpelExpression}s.
9998
*/
@@ -170,7 +169,6 @@ private static class ExpressionBasedQueryParameterSetterFactory extends QueryPar
170169
/**
171170
* @param parser must not be {@literal null}.
172171
* @param evaluationContextProvider must not be {@literal null}.
173-
* @param parameters must not be {@literal null}.
174172
*/
175173
ExpressionBasedQueryParameterSetterFactory(ValueExpressionParser parser,
176174
ValueEvaluationContextProvider evaluationContextProvider) {

0 commit comments

Comments
 (0)