Top Description Fields Constructors Methods
org.eclipse.persistence.jpa.jpql.parser

public abstract Class AbstractJPQLGrammar

extends Object
implements JPQLGrammar
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar
Known Direct Subclasses
org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar2_2, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar1, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar2_0, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar2_1, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar2_3, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar2_4, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar2_5, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar2_6, org.eclipse.persistence.jpa.jpql.parser.EclipseLinkJPQLGrammar4_0, org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar1_0, org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar2_0, org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar2_1, org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar2_2, org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar3_0, org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar3_1
Imports
org.eclipse.persistence.jpa.jpql.JPAVersion

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.

Author
Pascal Filion
Since
2.4
Version
2.5

Field Summary

Modifier and TypeField and Description
private JPQLGrammar
jpqlGrammar

The base JPQLGrammar this one extends or null if this is the base grammar.

private ExpressionRegistry
registry

The registry contains the JPQLQueryBNFs and the ExpressionFactories and the support JPQL identifiers.

Constructor Summary

AccessConstructor and Description
protected
AbstractJPQLGrammar()

Creates a new AbstractJPQLGrammar.

protected
AbstractJPQLGrammar(AbstractJPQLGrammar
The JPQLGrammar to extend with the content of this one without instantiating the base JPQLGrammar
jpqlGrammar
)

Creates a new AbstractJPQLGrammar.

Method Summary

Modifier and TypeMethod and Description
public void
addChildBNF(String
The unique identifier of the parent BNF to add a child BNF
queryBNFId
,
String
The unique identifier of the child to add to the parent BNF
childQueryBNFId
)

Adds to the given query BNF a child BNF.

public void
addChildFactory(String
The unique identifier of the parent BNF
queryBNFId
,
String
The unique identifier of the ExpressionFactory to add to the given query BNF
childExpressionFactoryId
)

Adds to the given unique identifier of an ExpressionFactory to the given query BNF.

public void
addIdentifier(String
The unique identifier of the ExpressionFactory to add more JPQL identifiers
expressionFactoryId
,
String
The JPQL identifier this factory will parse
identifier
)

Adds the given JPQL identifier to this factory.

public void
addIdentifiers(String
The unique identifier of the ExpressionFactory to add more JPQL identifiers
expressionFactoryId
,
String...
The JPQL identifiers this factory will parse
identifiers
)

Adds the given JPQL identifiers to this factory.

protected abstract JPQLGrammar

Returns:

The base JPQLGrammar or null if there is no base grammar
buildBaseGrammar
()

Creates the base JPQLGrammar this one extends, if one exists.

protected ExpressionRegistry

Returns:

The registry of JPQLQueryBNFs, ExpressionFactories and the JPQL identifiers
buildExpressionRegistry
()

Creates a new ExpressionRegistry that will be used to store the definition of the JPQL grammar.

public JPQLGrammar

Returns:

The base JPQLGrammar or null if this is the base grammar
getBaseGrammar
()

Creates the base JPQLGrammar this one extends.

public ExpressionRegistry
getExpressionRegistry()

Implements org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar.getExpressionRegistry.

Returns the registry containing the JPQLQueryBNFs and the ExpressionFactories that are used to properly parse a JPQL query.
protected void
initialize()

Initializes this JPQL grammar.

private void
initialize(AbstractJPQLGrammar
The JPQLGrammar to extend with the content of this one without instantiating the base JPQLGrammar
jpqlGrammar
)

This method simply retrieves the ExpressionRegistry from the given JPQLGrammar and extend its grammar by calling the initialize methods from this one.

protected abstract void
initializeBNFs()

Registers the JPQL query BNFs defining the JPQL grammar.

protected abstract void
initializeExpressionFactories()

Registers the ExpressionFactories required to properly parse JPQL queries.

protected abstract void
initializeIdentifiers()

Registers the JPQL identifiers support by this JPQLGrammar.

protected void
registerBNF(JPQLQueryBNF
The JPQLQueryBNF to store
queryBNF
)

Registers the given JPQLQueryBNF.

protected void
registerFactory(ExpressionFactory
The ExpressionFactory to store
expressionFactory
)

Registers the given ExpressionFactory by storing it for all its identifiers.

protected void
registerIdentifierRole(String
The JPQL identifier to register its role within a JPQL query
identifier
,
IdentifierRole
The role of the given JPQL identifier
role
)

Registers the IdentifierRole for the given JPQL identifier.

protected void
registerIdentifierVersion(String
The JPQL identifier to register in which version it was added to the grammar
identifier
,
JPAVersion
The version when the JPQL identifier was added to the grammar
version
)

Registers the JPAVersion for which the given JPQL identifier was defined.

