Class JPQLQueryBNF
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.parser.JPQLQueryBNF
-
- Direct Known Subclasses:
AbstractSchemaNameBNF,AggregateExpressionBNF,AllOrAnyExpressionBNF,ArithmeticExpressionBNF,ArithmeticFactorBNF,ArithmeticPrimaryBNF,ArithmeticTermBNF,AsOfClauseBNF,BadExpressionBNF,BetweenExpressionBNF,BooleanExpressionBNF,BooleanLiteralBNF,BooleanPrimaryBNF,CaseExpressionBNF,CaseOperandBNF,CastExpressionBNF,CoalesceExpressionBNF,CollectionMemberDeclarationBNF,CollectionMemberExpressionBNF,CollectionValuedPathExpressionBNF,ComparisonExpressionBNF,ConditionalExpressionBNF,ConditionalFactorBNF,ConditionalPrimaryBNF,ConditionalTermBNF,ConnectByClauseBNF,ConstructorExpressionBNF,ConstructorItemBNF,DatabaseTypeQueryBNF,DatetimeExpressionBNF,DateTimePrimaryBNF,DateTimeTimestampLiteralBNF,DeleteClauseBNF,DeleteClauseRangeVariableDeclarationBNF,DeleteStatementBNF,DerivedCollectionMemberDeclarationBNF,ElseExpressionBNF,EmptyCollectionComparisonExpressionBNF,EntityExpressionBNF,EntityOrValueExpressionBNF,EntityTypeExpressionBNF,EntityTypeLiteralBNF,EnumExpressionBNF,EnumLiteralBNF,EnumPrimaryBNF,ExistsExpressionBNF,ExtractExpressionBNF,FromClauseBNF,FunctionExpressionBNF,FunctionItemBNF,FunctionsReturningDatetimeBNF,FunctionsReturningNumericsBNF,FunctionsReturningStringsBNF,GeneralCaseExpressionBNF,GeneralIdentificationVariableBNF,GenericQueryBNF,GroupByClauseBNF,GroupByItemBNF,HavingClauseBNF,HierarchicalQueryClauseBNF,IdentificationVariableBNF,IdentificationVariableDeclarationBNF,InExpressionBNF,InExpressionExpressionBNF,InExpressionItemBNF,InputParameterBNF,InternalAggregateFunctionBNF,InternalBetweenExpressionBNF,InternalCoalesceExpressionBNF,InternalColumnExpressionBNF,InternalConcatExpressionBNF,InternalConnectByClauseBNF,InternalCountBNF,InternalEntityTypeExpressionBNF,InternalFromClauseBNF,InternalJoinBNF,InternalLengthExpressionBNF,InternalLocateStringExpressionBNF,InternalLocateThirdExpressionBNF,InternalLowerExpressionBNF,InternalModExpressionBNF,InternalOrderByClauseBNF,InternalOrderByItemBNF,InternalSelectExpressionBNF,InternalSimpleFromClauseBNF,InternalSimpleSelectExpressionBNF,InternalSqrtExpressionBNF,InternalSubstringPositionExpressionBNF,InternalSubstringStringExpressionBNF,InternalUpdateClauseBNF,InternalUpperExpressionBNF,InternalWhenClauseBNF,JoinAssociationPathExpressionBNF,JoinBNF,JoinFetchBNF,JPQLStatementBNF,LikeExpressionBNF,LikeExpressionEscapeCharacterBNF,LiteralBNF,NewValueBNF,NullComparisonExpressionBNF,NullIfExpressionBNF,NumericLiteralBNF,ObjectExpressionBNF,OnClauseBNF,OrderByClauseBNF,OrderByItemBNF,OrderSiblingsByClauseBNF,PatternValueBNF,QualifiedIdentificationVariableBNF,RangeDeclarationBNF,RangeVariableDeclarationBNF,RegexpExpressionBNF,ResultVariableBNF,ScalarExpressionBNF,SelectClauseBNF,SelectExpressionBNF,SelectStatementBNF,SimpleArithmeticExpressionBNF,SimpleCaseExpressionBNF,SimpleConditionalExpressionBNF,SimpleEntityExpressionBNF,SimpleEntityOrValueExpressionBNF,SimpleResultVariableBNF,SimpleSelectClauseBNF,SimpleSelectExpressionBNF,SingleValuedObjectPathExpressionBNF,SingleValuedPathExpressionBNF,StartWithClauseBNF,StateFieldPathExpressionBNF,StringExpressionBNF,StringLiteralBNF,StringPrimaryBNF,SubqueryBNF,SubqueryFromClauseBNF,SubSelectIdentificationVariableDeclarationBNF,TableExpressionBNF,TableVariableDeclarationBNF,TreatExpressionBNF,TypeExpressionBNF,UnionClauseBNF,UpdateClauseBNF,UpdateItemBNF,UpdateItemStateFieldPathExpressionBNF,UpdateStatementBNF,VirtualJPQLQueryBNF,WhenClauseBNF,WhereClauseBNF
public abstract class JPQLQueryBNF extends java.lang.ObjectThis defines a single Backus-Naur Form (BNF) of the JPQL grammar. The Java Persistence functional specifications are:
JPQLGrammar1_0: JSR 220: Enterprise JavaBeans™ version 3.0JPQLGrammar2_0: JSR 317: Java™ Persistence 2.0JPQLGrammar2_1: JSR 338: Java™ Persistence 2.1
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.1
- Author:
- Pascal Filion
- Since:
- 2.3
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJPQLQueryBNF(java.lang.String id)Creates a newJPQLQueryBNF.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Iterable<JPQLQueryBNF>children()Returns the set of all the query BNFs that are part of this BNF.ExpressionFactorygetExpressionFactory(java.lang.String identifier)Retrieves theExpressionFactorythat is associated with the given identifier, if the given string is indeed a JPQL identifier.java.lang.Iterable<java.lang.String>getExpressionFactoryIds()Returns the unique identifiers of theExpressionFactoryhandled by this BNF rule, which includes those from the children as well.ExpressionRegistrygetExpressionRegistry()Returns the registry containing theJPQLQueryBNFsand theExpressionFactoriesthat are used to properly parse a JPQL query.java.lang.StringgetFallbackBNFId()When parsing the query and noJPQLQueryBNFscan help to parse the query, then it will fall back on this one.java.lang.StringgetFallbackExpressionFactoryId()Returns the unique identifier of theExpressionFactoryto use when the fall back BNF ID is notnull.java.lang.StringgetId()Returns the unique identifier of thisJPQLQueryBNF.java.lang.Iterable<java.lang.String>getIdentifiers()Retrieves the JPQL identifiers that are supported by this BNF rule.booleanhandleAggregate()Determines whether theExpressionhandles a collection of sub-expressions that are aggregated by logical or arithmetic operators.booleanhandleCollection()Determines whether theExpressionhandles a collection of sub-expressions that are separated by commas.booleanhandlesNestedArray()booleanhandleSubExpression()Determines whether this BNF handles parsing a sub-expression, i.e. parsing an expression encapsulated by parenthesis.booleanhasChild(java.lang.String queryBNFId)Determines whether the BNF with the given ID is part of this BNF or not.booleanhasIdentifier(java.lang.String word)Determines if this query BNF support the given word, which can be an identifier.protected voidinitialize()Initializes this BNF by registering childJPQLQueryBNFsandExpressionFactories.booleanisCompound()Determines whether this BNF has child BNFs registered only to properly parse a query or if the child BNFs are part of the BNF.java.lang.Iterable<JPQLQueryBNF>nonCompoundChildren()Returns the set of all the query BNFs that are part of this BNF.protected voidregisterChild(java.lang.String queryBNFId)Registers the unique identifier of the BNF rule as a child of this BNF rule.protected voidregisterExpressionFactory(java.lang.String expressionFactoryId)Registers a unique identifier of theExpressionFactoryto register with this BNF rule.voidsetCompound(boolean compound)Determines whether this BNF has child BNFs registered only to properly parse a query or if the child BNFs are part of the BNF.voidsetFallbackBNFId(java.lang.String fallbackBNFId)When parsing the query and noJPQLQueryBNFscan help to parse the query, then it will fall back on the given one.voidsetFallbackExpressionFactoryId(java.lang.String fallbackExpressionFactoryId)Sets the unique identifier of theExpressionFactoryto use when the fall back BNF ID is notnull.voidsetHandleAggregate(boolean handleAggregate)Sets whether theExpressionhandles a collection of sub-expressions that are aggregated by logical or arithmetic operators.voidsetHandleCollection(boolean handleCollection)Sets whether theExpressionhandles a collection of sub-expressions that are separated by commas.voidsetHandleNestedArray(boolean handleNestedArray)Sets whether this BNF supports nested array or not.voidsetHandleSubExpression(boolean handleSubExpression)Sets whether this BNF handles parsing a sub-expression, i.e. parsing an expression encapsulated by parenthesis.java.lang.StringtoString()protected voidtoString(java.lang.StringBuilder sb)Adds to the given builder more information about thisJPQLQueryBNF.
-
-
-
Method Detail
-
children
public java.lang.Iterable<JPQLQueryBNF> children()
Returns the set of all the query BNFs that are part of this BNF. The set always include this BNF as well.- Returns:
- The children BNFs describing this BNF rule
-
getExpressionFactory
public ExpressionFactory getExpressionFactory(java.lang.String identifier)
Retrieves theExpressionFactorythat is associated with the given identifier, if the given string is indeed a JPQL identifier.- Parameters:
identifier- The JPQL identifier (in theory) that is used to retrieve the factory responsible to parse a portion of the query starting with that identifier- Returns:
- The
ExpressionFactoryresponsible to parse a portion of the query starting with the given identifier;nullif nothing was registered for it
-
getExpressionFactoryIds
public java.lang.Iterable<java.lang.String> getExpressionFactoryIds()
Returns the unique identifiers of theExpressionFactoryhandled by this BNF rule, which includes those from the children as well.- Returns:
- The list of unique identifiers of the
ExpressionFactoryregistered with this BNF rule and with its children
-
getExpressionRegistry
public ExpressionRegistry getExpressionRegistry()
Returns the registry containing theJPQLQueryBNFsand theExpressionFactoriesthat are used to properly parse a JPQL query.- Returns:
- The registry containing the information related to the JPQL grammar
-
getFallbackBNFId
public java.lang.String getFallbackBNFId()
When parsing the query and noJPQLQueryBNFscan help to parse the query, then it will fall back on this one.- Returns:
- The unique identifier of the
JPQLQueryBNFto use in the last resort
-
getFallbackExpressionFactoryId
public java.lang.String getFallbackExpressionFactoryId()
Returns 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
getFallbackBNFId()does not returnnull.- Returns:
- The unique identifier of the
ExpressionFactory
-
getId
public java.lang.String getId()
Returns the unique identifier of thisJPQLQueryBNF.- Returns:
- The identifier used to register this
JPQLQueryBNFwithAbstractExpression
-
getIdentifiers
public java.lang.Iterable<java.lang.String> getIdentifiers()
Retrieves the JPQL identifiers that are supported by this BNF rule. The JPQL identifiers are retrieved by scanning theExpressionFactoryregistered with this BNF rule and the child BNF rules.- Returns:
- The list of JPQL identifiers that are supported by this BNF
-
handleAggregate
public boolean handleAggregate()
Determines whether theExpressionhandles a collection of sub-expressions that are aggregated by logical or arithmetic operators.- Returns:
trueif the sub-expression to parse might have several logical and/or arithmetic expressions;falseotherwise
-
handleCollection
public boolean handleCollection()
Determines whether theExpressionhandles a collection of sub-expressions that are separated by commas.- Returns:
trueif the sub-expression to parse might have several sub-expressions separated by commas;falseotherwise
-
handlesNestedArray
public boolean handlesNestedArray()
- Since:
- 2.5
-
handleSubExpression
public boolean handleSubExpression()
Determines whether this BNF handles parsing a sub-expression, i.e. parsing an expression encapsulated by parenthesis. SeesetHandleSubExpression(boolean)for more details.- Returns:
trueif this BNF handles parsing a sub-expression;falseotherwise
-
hasChild
public boolean hasChild(java.lang.String queryBNFId)
Determines whether the BNF with the given ID is part of this BNF or not.- Parameters:
queryBNFId- The unique identifier of the BNF rule to check if it's a child of this one- Returns:
trueif the BNF with the given ID is- Since:
- 2.5.1
-
hasIdentifier
public boolean hasIdentifier(java.lang.String word)
Determines if this query BNF support the given word, which can be an identifier.- Parameters:
word- A word that could be a JPQL identifier or anything else- Returns:
trueif the given word is a JPQL identifier and it is supported by this BNF;falseotherwise
-
initialize
protected void initialize()
Initializes this BNF by registering childJPQLQueryBNFsandExpressionFactories.
-
isCompound
public boolean isCompound()
Determines whether this BNF has child BNFs registered only to properly parse a query or if the child BNFs are part of the BNF. An example if a compound BNF isBetweenExpressionBNF, it registers a series of children BNFs but they shouldn't be used to determine if they are part of that BNF since the comparator identifiers are.- Returns:
falseby default
-
nonCompoundChildren
public java.lang.Iterable<JPQLQueryBNF> nonCompoundChildren()
Returns the set of all the query BNFs that are part of this BNF. The set always include this BNF as well.- Returns:
- The children BNFs describing this BNF rule. The set excludes BNF rules that are used to complete a BNF, such as the BNF rules defined for BETWEEN since they are required to properly parse the query
-
registerChild
protected final void registerChild(java.lang.String queryBNFId)
Registers the unique identifier of the BNF rule as a child of this BNF rule.- Parameters:
queryBNFId- The unique identifier of the BNF rule to add as a child- Throws:
java.lang.NullPointerException- ThequeryBNFIdcannot benull
-
registerExpressionFactory
protected final void registerExpressionFactory(java.lang.String expressionFactoryId)
Registers a unique identifier of theExpressionFactoryto register with this BNF rule.- Parameters:
expressionFactoryId- The unique identifier of theExpressionFactory- Throws:
java.lang.NullPointerException- TheexpressionFactoryIdcannot benull
-
setCompound
public void setCompound(boolean compound)
Determines whether this BNF has child BNFs registered only to properly parse a query or if the child BNFs are part of the BNF. An example if a compound BNF isBetweenExpressionBNF, it registers a series of children BNFs but they shouldn't be used to determine if they are part of that BNF since the comparator identifiers are.- Parameters:
compound-trueif this BNF represents a compound BNF and its children are not part of this BNF but only to support compound expression;falseotherwise
-
setFallbackBNFId
public void setFallbackBNFId(java.lang.String fallbackBNFId)
When parsing the query and noJPQLQueryBNFscan help to parse the query, then it will fall back on the given one.- Parameters:
fallbackBNFId- The unique identifier of theJPQLQueryBNFto use in the last resort
-
setFallbackExpressionFactoryId
public void setFallbackExpressionFactoryId(java.lang.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
getFallbackBNFId()does not returnnull.- Parameters:
fallbackExpressionFactoryId- The unique identifier of theExpressionFactory
-
setHandleAggregate
public void setHandleAggregate(boolean handleAggregate)
Sets whether theExpressionhandles a collection of sub-expressions that are aggregated by logical or arithmetic operators.- Parameters:
handleAggregate-trueif the sub-expression to parse might have several logical and/or arithmetic expressions;falseotherwise
-
setHandleCollection
public void setHandleCollection(boolean handleCollection)
Sets whether theExpressionhandles a collection of sub-expressions that are separated by commas.- Parameters:
handleCollection-trueif the sub-expression to parse might have several sub-expressions separated by commas;falseotherwise
-
setHandleNestedArray
public void setHandleNestedArray(boolean handleNestedArray)
Sets whether this BNF 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:
handleNestedArray-trueif the expression represented by this BNF can be a nested array;falseotherwise- Since:
- 2.5
-
setHandleSubExpression
public void setHandleSubExpression(boolean handleSubExpression)
Sets whether this BNF 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:
handleSubExpression-trueto let the creation of a sub-expression be created by the fallbackExpressionFactoryregistered with this BNF;falseotherwise (which is the default value)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
protected void toString(java.lang.StringBuilder sb)
Adds to the given builder more information about thisJPQLQueryBNF.- Parameters:
sb- The builder used to add information about this class
-
-