Class QueryContext

java.lang.Object
org.basex.core.jobs.Job
org.basex.query.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-21, BSD License, Christian Gruen
  • Field Details

    • stack

      public final QueryStack stack
      The evaluation stack.
    • vars

      public final Variables vars
      Static variables.
    • funcs

      public final StaticFuncs funcs
      Functions.
    • parent

      public final QueryContext parent
      Parent query context.
    • info

      public final QueryInfo info
      Query info.
    • context

      public final Context context
      Database context.
    • resources

      public QueryResources resources
      Query resources.
    • updates

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

      public final QueryThreads threads
      Query threads.
    • focus

      public QueryFocus focus
      Current context value.
    • dateTime

      public QueryDateTime dateTime
      Current date/time values.
    • 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.
    • collations

      public TokenObjMap<Collation> collations
      Available collations.
    • locks

      public final LockList locks
      User-defined locks.
    • 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.
    • ctxItem

      public MainModule ctxItem
      Initial context value.
    • root

      public MainModule root
      Root expression of the query.
  • Constructor Details

    • QueryContext

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

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

    • parse

      public AModule parse(String query, String uri) throws QueryException
      Parses the specified query.
      Parameters:
      query - query string
      uri - base URI (may be null)
      Returns:
      main module
      Throws:
      QueryException - query exception
    • parse

      public AModule parse(String query, boolean library, String uri) throws QueryException
      Parses the specified query.
      Parameters:
      query - query string
      library - library/main module
      uri - base URI (may be null)
      Returns:
      main module
      Throws:
      QueryException - query exception
    • parseMain

      public MainModule parseMain(String query, String uri) throws QueryException
      Parses the specified query.
      Parameters:
      query - query string
      uri - base URI (may be null)
      Returns:
      main module
      Throws:
      QueryException - query exception
    • parseMain

      public MainModule parseMain(String query, String uri, StaticContext sc) throws QueryException
      Parses the specified query.
      Parameters:
      query - query string
      uri - base URI (may be null)
      sc - static context (may be null)
      Returns:
      main module
      Throws:
      QueryException - query exception
    • parseLibrary

      public LibraryModule parseLibrary(String query, String uri) throws QueryException
      Parses the specified module.
      Parameters:
      query - query string
      uri - base URI (may be null)
      Returns:
      name of module
      Throws:
      QueryException - query exception
    • mainModule

      public void mainModule(MainModule rt)
      Sets the main module (root expression).
      Parameters:
      rt - main module
    • compile

      public void compile() throws QueryException
      Compiles and optimizes the expression.
      Throws:
      QueryException - query exception
    • iter

      public Iter iter() throws QueryException
      Returns a result iterator.
      Returns:
      result iterator
      Throws:
      QueryException - query exception
    • value

      public Value value() throws QueryException
      Returns the result.
      Returns:
      result iterator
      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 a reference to the updates container.
      Returns:
      updates container
    • addLocks

      public void addLocks()
      Description copied from class: Job
      Adds the strings (databases, special identifiers) for which locks need to be acquired.
      Overrides:
      addLocks in class Job
    • context

      public void context(Object value, String type, StaticContext sc) throws QueryException
      Binds the context value, using the same rules as for binding variables.
      Parameters:
      value - value to be bound
      type - type (may be null)
      sc - static context
      Throws:
      QueryException - query exception
    • context

      public void context(Value value, StaticContext sc)
      Binds the context value.
      Parameters:
      value - value to be bound
      sc - static context
    • bind

      public void bind(String name, Object value, String type, StaticContext sc) throws QueryException
      Binds a value to a global variable. 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.
      If the value is an XQuery Value, it is directly assigned. Otherwise, it is cast to the XQuery data model, using a Java/XQuery mapping.
      Parameters:
      name - name of variable
      value - value to be bound
      type - type (may be null)
      sc - static context
      Throws:
      QueryException - query exception
    • bind

      public void bind(String name, Value value, StaticContext sc) throws QueryException
      Binds a value to a global variable.
      Parameters:
      name - name of variable
      value - value to be bound
      sc - static context
      Throws:
      QueryException - query exception
    • bind

      public void bind(QNm name, Value value)
      Binds a value to a global variable.
      Parameters:
      name - name of variable
      value - value to be bound
    • evalInfo

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

      public String info()
      Returns info on query compilation and evaluation.
      Returns:
      query info
    • serParams

      public SerializerOptions serParams()
      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
    • plan

      public FElem plan(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.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • 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
    • dateTime

      public QueryDateTime dateTime() throws QueryException
      Initializes the static date and time context of a query if not done yet.
      Returns:
      self reference
      Throws:
      QueryException - query exception
    • toString

      public String toString()
      Overrides:
      toString in class Object