Class QueryProcessor

java.lang.Object
org.basex.core.jobs.Job
org.basex.query.QueryProcessor
All Implemented Interfaces:
Closeable, AutoCloseable

public final class QueryProcessor extends Job implements Closeable
This class is an entry point for evaluating XQuery strings.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Details

  • Constructor Details

    • QueryProcessor

      public QueryProcessor(String query, Context ctx)
      Default constructor.
      Parameters:
      query - query string
      ctx - database context
    • QueryProcessor

      public QueryProcessor(String query, String uri, Context ctx)
      Default constructor.
      Parameters:
      query - query string
      uri - base uri (can be null)
      ctx - database context
  • Method Details

    • parse

      public void parse() throws QueryException
      Parses the query.
      Throws:
      QueryException - query exception
    • compile

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

      public Iter iter() throws QueryException
      Returns a memory-efficient result iterator. The query will only be fully evaluated if all items of this iterator are requested.
      Returns:
      result iterator
      Throws:
      QueryException - query exception
    • value

      public Value value() throws QueryException
      Evaluates the query and returns the resulting value.
      Returns:
      result value
      Throws:
      QueryException - query exception
    • cache

      public Value cache(int max) throws QueryException
      This function is called by the GUI; use iter() or value() instead. Caches and returns the result of the specified query. If all nodes are of the same database instance, the returned value will be of type DBNodes.
      Parameters:
      max - maximum number of results to cache (negative: return all values)
      Returns:
      result of query
      Throws:
      QueryException - query exception
    • bind

      public QueryProcessor bind(String name, Object value, String type) throws QueryException
      Binds a value with the specified type to a global variable. If the value is an Expr instance, it is directly assigned. Otherwise, it is first cast to the appropriate XQuery type. If "json" is specified as type, the value is interpreted according to the rules specified in JsonXQueryConverter.
      Parameters:
      name - name of variable
      value - value to be bound
      type - type (may be null)
      Returns:
      self reference
      Throws:
      QueryException - query exception
    • bind

      public QueryProcessor bind(String name, Object value) throws QueryException
      Binds a value to a global variable.
      Parameters:
      name - name of variable
      value - value to be bound
      Returns:
      self reference
      Throws:
      QueryException - query exception
    • bind

      public QueryProcessor bind(String name, Value value) throws QueryException
      Binds an XQuery value to a global variable.
      Parameters:
      name - name of variable
      value - value to be bound
      Returns:
      self reference
      Throws:
      QueryException - query exception
    • context

      public QueryProcessor context(Object value) throws QueryException
      Binds the context value.
      Parameters:
      value - value to be bound
      Returns:
      self reference
      Throws:
      QueryException - query exception
    • context

      public QueryProcessor context(Value value)
      Binds the context value.
      Parameters:
      value - XQuery value to be bound
      Returns:
      self reference
    • context

      public QueryProcessor context(Object value, String type) throws QueryException
      Binds the context value with a specified type, using the same rules as for binding variables.
      Parameters:
      value - value to be bound
      type - type (may be null)
      Returns:
      self reference
      Throws:
      QueryException - query exception
    • namespace

      public QueryProcessor namespace(String prefix, String uri) throws QueryException
      Declares a namespace. A namespace is undeclared if the uri is an empty string. The default element namespaces is set if the prefix is empty.
      Parameters:
      prefix - namespace prefix
      uri - namespace uri
      Returns:
      self reference
      Throws:
      QueryException - query exception
    • uriResolver

      public QueryProcessor uriResolver(UriResolver resolver)
      Assigns a URI resolver.
      Parameters:
      resolver - resolver
      Returns:
      self reference
    • getSerializer

      public Serializer getSerializer(OutputStream os) throws IOException, QueryException
      Returns a serializer for the given output stream. Optional output declarations within the query will be included in the serializer instance.
      Parameters:
      os - output stream
      Returns:
      serializer instance
      Throws:
      IOException - query exception
      QueryException - query exception
    • module

      public void module(String uri, String file)
      Adds a module reference. Only called from the test APIs.
      Parameters:
      uri - module uri
      file - file name
    • query

      public String query()
      Returns the query string.
      Returns:
      query
    • close

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

      public int updates()
      Returns the number of performed updates after query execution, or 0.
      Returns:
      number of updates
    • info

      public String info()
      Returns query information.
      Returns:
      query information
    • isLibrary

      public static boolean isLibrary(String query)
      Checks if the specified XQuery string is a library module.
      Parameters:
      query - query string
      Returns:
      result of check
    • removeComments

      public static String removeComments(String qu, int max)
      Removes comments from the specified string and returns the first characters of a query.
      Parameters:
      qu - query string
      max - maximum length of string to return
      Returns:
      result
    • plan

      public FDoc plan()
      Returns a tree representation of the query plan.
      Returns:
      root node
    • toString

      public String toString()
      Overrides:
      toString in class Object