Skip to content

Commit df8d817

Browse files
committed
Polishing.
Simplify POM setup. Reformat code. See #3745 Original pull request: #3781
1 parent 9be0e94 commit df8d817

13 files changed

+63
-141
lines changed

spring-data-jpa/pom.xml

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
<groupId>org.apache.maven.plugins</groupId>
340340
<artifactId>maven-compiler-plugin</artifactId>
341341
<configuration>
342-
<annotationProcessorPaths>
342+
<annotationProcessorPaths combine.children="append">
343343
<path>
344344
<groupId>com.querydsl</groupId>
345345
<artifactId>querydsl-apt</artifactId>
@@ -420,89 +420,4 @@
420420
</plugins>
421421
</build>
422422

423-
<profiles>
424-
<profile>
425-
<id>nullaway</id>
426-
<build>
427-
<plugins>
428-
<plugin>
429-
<groupId>org.apache.maven.plugins</groupId>
430-
<artifactId>maven-compiler-plugin</artifactId>
431-
<configuration>
432-
<annotationProcessorPaths>
433-
<path>
434-
<groupId>com.querydsl</groupId>
435-
<artifactId>querydsl-apt</artifactId>
436-
<version>${querydsl}</version>
437-
<classifier>jakarta</classifier>
438-
</path>
439-
<path>
440-
<groupId>org.hibernate.orm</groupId>
441-
<artifactId>hibernate-jpamodelgen</artifactId>
442-
<version>${hibernate}</version>
443-
</path>
444-
<path>
445-
<groupId>org.hibernate.orm</groupId>
446-
<artifactId>hibernate-core</artifactId>
447-
<version>${hibernate}</version>
448-
</path>
449-
<path>
450-
<groupId>org.openjdk.jmh</groupId>
451-
<artifactId>jmh-generator-annprocess</artifactId>
452-
<version>${jmh}</version>
453-
</path>
454-
<path>
455-
<groupId>jakarta.persistence</groupId>
456-
<artifactId>jakarta.persistence-api</artifactId>
457-
<version>${jakarta-persistence-api}</version>
458-
</path>
459-
<path>
460-
<groupId>com.google.errorprone</groupId>
461-
<artifactId>error_prone_core</artifactId>
462-
<version>${errorprone}</version>
463-
</path>
464-
<path>
465-
<groupId>com.uber.nullaway</groupId>
466-
<artifactId>nullaway</artifactId>
467-
<version>${nullaway}</version>
468-
</path>
469-
</annotationProcessorPaths>
470-
</configuration>
471-
<executions>
472-
<execution>
473-
<id>default-compile</id>
474-
<phase>none</phase>
475-
</execution>
476-
<execution>
477-
<id>default-testCompile</id>
478-
<phase>none</phase>
479-
</execution>
480-
<execution>
481-
<id>java-compile</id>
482-
<phase>compile</phase>
483-
<goals>
484-
<goal>compile</goal>
485-
</goals>
486-
<configuration>
487-
<compilerArgs>
488-
<arg>-XDcompilePolicy=simple</arg>
489-
<arg>--should-stop=ifError=FLOW</arg>
490-
<arg>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:TreatGeneratedAsUnannotated=true -XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract</arg>
491-
</compilerArgs>
492-
</configuration>
493-
</execution>
494-
<execution>
495-
<id>java-test-compile</id>
496-
<phase>test-compile</phase>
497-
<goals>
498-
<goal>testCompile</goal>
499-
</goals>
500-
</execution>
501-
</executions>
502-
</plugin>
503-
</plugins>
504-
</build>
505-
</profile>
506-
</profiles>
507-
508423
</project>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import java.util.Arrays;
2626
import java.util.stream.StreamSupport;
2727

28-
import org.springframework.lang.CheckReturnValue;
29-
3028
import org.jspecify.annotations.Nullable;
29+
30+
import org.springframework.lang.CheckReturnValue;
3131
import org.springframework.lang.Contract;
3232
import org.springframework.util.Assert;
3333

@@ -232,6 +232,6 @@ static <T> Specification<T> anyOf(Iterable<Specification<T>> specifications) {
232232
* @return a {@link Predicate}, may be {@literal null}.
233233
*/
234234
@Nullable
235-
Predicate toPredicate(Root<T> root, @Nullable CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);
235+
Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);
236236

237237
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static <T> Specification<T> composed(@Nullable Specification<T> lhs, @Nullable S
6161
}
6262

