Class JavaQueryCompiler

  • All Implemented Interfaces:
    Direct Known Subclasses:
    JDOQLCompiler, JPQLCompiler

    public abstract class JavaQueryCompiler
    extends Object
    implements SymbolResolver
    Typical implementation of a compiler for a java-based query language. The constructor takes in the components of the query, and the method compile() compiles it returning the compiled query, for use elsewhere.

    Each "Expression" is effectively a tree of Expressions. You can navigate through each expression based on their type. For example, a DyadicExpression has a "left" and "right" and an operator between them. The left could also be a DyadicExpression, so you would navigate to its left/right components etc etc.

    • Method Detail

      • getLanguage

        public abstract String getLanguage()
        Accessor for the query language name.
        Name of the query language.
      • setOption

        public void setOption​(String name,
                              Object value)
      • setLinkToParentQuery

        public void setLinkToParentQuery​(JavaQueryCompiler parentCompiler,
                                         Map paramSubstitutionMap)
        Method to set the linkage to the parent query.
        parentCompiler - Compiler for the parent query
        paramSubstitutionMap - Map of parameters in this subquery and what they are in the parent query.
      • compile

        public abstract QueryCompilation compile​(Map parameters,
                                                 Map subqueryMap)
        Method to compile the query.
        parameters - The parameter values keyed by name.
        subqueryMap - Map of subqueries keyed by the subquery name
        The query compilation
      • compileCandidatesParametersVariables

        public void compileCandidatesParametersVariables​(Map parameters)
        Compile the candidates, variables and parameters.
        parameters - Map of parameter values keyed by their name
      • compileFrom

        protected Expression[] compileFrom()
        Method to compile the "from" clause (if present for the query language).
        The compiled from expression(s)
      • compileUpdate

        public Expression[] compileUpdate()
      • compileFilter

        public Expression compileFilter()
        Compile the filter and return the compiled expression.
        The compiled expression
      • swapCandidateAliasNodeName

        protected void swapCandidateAliasNodeName​(Node node)
        Convenience method that takes the input node and if it is set to the original candidate alias then swaps the value to the candidate alias. This is for the situation where we have a subquery which had no alias defined so defaults to "this" (the same as the outer query), so we change the subquery alias from "this" to "sub_this".
        node - The node to process
      • swapSubqueryParameters

        protected Node swapSubqueryParameters​(Node node)
        Convenience method that takes the input node if it is a parameter node and swaps the node
        node - The node to process
        The Node with the swap
      • compileResult

        public Expression[] compileResult()
      • compileGrouping

        public Expression[] compileGrouping()
      • compileHaving

        public Expression compileHaving()
      • compileOrdering

        public Expression[] compileOrdering()
      • resolveClass

        public Class resolveClass​(String className)
        Method to perform a lookup of the class name from the input name. Makes use of the query "imports" and the lookup to "entity name".
        Specified by:
        resolveClass in interface SymbolResolver
        className - Name of the class
        The class corresponding to this name
        ClassNotResolvedException - thrown if not resolvable using imports or entity name
      • isKeyword

        protected abstract boolean isKeyword​(String name)
        Method to return if the supplied name is a keyword. Keywords can only appear at particular places in a query so we need to detect for valid queries.
        name - The name
        Whether it is a keyword