|
EclipseLink 2.5.0, build 'v20130507-3faac2b' API Reference | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eclipse.persistence.jpa.jpql.parser.AbstractJPQLGrammar
public abstract class AbstractJPQLGrammar
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.
| Constructor Summary | |
|---|---|
protected |
AbstractJPQLGrammar()
Creates a new AbstractJPQLGrammar. |
protected |
AbstractJPQLGrammar(AbstractJPQLGrammar jpqlGrammar)
Creates a new AbstractJPQLGrammar. |
| Method Summary | |
|---|---|
void |
addChildBNF(java.lang.String queryBNFId,
java.lang.String childQueryBNFId)
Adds to the given query BNF a child BNF. |
void |
addChildFactory(java.lang.String queryBNFId,
java.lang.String childExpressionFactoryId)
Adds to the given unique identifier of an ExpressionFactory to the given query BNF. |
void |
addIdentifier(java.lang.String expressionFactoryId,
java.lang.String identifier)
Adds the given JPQL identifier to this factory. |
void |
addIdentifiers(java.lang.String expressionFactoryId,
java.lang.String... identifiers)
Adds the given JPQL identifiers to this factory. |
protected abstract JPQLGrammar |
buildBaseGrammar()
Creates the base JPQLGrammar this one extends, if one exists. |
protected ExpressionRegistry |
buildExpressionRegistry()
Creates a new ExpressionRegistry that will be used to store the definition of the JPQL
grammar. |
JPQLGrammar |
getBaseGrammar()
Creates the base JPQLGrammar this one extends. |
ExpressionRegistry |
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. |
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 IJPQLExtension. |
protected void |
registerBNF(JPQLQueryBNF queryBNF)
Registers the given JPQLQueryBNF. |
protected void |
registerFactory(ExpressionFactory expressionFactory)
Registers the given ExpressionFactory by storing it for all its identifiers. |
protected void |
registerIdentifierRole(java.lang.String identifier,
IdentifierRole role)
Registers the IdentifierRole for the given JPQL identifier. |
protected void |
registerIdentifierVersion(java.lang.String identifier,
JPAVersion version)
Registers the JPAVersion for which the given JPQL identifier was defined. |
void |
setFallbackBNFId(java.lang.String queryBNFId,
java.lang.String fallbackBNFId)
When parsing the query and no JPQLQueryBNFs can help to parse the query,
then it will fall back on the given one. |
void |
setFallbackExpressionFactoryId(java.lang.String queryBNFId,
java.lang.String fallbackExpressionFactoryId)
Sets the unique identifier of the ExpressionFactory to use when the fall back BNF
ID is not null. |
void |
setHandleCollection(java.lang.String queryBNFId,
boolean handleCollection)
Determines whether the Expression handles a collection of sub-expressions that
are separated by commas. |
void |
setHandleNestedArray(java.lang.String queryBNFId,
boolean handleNestedArray)
Sets whether the BNF with the given ID supports nested array or not. |
void |
setHandleSubExpression(java.lang.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. |
| 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 Detail |
|---|
protected AbstractJPQLGrammar()
AbstractJPQLGrammar.
protected AbstractJPQLGrammar(AbstractJPQLGrammar jpqlGrammar)
AbstractJPQLGrammar.
jpqlGrammar - The JPQLGrammar to extend with the content of this one without
instantiating the base JPQLGrammar| Method Detail |
|---|
public void addChildBNF(java.lang.String queryBNFId,
java.lang.String childQueryBNFId)
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
public void addChildFactory(java.lang.String queryBNFId,
java.lang.String childExpressionFactoryId)
ExpressionFactory to the given query BNF.
queryBNFId - The unique identifier of the parent BNFchildExpressionFactoryId - The unique identifier of the ExpressionFactory to add
to the given query BNF
public void addIdentifier(java.lang.String expressionFactoryId,
java.lang.String identifier)
expressionFactoryId - The unique identifier of the ExpressionFactory to add more
JPQL identifiersidentifier - The JPQL identifier this factory will parse
public void addIdentifiers(java.lang.String expressionFactoryId,
java.lang.String... identifiers)
expressionFactoryId - The unique identifier of the ExpressionFactory to add more
JPQL identifiersidentifiers - The JPQL identifiers this factory will parseprotected abstract JPQLGrammar buildBaseGrammar()
JPQLGrammar this one extends, if one exists.
IMPORTANT: 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.
JPQLGrammar or null if there is no base grammarprotected ExpressionRegistry buildExpressionRegistry()
ExpressionRegistry that will be used to store the definition of the JPQL
grammar. This method is invoked if #buildJPQLGrammar() returns null.
JPQLQueryBNFs, ExpressionFactories and the JPQL identifierspublic JPQLGrammar getBaseGrammar()
JPQLGrammar this one extends.
JPQLGrammar or null if this is the base grammarpublic ExpressionRegistry getExpressionRegistry()
JPQLQueryBNFs and the ExpressionFactories that are used
to properly parse a JPQL query.
getExpressionRegistry in interface JPQLGrammarprotected void initialize()
protected abstract void initializeBNFs()
protected abstract void initializeExpressionFactories()
ExpressionFactories required to properly parse JPQL
queries. An ExpressionFactory is responsible to create an Expression object
that represents a portion of the JPQL query.
protected abstract void initializeIdentifiers()
IJPQLExtension. The registration
involves registering the JPAVersion and the IdentifierRole.
protected void registerBNF(JPQLQueryBNF queryBNF)
JPQLQueryBNF. The BNF will be registered using its unique
identifier.
queryBNF - The JPQLQueryBNF to storeprotected void registerFactory(ExpressionFactory expressionFactory)
ExpressionFactory by storing it for all its identifiers.
expressionFactory - The ExpressionFactory to store
protected void registerIdentifierRole(java.lang.String identifier,
IdentifierRole role)
IdentifierRole for the given JPQL identifier.
identifier - The JPQL identifier to register its role within a JPQL queryrole - The role of the given JPQL identifier
protected void registerIdentifierVersion(java.lang.String identifier,
JPAVersion version)
JPAVersion for which the given JPQL identifier was defined.
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
public void setFallbackBNFId(java.lang.String queryBNFId,
java.lang.String fallbackBNFId)
JPQLQueryBNFs can help to parse the query,
then it will fall back on the given one.
queryBNFId - The unique identifier of the BNF to modify its fallback BNF unique identifierfallbackBNFId - The unique identifier of the JPQLQueryBNF to use in the last resort
public void setFallbackExpressionFactoryId(java.lang.String queryBNFId,
java.lang.String fallbackExpressionFactoryId)
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.
queryBNFId - The unique identifier of the BNF to modify its fallback expression factory
unique identifier
public void setHandleCollection(java.lang.String queryBNFId,
boolean handleCollection)
Expression handles a collection of sub-expressions that
are separated by commas.
queryBNFId - The unique identifier of the JPQLQueryBNFhandleCollection - true if the sub-expression to parse might have several
sub-expressions separated by commas; false otherwise
public void setHandleNestedArray(java.lang.String queryBNFId,
boolean handleNestedArray)
queryBNFId - The unique identifier of the JPQLQueryBNFhandleNestedArray - true if the expression represented by this BNF can be
a nested array; false otherwise
public void setHandleSubExpression(java.lang.String queryBNFId,
boolean handleSubExpression)
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);
}
}
queryBNFId - The unique identifier of the JPQLQueryBNFhandleSubExpression - 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)
|
EclipseLink 2.5.0, build 'v20130507-3faac2b' API Reference | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||