6363
private static <T> @Nullable Predicate toPredicate(@Nullable Specification<T> specification, Root<T> root,
64-
@Nullable CriteriaQuery<?> query, CriteriaBuilder builder) {
64+
CriteriaQuery<?> query, CriteriaBuilder builder) {
6565
return specification == null ? null : specification.toPredicate(root, query, builder);
6666
}
6767

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import java.util.Optional;
3434
import java.util.Set;
3535

36-
import org.springframework.aot.generate.GenerationContext;
37-
3836
import org.jspecify.annotations.Nullable;
37+
38+
import org.springframework.aot.generate.GenerationContext;
3939
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
4040
import org.springframework.beans.factory.config.BeanDefinition;
4141
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -117,7 +117,7 @@ public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSo
117117

118118
Optional<String> transactionManagerRef = source.getAttribute("transactionManagerRef");
119119
builder.addPropertyValue("transactionManager", transactionManagerRef.orElse(DEFAULT_TRANSACTION_MANAGER_BEAN_NAME));
120-
if(entityManagerRefs.containsKey(source)) {
120+
if (entityManagerRefs.containsKey(source)) {
121121
builder.addPropertyReference("entityManager", entityManagerRefs.get(source));
122122
}
123123
builder.addPropertyValue(ESCAPE_CHARACTER_PROPERTY, getEscapeCharacter(source).orElse('\\'));

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import net.sf.jsqlparser.statement.select.SetOperationList;
3939
import net.sf.jsqlparser.statement.select.Values;
4040
import net.sf.jsqlparser.statement.update.Update;
41-
import org.jspecify.annotations.Nullable;
4241

4342
import java.io.ByteArrayInputStream;
4443
import java.io.IOException;
@@ -50,6 +49,8 @@
5049
import java.util.Set;
5150
import java.util.StringJoiner;
5251

52+
import org.jspecify.annotations.Nullable;
53+
5354
import org.springframework.data.domain.Sort;
5455
import org.springframework.util.Assert;
5556
import org.springframework.util.CollectionUtils;
@@ -77,7 +78,7 @@ public class JSqlParserQueryEnhancer implements QueryEnhancer {
7778
private final String projection;
7879
private final Set<String> joinAliases;
7980
private final Set<String> selectAliases;
80-
private final byte @Nullable[] serialized;
81+
private final byte @Nullable [] serialized;
8182

8283
/**
8384
* @param query the query we want to enhance. Must not be {@literal null}.
@@ -94,7 +95,7 @@ public JSqlParserQueryEnhancer(DeclaredQuery query) {
9495
this.selectAliases = Collections.unmodifiableSet(getSelectionAliases(this.statement));
9596
this.joinAliases = Collections.unmodifiableSet(getJoinAliases(this.statement));
9697
byte[] tmp = SerializationUtils.serialize(this.statement);
97-
// this.serialized = tmp != null ? tmp : new byte[0];
98+
// this.serialized = tmp != null ? tmp : new byte[0];
9899
this.serialized = SerializationUtils.serialize(this.statement);
99100
}
100101

@@ -331,7 +332,7 @@ private String applySorting(@Nullable Select selectStatement, Sort sort, @Nullab
331332
}
332333

333334
if (!(selectStatement instanceof PlainSelect selectBody)) {
334-
if(selectStatement != null) {
335+
if (selectStatement != null) {
335336
return selectStatement.toString();
336337
} else {
337338
throw new IllegalArgumentException("Select must not be null");
@@ -372,8 +373,8 @@ public String createCountQueryFor(@Nullable String countProjection) {
372373
return createCountQueryFor(selectBody, countProjection, primaryAlias);
373374
}
374375

375-
private static String createCountQueryFor(PlainSelect selectBody,
376-
@Nullable String countProjection, @Nullable String primaryAlias) {
376+
private static String createCountQueryFor(PlainSelect selectBody, @Nullable String countProjection,
377+
@Nullable String primaryAlias) {
377378

378379
// remove order by
379380
selectBody.setOrderByElements(null);
@@ -526,8 +527,8 @@ enum ParsedType {
526527
* @param bytes a serialized object
527528
* @return the result of deserializing the bytes
528529
*/
529-
private static @Nullable Object deserialize(byte @Nullable[] bytes) {
530-
if(ObjectUtils.isEmpty(bytes)) {
530+
private static @Nullable Object deserialize(byte @Nullable [] bytes) {
531+
if (ObjectUtils.isEmpty(bytes)) {
531532
return null;
532533
}
533534
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
@@ -539,9 +540,9 @@ enum ParsedType {
539540
}
540541
}
541542

542-
private static <T> T deserializeRequired(byte @Nullable[] bytes, Class<T> type) {
543+
private static <T> T deserializeRequired(byte @Nullable [] bytes, Class<T> type) {
543544
Object deserialize = deserialize(bytes);
544-
if(deserialize != null) {
545+
if (deserialize != null) {
545546
return type.cast(deserialize);
546547
}
547548
throw new IllegalStateException("Failed to deserialize object type");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

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

20-
import org.springframework.data.jpa.repository.query.QueryRenderer.QueryRendererBuilder;
21-
2220
import org.jspecify.annotations.Nullable;
21+
22+
import org.springframework.data.jpa.repository.query.QueryRenderer.QueryRendererBuilder;
2323
import org.springframework.data.jpa.repository.query.QueryTransformers.CountSelectionTokenStream;
2424
import org.springframework.util.StringUtils;
2525

@@ -82,7 +82,7 @@ public QueryRendererBuilder visitSelect_clause(JpqlParser.Select_clauseContext c
8282
if (usesDistinct) {
8383
nested.append(QueryTokens.expression(ctx.DISTINCT()));
8484
nested.append(getDistinctCountSelection(QueryTokenStream.concat(ctx.select_item(), this::visit, TOKEN_COMMA)));
85-
} else if(StringUtils.hasText(primaryFromAlias)) {
85+
} else if (StringUtils.hasText(primaryFromAlias)) {
8686
nested.append(QueryTokens.token(primaryFromAlias));
8787
} else {
8888
throw new IllegalStateException("No primary alias present");

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@
2525

2626
import java.util.Objects;
2727

28-
import org.springframework.data.mapping.PropertyPath;
29-
3028
import org.jspecify.annotations.Nullable;
29+
30+
import org.springframework.data.mapping.PropertyPath;
3131
import org.springframework.util.StringUtils;
3232

3333
/**
34+
* Utilities to create JPQL expressions, derived from {@link QueryUtils}.
35+
*
3436
* @author Mark Paluch
3537
*/
3638
class JpqlUtils {
3739

38-
static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, JpqlQueryBuilder.Origin source,
39-
Bindable<?> from, PropertyPath property) {
40+
static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel,
41+
JpqlQueryBuilder.Origin source, Bindable<?> from, PropertyPath property) {
4042
return toExpressionRecursively(metamodel, source, from, property, false);
4143
}
4244

43-
static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, JpqlQueryBuilder.Origin source,
44-
Bindable<?> from, PropertyPath property, boolean isForSelection) {
45+
static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel,
46+
JpqlQueryBuilder.Origin source, Bindable<?> from, PropertyPath property, boolean isForSelection) {
4547
return toExpressionRecursively(metamodel, source, from, property, isForSelection, false);
4648
}
4749

@@ -54,8 +56,9 @@ static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamod
5456
* @param hasRequiredOuterJoin has a parent already required an outer join?
5557
* @return the expression
5658
*/
57-
static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel, JpqlQueryBuilder.Origin source,
58-
Bindable<?> from, PropertyPath property, boolean isForSelection, boolean hasRequiredOuterJoin) {
59+
static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamodel metamodel,
60+
JpqlQueryBuilder.Origin source, Bindable<?> from, PropertyPath property, boolean isForSelection,
61+
boolean hasRequiredOuterJoin) {
5962

6063
String segment = property.getSegment();
6164

@@ -81,7 +84,7 @@ static JpqlQueryBuilder.PathExpression toExpressionRecursively(@Nullable Metamod
8184
ManagedType<?> managedTypeForModel = QueryUtils.getManagedTypeForModel(from);
8285
Attribute<?, ?> nextAttribute = getModelForPath(metamodel, property, managedTypeForModel, from);
8386

84-
if(nextAttribute == null) {
87+
if (nextAttribute == null) {
8588
throw new IllegalStateException("Binding property is null");
8689
}
8790

@@ -144,7 +147,7 @@ static boolean requiresOuterJoin(@Nullable Metamodel metamodel, Bindable<?> bind
144147
}
145148
}
146149

147-
if(metamodel != null) {
150+
if (metamodel != null) {
148151

149152
Class<?> fallbackType = fallback.getBindableJavaType();
150153
try {

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
import java.util.List;
2828

29-
import org.springframework.data.domain.KeysetScrollPosition;
30-
3129
import org.jspecify.annotations.Nullable;
30+
31+
import org.springframework.data.domain.KeysetScrollPosition;
3232
import org.springframework.data.domain.Sort;
3333
import org.springframework.data.domain.Sort.Order;
3434
import org.springframework.data.jpa.domain.Specification;
@@ -68,7 +68,8 @@ public static Sort createSort(KeysetScrollPosition position, Sort sort, JpaEntit
6868
}
6969

7070
@Override
71-
public @Nullable Predicate toPredicate(Root<T> root, @Nullable CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
71+
public @Nullable Predicate toPredicate(Root<T> root, @Nullable CriteriaQuery<?> query,
72+
CriteriaBuilder criteriaBuilder) {
7273
return createPredicate(root, criteriaBuilder);
7374
}
7475

@@ -78,7 +79,6 @@ public static Sort createSort(KeysetScrollPosition position, Sort sort, JpaEntit
7879
return delegate.createPredicate(position, sort, new CriteriaBuilderStrategy(root, criteriaBuilder));
7980
}
8081

81-
8282
public JpqlQueryBuilder.@Nullable Predicate createJpqlPredicate(Bindable<?> from, JpqlQueryBuilder.Entity entity,
8383
ParameterFactory factory) {
8484

@@ -108,9 +108,9 @@ public Expression<Comparable> createExpression(String property) {
108108
@Override
109109
public Predicate compare(Order order, Expression<Comparable> propertyExpression, @Nullable Object value) {
110110

111-
if(value instanceof Comparable compareValue) {
111+
if (value instanceof Comparable compareValue) {
112112
return order.isAscending() ? cb.greaterThan(propertyExpression, compareValue)
113-
: cb.lessThan(propertyExpression, compareValue);
113+
: cb.lessThan(propertyExpression, compareValue);
114114
}
115115
return order.isAscending() ? cb.isNull(propertyExpression) : cb.isNotNull(propertyExpression);
116116

@@ -139,12 +139,13 @@ private static class JpqlStrategy implements QueryStrategy<JpqlQueryBuilder.Expr
139139
private final ParameterFactory factory;
140140
private final @Nullable Metamodel metamodel;
141141

142-
public JpqlStrategy(@Nullable Metamodel metamodel, Bindable<?> from, JpqlQueryBuilder.Entity entity, ParameterFactory factory) {
142+
public JpqlStrategy(@Nullable Metamodel metamodel, Bindable<?> from, JpqlQueryBuilder.Entity entity,
143+
ParameterFactory factory) {
143144

144145
this.from = from;
145146
this.entity = entity;
146147
this.factory = factory;
147-
this.metamodel = metamodel;
148+
this.metamodel = metamodel;
148149
}
149150

150151
@Override
@@ -159,7 +160,7 @@ public JpqlQueryBuilder.Predicate compare(Order order, JpqlQueryBuilder.Expressi
159160
@Nullable Object value) {
160161

161162
JpqlQueryBuilder.WhereStep where = JpqlQueryBuilder.where(propertyExpression);
162-
if(value == null) {
163+
if (value == null) {
163164
return order.isAscending() ? where.isNull() : where.isNotNull();
164165
}
165166
return order.isAscending() ? where.gt(factory.capture(value)) : where.lt(factory.capture(value));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
import java.util.regex.Pattern;
4747
import java.util.stream.Collectors;
4848

49-
import org.springframework.core.annotation.AnnotationUtils;
50-
5149
import org.jspecify.annotations.Nullable;
50+
51+
import org.springframework.core.annotation.AnnotationUtils;
5252
import org.springframework.dao.InvalidDataAccessApiUsageException;
5353
import org.springframework.data.domain.Sort;
5454
import org.springframework.data.domain.Sort.Order;
@@ -868,7 +868,7 @@ static <T> T getAnnotationProperty(Attribute<?, ?> attribute, String propertyNam
868868
}
869869

870870
Annotation annotation = AnnotationUtils.getAnnotation(annotatedMember, associationAnnotation);
871-
if(annotation == null) {
871+
if (annotation == null) {
872872
return defaultValue;
873873
}
874874

0 commit comments

Comments
 (0)