public void
setFallbackBNFId(String
The unique identifier of the BNF to modify its fallback BNF unique identifier
queryBNFId
,
String
The unique identifier of the JPQLQueryBNF to use in the last resort
fallbackBNFId
)

When parsing the query and no JPQLQueryBNFs can help to parse the query, then it will fall back on the given one.

public void
setFallbackExpressionFactoryId(String
The unique identifier of the BNF to modify its fallback expression factory unique identifier
queryBNFId
,
String fallbackExpressionFactoryId)

Sets the unique identifier of the ExpressionFactory to use when the fall back BNF ID is not null.

public void
setHandleCollection(String
The unique identifier of the JPQLQueryBNF
queryBNFId
,
boolean
true if the sub-expression to parse might have several sub-expressions separated by commas; false otherwise
handleCollection
)

Determines whether the Expression handles a collection of sub-expressions that are separated by commas.

public void
setHandleNestedArray(String
The unique identifier of the JPQLQueryBNF
queryBNFId
,
boolean
true if the expression represented by this BNF can be a nested array; false otherwise
handleNestedArray
)

Sets whether the BNF with the given ID supports nested array or not.

public void
setHandleSubExpression(String
The unique identifier of the JPQLQueryBNF
queryBNFId
,
boolean
true to let the creation of a sub-expression be created by the fallback ExpressionFactory registered with this BNF; false otherwise (which is the default value)
handleSubExpression
)

Sets whether the query BNF with the given ID handles parsing a sub-expression, i.e. parsing an expression encapsulated by parenthesis.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

jpqlGrammarback to summary
private JPQLGrammar jpqlGrammar

The base JPQLGrammar this one extends or null if this is the base grammar.

registryback to summary
private ExpressionRegistry registry

The registry contains the JPQLQueryBNFs and the ExpressionFactories and the support JPQL identifiers.

Constructor Detail

AbstractJPQLGrammarback to summary
protected AbstractJPQLGrammar()

Creates a new AbstractJPQLGrammar.

AbstractJPQLGrammarback to summary
protected AbstractJPQLGrammar(AbstractJPQLGrammar jpqlGrammar)

Creates a new AbstractJPQLGrammar.

Parameters
jpqlGrammar:AbstractJPQLGrammar

The JPQLGrammar to extend with the content of this one without instantiating the base JPQLGrammar

Method Detail

addChildBNFback to summary
public void addChildBNF(String queryBNFId, String childQueryBNFId)

Adds to the given query BNF a child BNF.

Parameters
queryBNFId:String

The unique identifier of the parent BNF to add a child BNF

childQueryBNFId:String

The unique identifier of the child to add to the parent BNF

addChildFactoryback to summary
public void addChildFactory(String queryBNFId, String childExpressionFactoryId)

Adds to the given unique identifier of an ExpressionFactory to the given query BNF.

Parameters
queryBNFId:String

The unique identifier of the parent BNF

childExpressionFactoryId:String

The unique identifier of the ExpressionFactory to add to the given query BNF

addIdentifierback to summary
public void addIdentifier(String expressionFactoryId, String identifier)

Adds the given JPQL identifier to this factory.

Parameters
expressionFactoryId:String

The unique identifier of the ExpressionFactory to add more JPQL identifiers

identifier:String

The JPQL identifier this factory will parse

addIdentifiersback to summary
public void addIdentifiers(String expressionFactoryId, String... identifiers)

Adds the given JPQL identifiers to this factory.

Parameters
expressionFactoryId:String

The unique identifier of the ExpressionFactory to add more JPQL identifiers

identifiers:String[]

The JPQL identifiers this factory will parse

buildBaseGrammarback to summary
protected abstract JPQLGrammar buildBaseGrammar()

Creates the base JPQLGrammar this one extends, if one exists.

Important Note

