Skip to content

Commit 68cbfb6

Browse files
christophstroblmp911de
authored andcommitted
Polishing.
A round of minor code style improvements. Original Pull Request: #3695
1 parent b67f551 commit 68cbfb6

15 files changed

+48
-69
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ public <A extends Attribute<S, U>, U> Path<S, U> dot(A attribute) {
281281
* @return
282282
*/
283283
public <P extends PluralAttribute<S, ?, U>, U> Path<S, U> dot(P attribute) {
284-
return new Path<S, U>(add(attribute));
284+
return new Path<>(add(attribute));
285285
}
286286

287287
private List<Attribute<?, ?>> add(Attribute<?, ?> attribute) {
288288

289289
Assert.notNull(attribute, "Attribute must not be null");
290290

291-
List<Attribute<?, ?>> newAttributes = new ArrayList<Attribute<?, ?>>(attributes.size() + 1);
291+
List<Attribute<?, ?>> newAttributes = new ArrayList<>(attributes.size() + 1);
292292
newAttributes.addAll(attributes);
293293
newAttributes.add(attribute);
294294
return newAttributes;

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
@@ -92,9 +92,7 @@ public AbstractStringBasedJpaQuery(JpaQueryMethod method, EntityManager em, Stri
9292
return query.deriveCountQuery(method.getCountQueryProjection());
9393
});
9494

95-
this.countParameterBinder = Lazy.of(() -> {
96-
return this.createBinder(this.countQuery.get());
97-
});
95+
this.countParameterBinder = Lazy.of(() -> this.createBinder(this.countQuery.get()));
9896

9997
this.queryRewriter = queryRewriter;
10098

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
@@ -98,7 +98,8 @@ public JSqlParserQueryEnhancer(DeclaredQuery query) {
9898
/**
9999
* Parses a query string with JSqlParser.
100100
*
101-
* @param query the query to parse
101+
* @param sql the query to parse
102+
* @param classOfT the query to parse
102103
* @return the parsed query
103104
*/
104105
static <T extends Statement> T parseStatement(String sql, Class<T> classOfT) {
@@ -510,7 +511,7 @@ private static boolean onlyASingleColumnProjection(List<SelectItem<?>> projectio
510511
* </ul>
511512
*/
512513
enum ParsedType {
513-
DELETE, UPDATE, SELECT, INSERT, MERGE, OTHER;
514+
DELETE, UPDATE, SELECT, INSERT, MERGE, OTHER
514515
}
515516

516517
/**

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) //

0 commit comments

Comments
 (0)