org.basex.query
Class QueryProcessor

java.lang.Object
  extended by org.basex.core.Proc
      extended by org.basex.query.QueryProcessor

public final class QueryProcessor
extends Proc

This class is an entry point for evaluating XQuery implementations.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
 QueryContext ctx
          Expression context.
 
Fields inherited from class org.basex.core.Proc
listen, updating
 
Constructor Summary
QueryProcessor(java.lang.String qu, Context cx)
          Default constructor.
 
Method Summary
 QueryProcessor bind(java.lang.String name, java.lang.Object value)
          Binds a value to a global variable.
 QueryProcessor bind(java.lang.String name, java.lang.Object value, java.lang.String type)
          Binds a value with the specified data type to a global variable.
 void close()
          Closes the processor.
 void compile()
          Compiles the query.
 QueryProcessor context(Nodes nodes)
          Binds an initial nodeset to the context item.
 QueryProcessor context(java.lang.Object value)
          Binds a value to the context item.
 QueryProcessor context(java.lang.Object value, java.lang.String type)
          Binds a value with the specified data type to the context item, using the same rules as for binding variables.
 void databases(LockResult lr)
          Adds the names of the databases that may be touched by the process.
 java.lang.String det()
          Returns short information on this process.
 Result execute()
          Evaluates the specified query and returns the result.
 Serializer getSerializer(java.io.OutputStream os)
          Returns a serializer for the given output stream.
 java.lang.String info()
          Returns query background information.
static boolean isLibrary(java.lang.String qu)
          Checks if the specified XQuery string is a library module.
 Iter iter()
          Returns a result iterator.
 void module(java.lang.String uri, java.lang.String file)
          Adds a module reference.
 QueryProcessor namespace(java.lang.String prefix, java.lang.String uri)
          Declares a namespace.
 void parse()
          Parses the query.
 FDoc plan()
          Returns a tree representation of the query plan.
 java.lang.String query()
          Returns the query string.
 Nodes queryNodes()
          Evaluates the specified query and returns the result nodes.
static java.lang.String removeComments(java.lang.String qu, int max)
          Removes comments from the specified string and returns the first characters of a query.
 java.lang.String tit()
          Returns short information on this process.
 java.lang.String toString()
           
 int updates()
          Returns the number of performed updates after query execution, or 0.
 Value value()
          Returns a result value.
 
Methods inherited from class org.basex.core.Proc
abort, checkStop, detail, listen, proc, prog, progress, registered, registered, startTimeout, stop, stopTimeout, title
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ctx

public final QueryContext ctx
Expression context.

Constructor Detail

QueryProcessor

public QueryProcessor(java.lang.String qu,
                      Context cx)
Default constructor.

Parameters:
qu - query to process
cx - database context
Method Detail

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 result iterator.

Returns:
result iterator
Throws:
QueryException - query exception

value

public Value value()
            throws QueryException
Returns a result value.

Returns:
result value
Throws:
QueryException - query exception

execute

public Result execute()
               throws QueryException
Evaluates the specified query and returns the result.

Returns:
result of query
Throws:
QueryException - query exception

bind

public QueryProcessor bind(java.lang.String name,
                           java.lang.Object value,
                           java.lang.String type)
                    throws QueryException
Binds a value with the specified data 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 data type, the value is interpreted according to the rules specified in JsonMapConverter.

Parameters:
name - name of variable
value - value to be bound
type - data type (may be null)
Returns:
self reference
Throws:
QueryException - query exception

bind

public QueryProcessor bind(java.lang.String name,
                           java.lang.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

context

public QueryProcessor context(java.lang.Object value)
                       throws QueryException
Binds a value to the context item.

Parameters:
value - value to be bound
Returns:
self reference
Throws:
QueryException - query exception

context

public QueryProcessor context(java.lang.Object value,
                              java.lang.String type)
                       throws QueryException
Binds a value with the specified data type to the context item, using the same rules as for binding variables.

Parameters:
value - value to be bound
type - data type (may be null)
Returns:
self reference
Throws:
QueryException - query exception

context

public QueryProcessor context(Nodes nodes)
Binds an initial nodeset to the context item.

Parameters:
nodes - node set
Returns:
self reference

namespace

public QueryProcessor namespace(java.lang.String prefix,
                                java.lang.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

getSerializer

public Serializer getSerializer(java.io.OutputStream os)
                         throws java.io.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:
java.io.IOException - query exception
QueryException - query exception

queryNodes

public Nodes queryNodes()
                 throws QueryException
Evaluates the specified query and returns the result nodes.

Returns:
result nodes
Throws:
QueryException - query exception

module

public void module(java.lang.String uri,
                   java.lang.String file)
Adds a module reference. Only called from the test APIs.

Parameters:
uri - module uri
file - file name

query

public java.lang.String query()
Returns the query string.

Returns:
query

close

public void close()
Closes the processor.


databases

public void databases(LockResult lr)
Description copied from class: Proc
Adds the names of the databases that may be touched by the process.

Overrides:
databases in class Proc
Parameters:
lr - Container for lock result to pass around

updates

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

Returns:
number of updates

info

public java.lang.String info()
Returns query background information.

Returns:
background information

isLibrary

public static boolean isLibrary(java.lang.String qu)
Checks if the specified XQuery string is a library module.

Parameters:
qu - query string
Returns:
result of check

removeComments

public static java.lang.String removeComments(java.lang.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

tit

public java.lang.String tit()
Description copied from class: Proc
Returns short information on this process. Can be overwritten to give more detailed information.

Overrides:
tit in class Proc
Returns:
header information

det

public java.lang.String det()
Description copied from class: Proc
Returns short information on this process.

Overrides:
det in class Proc
Returns:
header information

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object