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 4913bbb0ce
commit 13f9395d05
5 changed files with 46 additions and 0 deletions

View File

@@ -685,18 +685,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

@@ -2108,21 +2108,36 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<QueryTokenStream> {
@Override
public QueryTokenStream 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 QueryTokenStream 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 QueryTokenStream visitState_field(JpqlParser.State_fieldContext ctx) {
if (ctx.reserved_word() != null) {
return visit(ctx.reserved_word());
}
return visit(ctx.identification_variable());
}
@Override
public QueryTokenStream 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

@@ -1040,4 +1040,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

@@ -1923,4 +1923,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

@@ -1027,4 +1027,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");
}
}