Class AbstractJPQLGrammar
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.parser.AbstractJPQLGrammar
-
- All Implemented Interfaces:
JPQLGrammar
- Direct Known Subclasses:
EclipseLinkJPQLGrammar1,EclipseLinkJPQLGrammar2_0,EclipseLinkJPQLGrammar2_1,EclipseLinkJPQLGrammar2_2,EclipseLinkJPQLGrammar2_3,EclipseLinkJPQLGrammar2_4,EclipseLinkJPQLGrammar2_5,EclipseLinkJPQLGrammar2_6,JPQLGrammar1_0,JPQLGrammar2_0,JPQLGrammar2_1
public abstract class AbstractJPQLGrammar extends Object implements JPQLGrammar
The abstract definition of a
JPQLGrammar. The grammar defines how a JPQL query is parsed, which is based on the BNF defined for that grammar.Provisional API: This interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.
- Since:
- 2.4
- Version:
- 2.5
- Author:
- Pascal Filion
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChildBNF(String queryBNFId, String childQueryBNFId)Adds to the given query BNF a child BNF.voidaddChildFactory(String queryBNFId, String childExpressionFactoryId)Adds to the given unique identifier of anExpressionFactoryto the given query BNF.voidaddIdentifier(String expressionFactoryId, String identifier)Adds the given JPQL identifier to this factory.voidaddIdentifiers(String expressionFactoryId, String... identifiers)Adds the given JPQL identifiers to this factory.JPQLGrammargetBaseGrammar()Creates the baseJPQLGrammarthis one extends.ExpressionRegistrygetExpressionRegistry()Returns the registry containing theJPQLQueryBNFsand theExpressionFactoriesthat are used to properly parse a JPQL query.voidsetFallbackBNFId(String queryBNFId, String fallbackBNFId)When parsing the query and noJPQLQueryBNFscan help to parse the query, then it will fall back on the given one.voidsetFallbackExpressionFactoryId(String queryBNFId, String fallbackExpressionFactoryId)Sets the unique identifier of theExpressionFactoryto use when the fall back BNF ID is notnull.voidsetHandleCollection(String queryBNFId, boolean handleCollection)Determines whether theExpressionhandles a collection of sub-expressions that are separated by commas.voidsetHandleNestedArray(String queryBNFId, boolean handleNestedArray)Sets whether the BNF with the given ID supports nested array or not.voidsetHandleSubExpression(String queryBNFId, boolean handleSubExpression)Sets whether the query BNF with the given ID handles parsing a sub-expression, i.e.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar
getJPAVersion, getProvider, getProviderVersion
-
-
-
-
Method Detail
-
addChildBNF
public void addChildBNF(String queryBNFId, String childQueryBNFId)
Adds to the given query BNF a child BNF.- Parameters:
queryBNFId- The unique identifier of the parent BNF to add a child BNFchildQueryBNFId- The unique identifier of the child to add to the parent BNF
-
addChildFactory
public void addChildFactory(String queryBNFId, String childExpressionFactoryId)
Adds to the given unique identifier of anExpressionFactoryto the given query BNF.- Parameters:
queryBNFId- The unique identifier of the parent BNFchildExpressionFactoryId- The unique identifier of theExpressionFactoryto add to the given query BNF
-
addIdentifier
public void addIdentifier(String expressionFactoryId, String identifier)
Adds the given JPQL identifier to this factory.- Parameters:
expressionFactoryId- The unique identifier of theExpressionFactoryto add more JPQL identifiersidentifier- The JPQL identifier this factory will parse
-
addIdentifiers
public void addIdentifiers(String expressionFactoryId, String... identifiers)
Adds the given JPQL identifiers to this factory.- Parameters:
expressionFactoryId- The unique identifier of theExpressionFactoryto add more JPQL identifiersidentifiers- The JPQL identifiers this factory will parse
-
getBaseGrammar
public JPQLGrammar getBaseGrammar()
Creates the baseJPQLGrammarthis one extends.- Returns:
- The base
JPQLGrammarornullif this is the base grammar
-
getExpressionRegistry
public ExpressionRegistry getExpressionRegistry()
Returns the registry containing theJPQLQueryBNFsand theExpressionFactoriesthat are used to properly parse a JPQL query.- Specified by:
getExpressionRegistryin interfaceJPQLGrammar- Returns:
- The registry containing the information related to the JPQL grammar
-
setFallbackBNFId
public void setFallbackBNFId(String queryBNFId, String fallbackBNFId)
When parsing the query and noJPQLQueryBNFscan help to parse the query, then it will fall back on the given one.- Parameters:
queryBNFId- The unique identifier of the BNF to modify its fallback BNF unique identifierfallbackBNFId- The unique identifier of theJPQLQueryBNFto use in the last resort
-
setFallbackExpressionFactoryId
public void setFallbackExpressionFactoryId(String queryBNFId, String fallbackExpressionFactoryId)
Sets the unique identifier of theExpressionFactoryto use when the fall back BNF ID is notnull. This will be used to parse a portion of the query when the registeredexpression factoriescannot parse it.Note: This method is only called if
JPQLQueryBNF. getFallbackBNFId()does not returnnull.- Parameters:
queryBNFId- The unique identifier of the BNF to modify its fallback expression factory unique identifier
-
setHandleCollection
public void setHandleCollection(String queryBNFId, boolean handleCollection)
Determines whether theExpressionhandles a collection of sub-expressions that are separated by commas.- Parameters:
queryBNFId- The unique identifier of theJPQLQueryBNFhandleCollection-trueif the sub-expression to parse might have several sub-expressions separated by commas;falseotherwise
-
setHandleNestedArray
public void setHandleNestedArray(String queryBNFId, boolean handleNestedArray)
Sets whether the BNF with the given ID supports nested array or not. A nested array is a sub- expression with its child being a collection expression: (item_1, item_2, ..., item_n).- Parameters:
queryBNFId- The unique identifier of theJPQLQueryBNFhandleNestedArray-trueif the expression represented by this BNF can be a nested array;falseotherwise- Since:
- 2.5
-
setHandleSubExpression
public void setHandleSubExpression(String queryBNFId, boolean handleSubExpression)
Sets whether the query BNF with the given ID handles parsing a sub-expression, i.e. parsing an expression encapsulated by parenthesis. Which in fact would be handled by the fallbackExpressionFactory. The default behavior is to not handle it.A good example for using this option is when an
Expressioncannot use anyExpressionFactoryfor creating a child object, parsing will use the fallbackExpressionFactory, if one was specified. So when this is set totrue, the fallbackExpressionFactorywill be immediately invoked.Let's say we want to parse "SELECT e FROM (SELECT a FROM Address a) e",
FromClausecannot use a factory for parsing the entity name (that's what usually theFROMclause has) so it uses the fallback factory to createIdentificationVariableDeclaration. ThenIdentificationVariableDeclarationalso cannot use any factory to create its child object so it uses the fallback factory to createRangeVariableDeclaration. By changing the status of for handling the sub-expression for the BNFs for those objects, then a subquery can be created byRangeVariableDeclaration.
In order to get this working, the following would have to be done into the grammar:FromClause |- IdentificationVariableDeclaration |- RangeVariableDeclaration |- SubExpression(subquery)public class MyJPQLGrammar extends AbstractJPQLGrammar { @Override protected void initializeBNFs() { setHandleSubExpression(InternalFromClauseBNF.ID, true); setHandleSubExpression(InternalSimpleFromClauseBNF.ID, true); setHandleSubExpression(IdentificationVariableDeclarationBNF.ID, true); setHandleSubExpression(RangeVariableDeclarationBNF.ID, true); } }- Parameters:
queryBNFId- The unique identifier of theJPQLQueryBNFhandleSubExpression-trueto let the creation of a sub-expression be created by the fallbackExpressionFactoryregistered with this BNF;falseotherwise (which is the default value)
-
-