The singleton instance of any JPQLGrammar (for example JPQLGrammar1_0.instance() cannot be used, the API does not support extending it, a new instance has to be created.

Returns:JPQLGrammar

The base JPQLGrammar or null if there is no base grammar

buildExpressionRegistryback to summary
protected ExpressionRegistry buildExpressionRegistry()

Creates a new ExpressionRegistry that will be used to store the definition of the JPQL grammar. This method is invoked if buildBaseGrammar() returns null.

Returns:ExpressionRegistry

The registry of JPQLQueryBNFs, ExpressionFactories and the JPQL identifiers

getBaseGrammarback to summary
public JPQLGrammar getBaseGrammar()

Creates the base JPQLGrammar this one extends.

Returns:JPQLGrammar

The base JPQLGrammar or null if this is the base grammar

getExpressionRegistryback to summary
public ExpressionRegistry getExpressionRegistry()

Implements org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar.getExpressionRegistry.

Doc from org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar.getExpressionRegistry.

Returns the registry containing the JPQLQueryBNFs and the ExpressionFactories that are used to properly parse a JPQL query.

Returns:ExpressionRegistry

The registry containing the information related to the JPQL grammar

Annotations
@Override
initializeback to summary
protected void initialize()

Initializes this JPQL grammar.

initializeback to summary
private void initialize(AbstractJPQLGrammar jpqlGrammar)

This method simply retrieves the ExpressionRegistry from the given JPQLGrammar and extend its grammar by calling the initialize methods from this one.

Parameters
jpqlGrammar:AbstractJPQLGrammar

The JPQLGrammar to extend with the content of this one without instantiating the base JPQLGrammar

initializeBNFsback to summary
protected abstract void initializeBNFs()

Registers the JPQL query BNFs defining the JPQL grammar.

initializeExpressionFactoriesback to summary
protected abstract void initializeExpressionFactories()

Registers the ExpressionFactories required to properly parse JPQL queries. An ExpressionFactory is responsible to create an Expression object that represents a portion of the JPQL query.

initializeIdentifiersback to summary
protected abstract void initializeIdentifiers()

Registers the JPQL identifiers support by this JPQLGrammar. The registration involves registering the JPAVersion and the IdentifierRole.

registerBNFback to summary
protected void registerBNF(JPQLQueryBNF queryBNF)

Registers the given JPQLQueryBNF. The BNF will be registered using its unique identifier.

Parameters
queryBNF:JPQLQueryBNF

The JPQLQueryBNF to store

registerFactoryback to summary
protected void registerFactory(ExpressionFactory expressionFactory)

Registers the given ExpressionFactory by storing it for all its identifiers.

Parameters
expressionFactory:ExpressionFactory

The ExpressionFactory to store

registerIdentifierRoleback to summary
protected void registerIdentifierRole(String identifier, IdentifierRole role)

Registers the IdentifierRole for the given JPQL identifier.

Parameters
identifier:String

The JPQL identifier to register its role within a JPQL query

role:IdentifierRole

The role of the given JPQL identifier

registerIdentifierVersionback to summary
protected void registerIdentifierVersion(String identifier, JPAVersion version)

Registers the JPAVersion for which the given JPQL identifier was defined.

Parameters
identifier:String

The JPQL identifier to register in which version it was added to the grammar

version:JPAVersion

The version when the JPQL identifier was added to the grammar

setFallbackBNFIdback to summary
public void setFallbackBNFId(String queryBNFId, String fallbackBNFId)

When parsing the query and no JPQLQueryBNFs can help to parse the query, then it will fall back on the given one.

Parameters
queryBNFId:String

The unique identifier of the BNF to modify its fallback BNF unique identifier

fallbackBNFId:String

The unique identifier of the JPQLQueryBNF to use in the last resort

setFallbackExpressionFactoryIdback to summary
public void setFallbackExpressionFactoryId(String queryBNFId, String fallbackExpressionFactoryId)

Sets the unique identifier of the ExpressionFactory to use when the fall back BNF ID is not null. This will be used to parse a portion of the query when the registered expression factories cannot parse it.

Note

This method is only called if JPQLQueryBNF. getFallbackBNFId() does not return null.

Parameters
queryBNFId:String

The unique identifier of the BNF to modify its fallback expression factory unique identifier

setHandleCollectionback to summary
public void setHandleCollection(String queryBNFId, boolean handleCollection)

Determines whether the Expression handles a collection of sub-expressions that are separated by commas.

Parameters
queryBNFId:String

The unique identifier of the JPQLQueryBNF

handleCollection:boolean

true if the sub-expression to parse might have several sub-expressions separated by commas; false otherwise

setHandleNestedArrayback to summary
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:String

The unique identifier of the JPQLQueryBNF

handleNestedArray:boolean

true if the expression represented by this BNF can be a nested array; false otherwise

Since
2.5
setHandleSubExpressionback to summary
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 fallback ExpressionFactory. The default behavior is to not handle it.

A good example for using this option is when an Expression cannot use any ExpressionFactory for creating a child object, parsing will use the fallback ExpressionFactory, if one was specified. So when this is set to true, the fallback ExpressionFactory 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 the FROM clause has) so it uses the fallback factory to create IdentificationVariableDeclaration. Then IdentificationVariableDeclaration also cannot use any factory to create its child object so it uses the fallback factory to create RangeVariableDeclaration. By changing the status of for handling the sub-expression for the BNFs for those objects, then a subquery can be created by RangeVariableDeclaration.

FromClause
 |- IdentificationVariableDeclaration
      |- RangeVariableDeclaration
           |- SubExpression(subquery)
In order to get this working, the following would have to be done into the grammar:
 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:String

The unique identifier of the JPQLQueryBNF

handleSubExpression:boolean

true to let the creation of a sub-expression be created by the fallback ExpressionFactory registered with this BNF; false otherwise (which is the default value)