Package org.basex.query
Class QueryProcessor
java.lang.Object
org.basex.core.jobs.Job
org.basex.query.QueryProcessor
- All Implemented Interfaces:
Closeable,AutoCloseable
This class is an entry point for evaluating XQuery strings.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal QueryContextExpression context.final StaticContextStatic context. -
Constructor Summary
ConstructorsConstructorDescriptionQueryProcessor(String query, String uri, Context ctx) Default constructor.QueryProcessor(String query, Context ctx) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLocks()Adds the strings (databases, special identifiers) for which locks need to be acquired.Binds a value to a global variable.Binds a value with the specified type to a global variable.Binds an XQuery value to a global variable.cache(int max) voidclose()voidcompile()Compiles the query.Binds the context value.Binds the context value with a specified type, using the same rules as forbinding variables.Binds the context value.Returns a serializer for the given output stream.info()Returns query information.static booleanChecks if the specified XQuery string is a library module.iter()Returns a memory-efficient result iterator.voidAdds a module reference.Declares a namespace.voidparse()Parses the query.plan()Returns a tree representation of the query plan.query()Returns the query string.static StringremoveComments(String qu, int max) Removes comments from the specified string and returns the first characters of a query.toString()intupdates()Returns the number of performed updates after query execution, or0.uriResolver(UriResolver resolver) Assigns a URI resolver.value()Evaluates the query and returns the resulting value.
-
Field Details
-
sc
Static context. -
qc
Expression context.
-
-
Constructor Details
-
QueryProcessor
Default constructor.- Parameters:
query- query stringctx- database context
-
QueryProcessor
Default constructor.- Parameters:
query- query stringuri- base uri (can benull)ctx- database context
-
-
Method Details
-
parse
Parses the query.- Throws:
QueryException- query exception
-
compile
Compiles the query.- Throws:
QueryException- query exception
-
iter
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
Evaluates the query and returns the resulting value.- Returns:
- result value
- Throws:
QueryException- query exception
-
cache
This function is called by the GUI; useiter()orvalue()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 typeDBNodes.- Parameters:
max- maximum number of results to cache (negative: return all values)- Returns:
- result of query
- Throws:
QueryException- query exception
-
bind
Binds a value with the specified type to a global variable. If the value is anExprinstance, 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 inJsonXQueryConverter.- Parameters:
name- name of variablevalue- value to be boundtype- type (may benull)- Returns:
- self reference
- Throws:
QueryException- query exception
-
bind
Binds a value to a global variable.- Parameters:
name- name of variablevalue- value to be bound- Returns:
- self reference
- Throws:
QueryException- query exception
-
bind
Binds an XQuery value to a global variable.- Parameters:
name- name of variablevalue- value to be bound- Returns:
- self reference
- Throws:
QueryException- query exception
-
context
Binds the context value.- Parameters:
value- value to be bound- Returns:
- self reference
- Throws:
QueryException- query exception
-
context
Binds the context value.- Parameters:
value- XQuery value to be bound- Returns:
- self reference
-
context
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
Declares a namespace. A namespace is undeclared if theuriis an empty string. The default element namespaces is set if theprefixis empty.- Parameters:
prefix- namespace prefixuri- namespace uri- Returns:
- self reference
- Throws:
QueryException- query exception
-
uriResolver
Assigns a URI resolver.- Parameters:
resolver- resolver- Returns:
- self reference
-
getSerializer
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
Adds a module reference. Only called from the test APIs.- Parameters:
uri- module urifile- file name
-
query
Returns the query string.- Returns:
- query
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
addLocks
public void addLocks()Description copied from class:JobAdds the strings (databases, special identifiers) for which locks need to be acquired. -
updates
public int updates()Returns the number of performed updates after query execution, or0.- Returns:
- number of updates
-
info
Returns query information.- Returns:
- query information
-
isLibrary
Checks if the specified XQuery string is a library module.- Parameters:
query- query string- Returns:
- result of check
-
removeComments
Removes comments from the specified string and returns the first characters of a query.- Parameters:
qu- query stringmax- maximum length of string to return- Returns:
- result
-
plan
Returns a tree representation of the query plan.- Returns:
- root node
-
toString
-