Class 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-22, BSD License, Christian Gruen
    • Constructor Detail

      • 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,
                              QueryInfo info)
        Default constructor.
        Parameters:
        query - query string
        uri - base uri (can be null)
        ctx - database context
        info - query info (can be null)
    • Method Detail

      • 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 void cache​(AQuery cmd,
                          int max)
                   throws QueryException
        This function is called by the GUI. Caches the result of the specified query. If all nodes are of the same database instance, the cached value will be of type DBNodes.
        Parameters:
        cmd - query command
        max - maximum number of items to cache (negative: return full result)
        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
      • serializer

        public Serializer serializer​(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
      • addLocks

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

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

        public FElem toXml()
        Returns a query plan as XML.
        Returns:
        query plan