Class 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
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.
- Version:
- 2.5
- Author:
- Pascal Filion
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a newAbstractJPQLGrammar
.protected
AbstractJPQLGrammar
(AbstractJPQLGrammar jpqlGrammar) Creates a newAbstractJPQLGrammar
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChildBNF
(String queryBNFId, String childQueryBNFId) Adds to the given query BNF a child BNF.void
addChildFactory
(String queryBNFId, String childExpressionFactoryId) Adds to the given unique identifier of anExpressionFactory
to the given query BNF.void
addIdentifier
(String expressionFactoryId, String identifier) Adds the given JPQL identifier to this factory.void
addIdentifiers
(String expressionFactoryId, String... identifiers) Adds the given JPQL identifiers to this factory.protected abstract JPQLGrammar
Creates the baseJPQLGrammar
this one extends, if one exists.protected ExpressionRegistry
Creates a newExpressionRegistry
that will be used to store the definition of the JPQL grammar.Creates the baseJPQLGrammar
this one extends.Returns the registry containing theJPQLQueryBNFs
and theExpressionFactories
that are used to properly parse a JPQL query.protected void
Initializes this JPQL grammar.protected abstract void
Registers the JPQL query BNFs defining the JPQL grammar.protected abstract void
Registers theExpressionFactories
required to properly parse JPQL queries.protected abstract void
Registers the JPQL identifiers support by thisJPQLGrammar
.protected void
registerBNF
(JPQLQueryBNF queryBNF) Registers the givenJPQLQueryBNF
.protected void
registerFactory
(ExpressionFactory expressionFactory) Registers the givenExpressionFactory
by storing it for all its identifiers.protected void
registerIdentifierRole
(String identifier, IdentifierRole role) Registers theIdentifierRole
for the given JPQL identifier.protected void
registerIdentifierVersion
(String identifier, JPAVersion version) Registers theJPAVersion
for which the given JPQL identifier was defined.void
setFallbackBNFId
(String queryBNFId, String fallbackBNFId) When parsing the query and noJPQLQueryBNFs
can help to parse the query, then it will fall back on the given one.void
setFallbackExpressionFactoryId
(String queryBNFId, String fallbackExpressionFactoryId) Sets the unique identifier of theExpressionFactory
to use when the fall back BNF ID is notnull
.void
setHandleCollection
(String queryBNFId, boolean handleCollection) Determines whether theExpression
handles a collection of sub-expressions that are separated by commas.void
setHandleNestedArray
(String queryBNFId, boolean handleNestedArray) Sets whether the BNF with the given ID supports nested array or not.void
setHandleSubExpression
(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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar
getJPAVersion, getProvider, getProviderVersion
-
Constructor Details
-
AbstractJPQLGrammar
protected AbstractJPQLGrammar()Creates a newAbstractJPQLGrammar
. -
AbstractJPQLGrammar
Creates a newAbstractJPQLGrammar
.- Parameters:
jpqlGrammar
- TheJPQLGrammar
to extend with the content of this one without instantiating the baseJPQLGrammar
-
-
Method Details
-
addChildBNF
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
Adds to the given unique identifier of anExpressionFactory
to the given query BNF.- Parameters:
queryBNFId
- The unique identifier of the parent BNFchildExpressionFactoryId
- The unique identifier of theExpressionFactory
to add to the given query BNF
-
addIdentifier
Adds the given JPQL identifier to this factory.- Parameters:
expressionFactoryId
- The unique identifier of theExpressionFactory
to add more JPQL identifiersidentifier
- The JPQL identifier this factory will parse
-
addIdentifiers
Adds the given JPQL identifiers to this factory.- Parameters:
expressionFactoryId
- The unique identifier of theExpressionFactory
to add more JPQL identifiersidentifiers
- The JPQL identifiers this factory will parse
-
buildBaseGrammar
Creates the baseJPQLGrammar
this one extends, if one exists.IMPORTANT: The singleton instance of any
JPQLGrammar
(for exampleJPQLGrammar1_0.instance()
cannot be used, the API does not support extending it, a new instance has to be created.- Returns:
- The base
JPQLGrammar
ornull
if there is no base grammar
-
buildExpressionRegistry
Creates a newExpressionRegistry
that will be used to store the definition of the JPQL grammar. This method is invoked ifbuildBaseGrammar()
returnsnull
.- Returns:
- The registry of
JPQLQueryBNFs
,ExpressionFactories
and the JPQL identifiers
-
getBaseGrammar
Creates the baseJPQLGrammar
this one extends.- Returns:
- The base
JPQLGrammar
ornull
if this is the base grammar
-
getExpressionRegistry
Description copied from interface:JPQLGrammar
Returns the registry containing theJPQLQueryBNFs
and theExpressionFactories
that are used to properly parse a JPQL query.- Specified by:
getExpressionRegistry
in interfaceJPQLGrammar
- Returns:
- The registry containing the information related to the JPQL grammar
-
initialize
protected void initialize()Initializes this JPQL grammar. -
initializeBNFs
protected abstract void initializeBNFs()Registers the JPQL query BNFs defining the JPQL grammar. -
initializeExpressionFactories
protected abstract void initializeExpressionFactories()Registers theExpressionFactories
required to properly parse JPQL queries. AnExpressionFactory
is responsible to create anExpression
object that represents a portion of the JPQL query. -
initializeIdentifiers
protected abstract void initializeIdentifiers()Registers the JPQL identifiers support by thisJPQLGrammar
. The registration involves registering theJPAVersion
and theIdentifierRole
. -
registerBNF
Registers the givenJPQLQueryBNF
. The BNF will be registered using its unique identifier.- Parameters:
queryBNF
- TheJPQLQueryBNF
to store
-
registerFactory
Registers the givenExpressionFactory
by storing it for all its identifiers.- Parameters:
expressionFactory
- TheExpressionFactory
to store
-
registerIdentifierRole
Registers theIdentifierRole
for the given JPQL identifier.- Parameters:
identifier
- The JPQL identifier to register its role within a JPQL queryrole
- The role of the given JPQL identifier
-
registerIdentifierVersion
Registers theJPAVersion
for which the given JPQL identifier was defined.- Parameters:
identifier
- The JPQL identifier to register in which version it was added to the grammarversion
- The version when the JPQL identifier was added to the grammar
-
setFallbackBNFId
When parsing the query and noJPQLQueryBNFs
can 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 theJPQLQueryBNF
to use in the last resort
-
setFallbackExpressionFactoryId
Sets the unique identifier of theExpressionFactory
to use when the fall back BNF ID is notnull
. This will be used to parse a portion of the query when the registeredexpression factories
cannot 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
Determines whether theExpression
handles a collection of sub-expressions that are separated by commas.- Parameters:
queryBNFId
- The unique identifier of theJPQLQueryBNF
handleCollection
-true
if the sub-expression to parse might have several sub-expressions separated by commas;false
otherwise
-
setHandleNestedArray
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 theJPQLQueryBNF
handleNestedArray
-true
if the expression represented by this BNF can be a nested array;false
otherwise
-
setHandleSubExpression
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
Expression
cannot use anyExpressionFactory
for creating a child object, parsing will use the fallbackExpressionFactory
, if one was specified. So when this is set totrue
, the fallbackExpressionFactory
will be immediately invoked.Let's say we want to parse "SELECT e FROM (SELECT a FROM Address a) e",
FromClause
cannot use a factory for parsing the entity name (that's what usually theFROM
clause has) so it uses the fallback factory to createIdentificationVariableDeclaration
. ThenIdentificationVariableDeclaration
also 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 theJPQLQueryBNF
handleSubExpression
-true
to let the creation of a sub-expression be created by the fallbackExpressionFactory
registered with this BNF;false
otherwise (which is the default value)
-