Package org.basex.query
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-22, BSD License, Christian Gruen
-
-
Field Summary
Fields Modifier and Type Field Description QueryContext
qc
Expression context.StaticContext
sc
Static context.
-
Constructor Summary
Constructors Constructor Description QueryProcessor(String query, String uri, Context ctx, QueryInfo info)
Default constructor.QueryProcessor(String query, Context ctx)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLocks()
Collects lock strings (databases, special identifiers) when registering a query.void
cache(AQuery cmd, int max)
This function is called by the GUI.void
close()
void
compile()
Compiles the query.QueryProcessor
context(Object value)
Binds the context value.QueryProcessor
context(Object value, String type)
Binds the context value with a specified type, using the same rules as forbinding variables
.Iter
iter()
Returns a memory-efficient result iterator.void
module(String uri, String file)
Adds a module reference.QueryProcessor
namespace(String prefix, String uri)
Declares a namespace.void
optimize()
Optimizes the query.void
parse()
Parses the query.Serializer
serializer(OutputStream os)
Returns a serializer for the given output stream.String
toString()
FElem
toXml()
Returns a query plan as XML.int
updates()
Returns the number of performed updates after query execution, or0
.QueryProcessor
uriResolver(UriResolver resolver)
Assigns a URI resolver.Value
value()
Evaluates the query and returns the resulting value.QueryProcessor
variable(String name, Object value)
Binds a value to a global variable.QueryProcessor
variable(String name, Object value, String type)
Binds a value to a global variable or the context value.
-
-
-
Field Detail
-
sc
public final StaticContext sc
Static context.
-
qc
public final QueryContext qc
Expression 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
-
optimize
public void optimize() throws QueryException
Optimizes 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 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 typeDBNodes
.- Parameters:
cmd
- query commandmax
- maximum number of items to cache (negative: return full result)- Throws:
QueryException
- query exception
-
variable
public QueryProcessor variable(String name, Object value, String type) 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.- Parameters:
name
- name of variable; context value if empty string ornull
value
- value to be bound (object or XQueryValue
)type
- type (may benull
)- Returns:
- self reference
- Throws:
QueryException
- query exception- See Also:
QueryContext.bind(String, Object, String, StaticContext)
-
variable
public QueryProcessor variable(String name, Object value) throws QueryException
Binds a value to a global variable.- Parameters:
name
- name of variablevalue
- 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(Object value, String type) throws QueryException
Binds the context value with a specified type, using the same rules as forbinding variables
.- Parameters:
value
- value to be boundtype
- type (may benull
)- 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 theuri
is an empty string. The default element namespaces is set if theprefix
is empty.- Parameters:
prefix
- namespace prefixuri
- 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 exceptionQueryException
- query exception
-
module
public void module(String uri, String file)
Adds a module reference. Only called from the test APIs.- Parameters:
uri
- module urifile
- file name
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
addLocks
public void addLocks()
Description copied from class:Job
Collects lock strings (databases, special identifiers) when registering a query.
-
updates
public int updates()
Returns the number of performed updates after query execution, or0
.- Returns:
- number of updates
-
toXml
public FElem toXml()
Returns a query plan as XML.- Returns:
- query plan
-
-