Class AbstractJPQLGrammar

    • 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 BNF
        childQueryBNFId - 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 an ExpressionFactory to the given query BNF.
        Parameters:
        queryBNFId - The unique identifier of the parent BNF
        childExpressionFactoryId - The unique identifier of the ExpressionFactory to 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 the ExpressionFactory to add more JPQL identifiers
        identifier - 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 the ExpressionFactory to add more JPQL identifiers
        identifiers - The JPQL identifiers this factory will parse
      • getBaseGrammar

        public JPQLGrammar getBaseGrammar()
        Creates the base JPQLGrammar this one extends.
        Returns:
        The base JPQLGrammar or null if this is the base grammar
      • setFallbackBNFId

        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 - The unique identifier of the BNF to modify its fallback BNF unique identifier
        fallbackBNFId - The unique identifier of the JPQLQueryBNF to use in the last resort
      • setFallbackExpressionFactoryId

        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 - The unique identifier of the BNF to modify its fallback expression factory unique identifier
      • setHandleCollection

        public void setHandleCollection​(String queryBNFId,
                                        boolean handleCollection)
        Determines whether the Expression handles a collection of sub-expressions that are separated by commas.
        Parameters:
        queryBNFId - The unique identifier of the JPQLQueryBNF
        handleCollection - true if the sub-expression to parse might have several sub-expressions separated by commas; false otherwise
      • 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 the JPQLQueryBNF
        handleNestedArray - true if the expression represented by this BNF can be a nested array; false otherwise
        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 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 - The unique identifier of the JPQLQueryBNF
        handleSubExpression - 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)