5
5
package org .hibernate .query .hql .internal ;
6
6
7
7
import java .util .Locale ;
8
+ import java .util .Set ;
8
9
9
10
import org .hibernate .grammars .hql .HqlParser ;
10
11
import org .hibernate .jpa .spi .JpaCompliance ;
19
20
import org .antlr .v4 .runtime .Token ;
20
21
import org .antlr .v4 .runtime .tree .ParseTree ;
21
22
22
- import static org .hibernate .grammars .hql .HqlParser .IDENTIFIER ;
23
-
24
23
/**
25
24
* Helper for dealing with SQM tree creation
26
25
*
27
26
* @author Steve Ebersole
28
27
*/
29
28
public class SqmTreeCreationHelper {
30
29
30
+ // The list is from the spec section 4.4.1
31
+ private static final Set <String > RESERVED_WORDS = Set .of (
32
+ "abs" ,
33
+ "all" ,
34
+ "and" ,
35
+ "any" ,
36
+ "as" ,
37
+ "asc" ,
38
+ "avg" ,
39
+ "between" ,
40
+ "bit_length" ,
41
+ "both" ,
42
+ "by" ,
43
+ "case" ,
44
+ "ceiling" ,
45
+ "char_length" ,
46
+ "character_length" ,
47
+ "class" ,
48
+ "coalesce" ,
49
+ "concat" ,
50
+ "count" ,
51
+ "current_date" ,
52
+ "current_time" ,
53
+ "current_timestamp" ,
54
+ "delete" ,
55
+ "desc" ,
56
+ "distinct" ,
57
+ "else" ,
58
+ "empty" ,
59
+ "end" ,
60
+ "entry" ,
61
+ "escape" ,
62
+ "exists" ,
63
+ "exp" ,
64
+ "extract" ,
65
+ "false" ,
66
+ "fetch" ,
67
+ "first" ,
68
+ "floor" ,
69
+ "from" ,
70
+ "function" ,
71
+ "group" ,
72
+ "having" ,
73
+ "in" ,
74
+ "index" ,
75
+ "inner" ,
76
+ "is" ,
77
+ "join" ,
78
+ "key" ,
79
+ "leading" ,
80
+ "last" ,
81
+ "left" ,
82
+ "length" ,
83
+ "like" ,
84
+ "local" ,
85
+ "ln" ,
86
+ "locate" ,
87
+ "lower" ,
88
+ "max" ,
89
+ "member" ,
90
+ "min" ,
91
+ "mod" ,
92
+ "new" ,
93
+ "not" ,
94
+ "null" ,
95
+ "nulls" ,
96
+ "nullif" ,
97
+ "object" ,
98
+ "of" ,
99
+ "on" ,
100
+ "or" ,
101
+ "order" ,
102
+ "outer" ,
103
+ "position" ,
104
+ "power" ,
105
+ "replace" ,
106
+ "right" ,
107
+ "round" ,
108
+ "select" ,
109
+ "set" ,
110
+ "sign" ,
111
+ "size" ,
112
+ "some" ,
113
+ "sqrt" ,
114
+ "substring" ,
115
+ "sum" ,
116
+ "then" ,
117
+ "trailing" ,
118
+ "treat" ,
119
+ "trim" ,
120
+ "true" ,
121
+ "type" ,
122
+ "unknown" ,
123
+ "update" ,
124
+ "upper" ,
125
+ "value" ,
126
+ "when" ,
127
+ "where"
128
+ );
129
+
31
130
/**
32
131
* Handle secondary query roots using cross-join semantics.
33
132
*
@@ -108,7 +207,7 @@ public static String extractVariable(HqlParser.VariableContext ctx, SemanticQuer
108
207
// which JPA disallows...
109
208
if ( sqmBuilder .getCreationOptions ().useStrictJpaCompliance () ) {
110
209
final Token identificationVariableToken = identifierContext .getStart ();
111
- if ( identificationVariableToken .getType () != IDENTIFIER ) {
210
+ if ( RESERVED_WORDS . contains ( identificationVariableToken .getText (). toLowerCase ( Locale . ENGLISH ) ) ) {
112
211
throw new StrictJpaComplianceViolation (
113
212
String .format (
114
213
Locale .ROOT ,
@@ -128,7 +227,7 @@ public static String extractVariable(HqlParser.VariableContext ctx, SemanticQuer
128
227
// which JPA disallows...
129
228
if ( sqmBuilder .getCreationOptions ().useStrictJpaCompliance () ) {
130
229
final Token identificationVariableToken = identifierContext .getStart ();
131
- if ( identificationVariableToken .getType () != IDENTIFIER ) {
230
+ if ( RESERVED_WORDS . contains ( identificationVariableToken .getText (). toLowerCase ( Locale . ENGLISH ) ) ) {
132
231
throw new StrictJpaComplianceViolation (
133
232
String .format (
134
233
Locale .ROOT ,
0 commit comments