Package org.datanucleus.store.query
Class JPQLSingleStringParser
- java.lang.Object
-
- org.datanucleus.store.query.JPQLSingleStringParser
-
public class JPQLSingleStringParser extends java.lang.Object
Parser for handling JPQL Single-String queries. Takes a JPQLQuery and the query string and parses it into its constituent parts, updating the JPQLQuery accordingly with the result that, after calling the parse() method, the JPQLQuery is populated.SELECT [{result} ] [FROM {from-clause} ] [WHERE {filter}] [GROUP BY {grouping-clause} ] [HAVING {having-clause} ] [ORDER BY {ordering-clause}] [RANGE x,y] e.g SELECT c FROM Customer c INNER JOIN c.orders o WHERE c.status = 1
orUPDATE {update-clause} WHERE {filter}
and update-clause is of the form "Entity [[AS] identifier] SET {field = new_value}, ..." orDELETE {delete-clause} WHERE {filter}
and delete-clause is of the form "FROM Entity [[AS] identifier]"Note that only the {filter} and {having-clause} can strictly contain subqueries in JPQL, hence containing keywords
SELECT c FROM Customer c WHERE NOT EXISTS (SELECT o1 FROM c.orders o1)
So the "filter" for the outer query is "NOT EXISTS (SELECT o1 FROM c.orders o1)". Note also that we allow subqueries in {result}, {from}, and {having} clauses as well (vendor extension). If a subquery is contained we extract the subquery and then set it as a variable in the symbol table, and add the subquery separately. Note that the[RANGE x,y]
is a DataNucleus extension syntax to allow for specification of firstResult/maxResults in the query string and hence in subqueries and is dependent on enabling datanucleus.query.jpql.allowRange. TODO Need to better cater for the construct "TRIM(... FROM ...)" since it reuses the FROM keyword and we don't handle that explicitly here, just working around it
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
JPQLSingleStringParser.Compiler
Compiler to process keywords contents.private static class
JPQLSingleStringParser.Parser
Tokenizer that provides access to current token.
-
Field Summary
Fields Modifier and Type Field Description private boolean
allowRange
Standard JPQL does not allow RANGE keyword in the JPQL.private Query
query
The JPQL query to populate.private java.lang.String
queryString
The single-string query string.
-
Constructor Summary
Constructors Constructor Description JPQLSingleStringParser(Query query, java.lang.String queryString)
Constructor for the Single-String parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JPQLSingleStringParser
allowRange()
void
parse()
Method to parse the Single-String query
-
-
-
Field Detail
-
query
private Query query
The JPQL query to populate.
-
queryString
private java.lang.String queryString
The single-string query string.
-
allowRange
private boolean allowRange
Standard JPQL does not allow RANGE keyword in the JPQL.
-
-
Constructor Detail
-
JPQLSingleStringParser
public JPQLSingleStringParser(Query query, java.lang.String queryString)
Constructor for the Single-String parser.- Parameters:
query
- The query into which we populate the components of the queryqueryString
- The Single-String query
-
-
Method Detail
-
allowRange
public JPQLSingleStringParser allowRange()
-
parse
public void parse()
Method to parse the Single-String query
-
-