Extend reserved word usage also to JPQL parser.

Closes #3832
This commit is contained in:
Mark Paluch
2025-04-09 09:03:06 +02:00
parent 2ff51be3a1
commit e101ce4440
5 changed files with 48 additions and 2 deletions

View File

@@ -681,18 +681,22 @@ subtype
collection_valued_field
: identification_variable
| reserved_word
;
single_valued_object_field
: identification_variable
| reserved_word
;
state_field
: identification_variable
| reserved_word
;
collection_value_field
: identification_variable
| reserved_word
;
entity_name

View File

@@ -2164,7 +2164,7 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<List<JpaQueryParsingToken>> {
tokens.add(new JpaQueryParsingToken(ctx.INTLITERAL()));
} else if (ctx.FLOATLITERAL() != null) {
tokens.add(new JpaQueryParsingToken(ctx.FLOATLITERAL()));
} else if(ctx.LONGLITERAL() != null) {
} else if (ctx.LONGLITERAL() != null) {
tokens.add(new JpaQueryParsingToken(ctx.LONGLITERAL()));
} else if (ctx.boolean_literal() != null) {
tokens.addAll(visit(ctx.boolean_literal()));
@@ -2226,7 +2226,7 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<List<JpaQueryParsingToken>> {
return List.of(new JpaQueryParsingToken(ctx.INTLITERAL()));
} else if (ctx.FLOATLITERAL() != null) {
return List.of(new JpaQueryParsingToken(ctx.FLOATLITERAL()));
} else if(ctx.LONGLITERAL() != null) {
} else if (ctx.LONGLITERAL() != null) {
return List.of(new JpaQueryParsingToken(ctx.LONGLITERAL()));
} else {
return List.of();
@@ -2275,21 +2275,36 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<List<JpaQueryParsingToken>> {
@Override
public List<JpaQueryParsingToken> visitCollection_valued_field(JpqlParser.Collection_valued_fieldContext ctx) {
if (ctx.reserved_word() != null) {
return visit(ctx.reserved_word());
}
return visit(ctx.identification_variable());
}
@Override
public List<JpaQueryParsingToken> visitSingle_valued_object_field(JpqlParser.Single_valued_object_fieldContext ctx) {
if (ctx.reserved_word() != null) {
return visit(ctx.reserved_word());
}
return visit(ctx.identification_variable());
}
@Override
public List<JpaQueryParsingToken> visitState_field(JpqlParser.State_fieldContext ctx) {
if (ctx.reserved_word() != null) {
return visit(ctx.reserved_word());
}
return visit(ctx.identification_variable());
}
@Override
public List<JpaQueryParsingToken> visitCollection_value_field(JpqlParser.Collection_value_fieldContext ctx) {
if (ctx.reserved_word() != null) {
return visit(ctx.reserved_word());
}
return visit(ctx.identification_variable());
}

View File

@@ -1031,4 +1031,13 @@ class EqlQueryRendererTests {
assertQuery("select e from Employee e where e.lateral = :_lateral");
assertQuery("select te from TestEntity te where te.lateral = :lateral");
}
@Test
void reservedWordsShouldWork() {
assertQuery("select ie from ItemExample ie left join ie.object io where io.externalId = :externalId");
assertQuery("select ie.object from ItemExample ie left join ie.object io where io.externalId = :externalId");
assertQuery("select ie from ItemExample ie left join ie.object io where io.object = :externalId");
assertQuery("select ie from ItemExample ie where ie.status = com.app.domain.object.Status.UP");
}
}

View File

@@ -1674,4 +1674,13 @@ class HqlQueryRendererTests {
String source = "select new com.company.%s.thing.stuff.ClassName(e.id) from Experience e".formatted(reservedWord);
assertQuery(source);
}
@Test
void reservedWordsShouldWork() {
assertQuery("select ie from ItemExample ie left join ie.object io where io.externalId = :externalId");
assertQuery("select ie.object from ItemExample ie left join ie.object io where io.externalId = :externalId");
assertQuery("select ie from ItemExample ie left join ie.object io where io.object = :externalId");
assertQuery("select ie from ItemExample ie where ie.status = com.app.domain.object.Status.UP");
}
}

View File

@@ -1033,4 +1033,13 @@ class JpqlQueryRendererTests {
assertQuery(source);
}
@Test
void reservedWordsShouldWork() {
assertQuery("select ie from ItemExample ie left join ie.object io where io.externalId = :externalId");
assertQuery("select ie.object from ItemExample ie left join ie.object io where io.externalId = :externalId");
assertQuery("select ie from ItemExample ie left join ie.object io where io.object = :externalId");
assertQuery("select ie from ItemExample ie where ie.status = com.app.domain.object.Status.UP");
}
}