This is an automated email from the ASF dual-hosted git repository.

pcristof pushed a commit to branch OPENJPA-2940
in repository https://gitbox.apache.org/repos/asf/openjpa.git


The following commit(s) were added to refs/heads/OPENJPA-2940 by this push:
     new bb2bc0011 [WIP][OPENJPA-2940] Adding JPQL syntax support for ID and 
VERSION
bb2bc0011 is described below

commit bb2bc00114f21da748fe29fdb7bd27e7066c7de2
Author: Paulo Cristovão de Araújo Silva Filho <[email protected]>
AuthorDate: Sun Oct 26 15:23:35 2025 -0300

    [WIP][OPENJPA-2940] Adding JPQL syntax support for ID and VERSION
---
 .../jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt | 32 +++++++++++++-
 .../apache/openjpa/kernel/jpql/TestJPQLParser.java | 51 ++++++++++++++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git 
a/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt 
b/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
index 386702449..bb06aad7f 100644
--- a/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
+++ b/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
@@ -144,6 +144,9 @@ TOKEN [ IGNORE_CASE ]: /* basics */
        |       < DIV: "/" >
 
        |       < NEW: "NEW" >
+       
+       |   < ID: "ID" >
+       |   < VERSION: "VERSION" >
 
        |       < ALL: "ALL" >
        |       < ANY: "ANY" >
@@ -886,7 +889,7 @@ void all_expression() #ALL : { }
 
 void comparison_expression() : { }
 {
-       // comparison_expression ::= string_value comparison_operator 
{string_expression | all_or_any_expression} | boolean_value { =|<>} 
{boolean_expression | all_or_any_expression} | datetime_primary 
comparison_operator {datetime_expression | all_or_any_expression} | 
entity_bean_value { = | <> } {entity_bean_expression | all_or_any_expression} | 
arithmetic_value comparison_operator {arithmetic_expression | 
all_or_any_expression
+       // comparison_expression ::= string_value comparison_operator 
{string_expression | all_or_any_expression} | boolean_value { =|<>} 
{boolean_expression | all_or_any_expression} | datetime_primary 
comparison_operator {datetime_expression | all_or_any_expression} | 
entity_bean_value { = | <> } {entity_bean_expression | all_or_any_expression} | 
arithmetic_value comparison_operator {arithmetic_expression | 
all_or_any_expression | entity_id_or_version_function {= | <>} input_parameter 
| entity [...]
 
        LOOKAHEAD(arithmetic_comp()) arithmetic_comp() |
        LOOKAHEAD(string_comp()) string_comp() |
@@ -894,6 +897,7 @@ void comparison_expression() : { }
        LOOKAHEAD(enum_comp()) enum_comp() |
        LOOKAHEAD(datetime_comp()) datetime_comp() |
        LOOKAHEAD(entity_comp()) entity_comp() |
+       LOOKAHEAD(entity_id_or_version_comp()) entity_id_or_version_comp() |
        LOOKAHEAD(entity_type_comp()) entity_type_comp()
 }
 
@@ -1040,6 +1044,11 @@ void entity_type_comp() : { }
        )
 }
 
+void entity_id_or_version_comp() : { } 
+{
+       entity_id_or_version_function() ( <EQ> input_parameter() #EQUALS(2) | 
<NE> input_parameter() #NOTEQUALS(2))
+}
+
 void type_discriminator() #TYPE : { }
 {
     <TYPE> "(" (LOOKAHEAD(path()) path()
@@ -1064,7 +1073,24 @@ void scalar_expression() #SCALAREXPRESSION : { }
     LOOKAHEAD(datetime_primary()) datetime_primary() |
     LOOKAHEAD(enum_primary()) enum_primary() |
     LOOKAHEAD(boolean_primary()) boolean_primary() |
-    LOOKAHEAD(entity_type_expression()) entity_type_expression()
+    LOOKAHEAD(entity_type_expression()) entity_type_expression() |
+    LOOKAHEAD(entity_id_or_version_function()) entity_id_or_version_function() 
+}
+
+void entity_id_or_version_function(): { }
+{
+    id_function() |
+    version_function()
+}
+
+void id_function() #IDFUNCTION : { }
+{
+       <ID> "(" ( general_identification_variable() | 
simple_entity_expression() ) ")"
+}
+
+void version_function() #VERSIONFUNCTION : { }
+{
+       <VERSION> "(" ( general_identification_variable() | 
simple_entity_expression() ) ")"
 }
 
 void arithmetic_cast_function() #CASTTONUMBER : { }
@@ -1567,6 +1593,8 @@ void path_component() #IDENTIFICATIONVARIABLE :
        | t = <INDEX>
        | t = <TYPE>
        | t = <CAST>
+       | t = <ID>
+       | t = <VERSION>
        | t = <STRING>
        | t = <CLASS>
     ) { jjtThis.setToken (t); }
diff --git 
a/openjpa-kernel/src/test/java/org/apache/openjpa/kernel/jpql/TestJPQLParser.java
 
b/openjpa-kernel/src/test/java/org/apache/openjpa/kernel/jpql/TestJPQLParser.java
index d986005af..9bacdf083 100644
--- 
a/openjpa-kernel/src/test/java/org/apache/openjpa/kernel/jpql/TestJPQLParser.java
+++ 
b/openjpa-kernel/src/test/java/org/apache/openjpa/kernel/jpql/TestJPQLParser.java
@@ -232,5 +232,56 @@ public class TestJPQLParser {
        }
        fail();
     }
+    
+    @Test
+    public void testIdFunctionSimple() {
+       try {
+               String query = "SELECT u FROM User AS u WHERE ID(u) = :id";
+               JPQLNode node = (JPQLNode) new JPQL(query).parseQuery();
+               assertNotNull(node);
+               return;
+       } catch (ParseException ex) {
+               ex.printStackTrace();
+       }
+       fail();
+    }
 
+    @Test
+    public void testIdFunctionOnSelect() {
+       try {
+               String query = "SELECT ID(u) FROM User AS u WHERE u.name = 
:name";
+               JPQLNode node = (JPQLNode) new JPQL(query).parseQuery();
+               assertNotNull(node);
+               return;
+       } catch (ParseException ex) {
+               ex.printStackTrace();
+       }
+       fail();
+    }
+    
+    @Test
+    public void testVersionFunctionSimple() {
+       try {
+               String query = "SELECT u FROM User AS u WHERE VERSION(u) <> 
:version";
+               JPQLNode node = (JPQLNode) new JPQL(query).parseQuery();
+               assertNotNull(node);
+               return;
+       } catch (ParseException ex) {
+               ex.printStackTrace();
+       }
+       fail();
+    }
+    
+    @Test
+    public void testDeleteUsingIdAndVersion() {
+       try {
+               String query = "DELETE from Employee WHERE id(this) = :id AND 
version(this) = :version";
+               JPQLNode node = (JPQLNode) new JPQL(query).parseQuery();
+               assertNotNull(node);
+               return;
+       } catch (ParseException ex) {
+               ex.printStackTrace();
+       }
+       fail();
+    }
 }

Reply via email to