Class QueryContext

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class QueryContext
    extends Job
    implements Closeable
    This class organizes both static and dynamic properties that are specific to a single query.
    Author:
    BaseX Team 2005-22, BSD License, Christian Gruen
    • Field Detail

      • stack

        public final QueryStack stack
        The evaluation stack.
      • vars

        public final Variables vars
        Static variables.
      • functions

        public final StaticFuncs functions
        Functions.
      • parent

        public final QueryContext parent
        Parent query context.
      • context

        public final Context context
        Database context.
      • info

        public final QueryInfo info
        Query info.
      • locks

        public final LockList locks
        User-defined locks.
      • focus

        public QueryFocus focus
        Current query focus.
      • updates

        public Updates updates
        Update container; will be created if the first update is evaluated.
      • ftPosData

        public FTPosData ftPosData
        Full-text position data (needed for highlighting full-text results).
      • ftLexer

        public FTLexer ftLexer
        Current full-text lexer.
      • ftPos

        public int ftPos
        Full-text token positions (needed for highlighting full-text results).
      • scoring

        public boolean scoring
        Scoring flag.
      • tailCalls

        public int tailCalls
        Number of successive tail calls.
      • maxCalls

        public int maxCalls
        Maximum number of successive tail calls (will be set before compilation).
      • varIDs

        public int varIDs
        Counter for variable IDs.
      • modParsed

        public final TokenMap modParsed
        Parsed modules, containing the file path and module uri.
      • main

        public MainModule main
        Main module (root expression).
      • contextScope

        public ContextScope contextScope
        Context scope.
      • finalContext

        public boolean finalContext
        Indicates if context scope exists and is final.
    • Constructor Detail

      • QueryContext

        public QueryContext​(QueryContext parent)
        Constructor.
        Parameters:
        parent - parent context
      • QueryContext

        public QueryContext​(Context context)
        Constructor.
        Parameters:
        context - database context
      • QueryContext

        public QueryContext​(Context context,
                            QueryContext parent,
                            QueryResources resources,
                            QueryInfo info)
        Constructor.
        Parameters:
        context - database context
        parent - parent context (can be null)
        info - query info (can be null)
        resources - resources (can be null)
    • Method Detail

      • suggest

        public StringList suggest​(String query,
                                  Data data)
        Collects suggestions for completing a path expression.
        Parameters:
        query - query string
        data - data reference
        Returns:
        list of suggestions, followed by valid input string
      • parseMain

        public MainModule parseMain​(String query,
                                    String uri,
                                    StaticContext sc)
                             throws QueryException
        Parses the specified query and assigns the root expression.
        Parameters:
        query - query string
        uri - base URI (can be null)
        sc - static context (can be null)
        Returns:
        main module
        Throws:
        QueryException - query exception
      • assign

        public void assign​(StaticFunc func,
                           Expr... args)
                    throws QueryException
        Creates a function call for the specified function and assigns it as root expression.
        Parameters:
        func - user-defined function
        args - arguments
        Throws:
        QueryException - query exception
      • compile

        public void compile()
                     throws QueryException
        Compiles the expression. Performs static optimizations.
        Throws:
        QueryException - query exception
      • optimize

        public void optimize()
                      throws QueryException
        Optimizes the expression. Performs dynamic optimizations.
        Throws:
        QueryException - query exception
      • next

        public Item next​(Iter iter)
                  throws QueryException
        Checks if evaluation has been stopped and returns the next item of an iterator.
        Parameters:
        iter - iterator
        Returns:
        item or null
        Throws:
        QueryException - query exception
      • updates

        public Updates updates()
        Returns the updates container.
        Returns:
        updates container
      • addLocks

        public void addLocks()
        Description copied from class: Job
        Collects lock strings (databases, special identifiers) when registering a query.
        Overrides:
        addLocks in class Job
      • bind

        public void bind​(String name,
                         Object value,
                         String type,
                         StaticContext sc)
                  throws QueryException
        Binds a value to a global variable or the context value. The arguments will be ignored if a value has already been assigned. The specified type is interpreted as follows:
        • If "json" is specified, the value is converted according to the rules specified in JsonXQueryConverter.
        • Otherwise, the type is cast to the specified XDM type.
        Parameters:
        name - name of variable; context value if empty string or null
        value - value to be bound (object or XQuery Value)
        type - type (may be null)
        sc - static context
        Throws:
        QueryException - query exception
      • evalInfo

        public void evalInfo​(String string)
        Adds some evaluation info.
        Parameters:
        string - evaluation info
      • parameters

        public SerializerOptions parameters()
        Returns query-specific or default serialization parameters.
        Returns:
        serialization parameters
      • ftOpt

        public FTOpt ftOpt()
        Returns the current full-text options. Creates a new instance if called for the first time.
        Returns:
        full-text options
      • ftOpt

        public void ftOpt​(FTOpt opt)
        Assigns full-text options.
        Parameters:
        opt - full-text options
      • toXml

        public FElem toXml​(boolean full)
        Creates and returns an XML query plan (expression tree) for this query.
        Parameters:
        full - include comprehensive information
        Returns:
        query plan
      • updating

        public void updating()
        Indicates that the query contains updating expressions.
      • shortInfo

        public String shortInfo()
        Description copied from class: Job
        Returns short progress information. Can be overwritten to give more specific feedback.
        Overrides:
        shortInfo in class Job
        Returns:
        header information
      • get

        public Value get​(Var var)
        Gets the value currently bound to the given variable.
        Parameters:
        var - variable
        Returns:
        bound value
      • set

        public void set​(Var var,
                        Value value)
                 throws QueryException
        Binds an expression to a local variable.
        Parameters:
        var - variable
        value - expression to be bound
        Throws:
        QueryException - exception
      • registerTailCall

        public void registerTailCall​(XQFunction fn,
                                     Value[] arg)
        Registers a tail-called function and its arguments to this query context.
        Parameters:
        fn - function to call
        arg - arguments to pass to fn
      • pollTailCall

        public XQFunction pollTailCall()
        Returns and clears the currently registered tail-call function.
        Returns:
        function to call if present, null otherwise
      • pollTailArgs

        public Value[] pollTailArgs()
        Returns and clears registered arguments of a tail-called function.
        Returns:
        argument values if a tail call was registered, null otherwise