Skip to content

Commit 9b0060d

Browse files
committed
Switch to Hibernate's official parser for HQL.
Rewrite our custom visitors to plug into Hibernate's official parser for HQL. See #3002 Original Pull Request: #3003
1 parent 480d1b7 commit 9b0060d

File tree

30 files changed

+13608
-3871
lines changed

30 files changed

+13608
-3871
lines changed

Jenkinsfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pipeline {
4848
when {
4949
beforeAgent(true)
5050
allOf {
51-
branch(pattern: "main|(\\d\\.\\d\\.x)", comparator: "REGEXP")
51+
branch(pattern: "issue/hql|main|(\\d\\.\\d\\.x)", comparator: "REGEXP") // TODO
5252
not { triggeredBy 'UpstreamCause' }
5353
}
5454
}

pom.xml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
34

45
<modelVersion>4.0.0</modelVersion>
56

@@ -29,7 +30,9 @@
2930
<properties>
3031
<antlr>4.10.1</antlr> <!-- align with Hibernate's parser -->
3132
<eclipselink>3.0.3</eclipselink>
32-
<hibernate>6.2.1.Final</hibernate>
33+
<hibernate-6.1>6.1.7.Final</hibernate-6.1>
34+
<hibernate-6.2>6.2.1.Final</hibernate-6.2>
35+
<hibernate>${hibernate-6.2}</hibernate>
3336
<hsqldb>2.7.1</hsqldb>
3437
<h2>2.1.214</h2>
3538
<jsqlparser>4.5</jsqlparser>
@@ -47,6 +50,9 @@
4750
<modules>
4851
<module>spring-data-envers</module>
4952
<module>spring-data-jpa</module>
53+
<module>spring-data-jpa-common-parser</module>
54+
<module>spring-data-jpa-hibernate61-parser</module>
55+
<module>spring-data-jpa-hibernate62-parser</module>
5056
<module>spring-data-jpa-distribution</module>
5157
</modules>
5258

@@ -55,7 +61,7 @@
5561
<profile>
5662
<id>hibernate-61</id>
5763
<properties>
58-
<hibernate>6.1.7.Final</hibernate>
64+
<hibernate>${hibernate-6.1}</hibernate>
5965
</properties>
6066
</profile>
6167
<profile>

spring-data-jpa-common-parser/pom.xml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.springframework.data</groupId>
8+
<artifactId>spring-data-jpa-common-parser</artifactId>
9+
<version>3.2.0-SNAPSHOT</version>
10+
11+
<name>Spring Data JPA - Commons Parser</name>
12+
<description>Spring Data module for Common query parsing.</description>
13+
<url>https://projects.spring.io/spring-data-jpa</url>
14+
15+
<parent>
16+
<groupId>org.springframework.data</groupId>
17+
<artifactId>spring-data-jpa-parent</artifactId>
18+
<version>3.2.0-SNAPSHOT</version>
19+
<relativePath>../pom.xml</relativePath>
20+
</parent>
21+
22+
<properties>
23+
<java-module-name>spring.data.jpa</java-module-name>
24+
</properties>
25+
26+
<dependencies>
27+
28+
<dependency>
29+
<groupId>org.antlr</groupId>
30+
<artifactId>antlr4-runtime</artifactId>
31+
<version>${antlr}</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>${project.groupId}</groupId>
36+
<artifactId>spring-data-commons</artifactId>
37+
<version>${springdata.commons}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.springframework</groupId>
42+
<artifactId>spring-tx</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>jakarta.persistence</groupId>
47+
<artifactId>jakarta.persistence-api</artifactId>
48+
<version>3.1.0</version>
49+
</dependency>
50+
51+
</dependencies>
52+
53+
</project>

spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/JpaSort.java renamed to spring-data-jpa-common-parser/src/main/java/org/springframework/data/jpa/domain/JpaSort.java

+14-20
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
import org.springframework.lang.Nullable;
2929
import org.springframework.util.Assert;
3030

31-
import java.util.ArrayList;
32-
import java.util.Arrays;
33-
import java.util.Collection;
34-
import java.util.Collections;
35-
import java.util.List;
36-
3731
/**
3832
* Sort option for queries that wraps JPA meta-model {@link Attribute}s for sorting.
3933
*
@@ -48,7 +42,7 @@ public class JpaSort extends Sort {
4842
private static final long serialVersionUID = 1L;
4943

5044
private JpaSort(Direction direction, List<Path<?, ?>> paths) {
51-
this(Collections.<Order>emptyList(), direction, paths);
45+
this(Collections.<Order> emptyList(), direction, paths);
5246
}
5347

5448
private JpaSort(List<Order> orders, @Nullable Direction direction, List<Path<?, ?>> paths) {
@@ -73,14 +67,14 @@ public static JpaSort of(Attribute<?, ?>... attributes) {
7367
*
7468
* @param paths must not be {@literal null} or empty.
7569
*/
76-
public static JpaSort of(JpaSort.Path<?, ?>... paths) {
70+
public static JpaSort of(Path<?, ?>... paths) {
7771
return new JpaSort(DEFAULT_DIRECTION, Arrays.asList(paths));
7872
}
7973

8074
/**
8175
* Creates a new {@link JpaSort} for the given direction and attributes.
8276
*
83-
* @param direction the sorting direction.
77+
* @param direction the sorting direction.
8478
* @param attributes must not be {@literal null} or empty.
8579
*/
8680
public static JpaSort of(Direction direction, Attribute<?, ?>... attributes) {
@@ -91,7 +85,7 @@ public static JpaSort of(Direction direction, Attribute<?, ?>... attributes) {
9185
* Creates a new {@link JpaSort} for the given direction and {@link Path}s.
9286
*
9387
* @param direction the sorting direction.
94-
* @param paths must not be {@literal null} or empty.
88+
* @param paths must not be {@literal null} or empty.
9589
*/
9690
public static JpaSort of(Direction direction, Path<?, ?>... paths) {
9791
return new JpaSort(direction, Arrays.asList(paths));
@@ -100,7 +94,7 @@ public static JpaSort of(Direction direction, Path<?, ?>... paths) {
10094
/**
10195
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
10296
*
103-
* @param direction can be {@literal null}.
97+
* @param direction can be {@literal null}.
10498
* @param attributes must not be {@literal null}.
10599
* @return
106100
*/
@@ -115,7 +109,7 @@ public JpaSort and(@Nullable Direction direction, Attribute<?, ?>... attributes)
115109
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
116110
*
117111
* @param direction can be {@literal null}.
118-
* @param paths must not be {@literal null}.
112+
* @param paths must not be {@literal null}.
119113
* @return
120114
*/
121115
public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
@@ -134,7 +128,7 @@ public JpaSort and(@Nullable Direction direction, Path<?, ?>... paths) {
134128
/**
135129
* Returns a new {@link JpaSort} with the given sorting criteria added to the current one.
136130
*
137-
* @param direction can be {@literal null}.
131+
* @param direction can be {@literal null}.
138132
* @param properties must not be {@literal null} or empty.
139133
* @return
140134
*/
@@ -152,7 +146,7 @@ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) {
152146
orders.add(new JpaOrder(direction, property));
153147
}
154148

155-
return new JpaSort(orders, direction, Collections.<Path<?, ?>>emptyList());
149+
return new JpaSort(orders, direction, Collections.<Path<?, ?>> emptyList());
156150
}
157151

158152
/**
@@ -223,7 +217,7 @@ public static JpaSort unsafe(String... properties) {
223217
/**
224218
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
225219
*
226-
* @param direction must not be {@literal null}.
220+
* @param direction must not be {@literal null}.
227221
* @param properties must not be {@literal null} or empty.
228222
* @return
229223
*/
@@ -239,7 +233,7 @@ public static JpaSort unsafe(Direction direction, String... properties) {
239233
/**
240234
* Creates new unsafe {@link JpaSort} based on given {@link Direction} and properties.
241235
*
242-
* @param direction must not be {@literal null}.
236+
* @param direction must not be {@literal null}.
243237
* @param properties must not be {@literal null} or empty.
244238
* @return
245239
*/
@@ -331,7 +325,7 @@ public static class JpaOrder extends Order {
331325
* {@link Sort#DEFAULT_DIRECTION}
332326
*
333327
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
334-
* @param property must not be {@literal null}.
328+
* @param property must not be {@literal null}.
335329
*/
336330
private JpaOrder(@Nullable Direction direction, String property) {
337331
this(direction, property, NullHandling.NATIVE);
@@ -341,16 +335,16 @@ private JpaOrder(@Nullable Direction direction, String property) {
341335
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
342336
* {@link Sort#DEFAULT_DIRECTION}.
343337
*
344-
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
345-
* @param property must not be {@literal null}.
338+
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}.
339+
* @param property must not be {@literal null}.
346340
* @param nullHandlingHint can be {@literal null}, will default to {@link NullHandling#NATIVE}.
347341
*/
348342
private JpaOrder(@Nullable Direction direction, String property, NullHandling nullHandlingHint) {
349343
this(direction, property, false, nullHandlingHint, true);
350344
}
351345

352346
private JpaOrder(@Nullable Direction direction, String property, boolean ignoreCase, NullHandling nullHandling,
353-
boolean unsafe) {
347+
boolean unsafe) {
354348

355349
super(direction, property, ignoreCase, nullHandling);
356350
this.unsafe = unsafe;

0 commit comments

Comments
 (0)