Package org.basex.query
Class QueryContext
java.lang.Object
org.basex.core.jobs.Job
org.basex.query.QueryContext
- All Implemented Interfaces:
Closeable,AutoCloseable
This class organizes both static and dynamic properties that are specific to a
single query.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionAvailable collations.final ContextDatabase context.Initial context value.Current date/time values.Current context value.Current full-text lexer.intFull-text token positions (needed for highlighting full-text results).Full-text position data (needed for highlighting full-text results).final StaticFuncsFunctions.final QueryInfoQuery info.final LockListUser-defined locks.intMaximum number of successive tail calls (will be set before compilation).final TokenMapParsed modules, containing the file path and module uri.final QueryContextParent query context.Query resources.Root expression of the query.booleanScoring flag.final QueryStackThe evaluation stack.intNumber of successive tail calls.final QueryThreadsQuery threads.Update container; will be created if the first update is evaluated.intCounter for variable IDs.final VariablesStatic variables. -
Constructor Summary
ConstructorsConstructorDescriptionQueryContext(Context context) Constructor.QueryContext(QueryContext parent) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLocks()Adds the strings (databases, special identifiers) for which locks need to be acquired.voidbind(String name, Object value, String type, StaticContext sc) Binds a value to a global variable.voidbind(String name, Value value, StaticContext sc) Binds a value to a global variable.voidBinds a value to a global variable.voidclose()voidcompile()Compiles and optimizes the expression.voidcontext(Object value, String type, StaticContext sc) Binds the context value, using the same rules as forbinding variables.voidcontext(Value value, StaticContext sc) Binds the context value.dateTime()Initializes the static date and time context of a query if not done yet.voidAdds some evaluation info.ftOpt()Returns the current full-text options.voidAssigns full-text options.Gets the value currently bound to the given variable.info()Returns info on query compilation and evaluation.iter()Returns a result iterator.voidmainModule(MainModule rt) Sets the main module (root expression).Checks if evaluation has been stopped and returns the next item of an iterator.Parses the specified query.Parses the specified query.parseLibrary(String query, String uri) Parses the specified module.Parses the specified query.parseMain(String query, String uri, StaticContext sc) Parses the specified query.plan(boolean full) Creates and returns an XML query plan (expression tree) for this query.Value[]Returns and clears registered arguments of a tail-called function.Returns and clears the currently registered tail-call function.voidregisterTailCall(XQFunction fn, Value[] arg) Registers a tail-called function and its arguments to this query context.Returns query-specific or default serialization parameters.voidBinds an expression to a local variable.Returns short progress information.toString()updates()Returns a reference to the updates container.voidupdating()Indicates that the query contains updating expressions.value()Returns the result.Methods inherited from class org.basex.core.jobs.Job
active, checkStop, detailedInfo, jc, memory, popJob, progressInfo, pushJob, register, state, stop, stopped, timeout, unregister
-
Field Details
-
stack
The evaluation stack. -
vars
Static variables. -
funcs
Functions. -
parent
Parent query context. -
info
Query info. -
context
Database context. -
resources
Query resources. -
updates
Update container; will be created if the first update is evaluated. -
threads
Query threads. -
focus
Current context value. -
dateTime
Current date/time values. -
ftPosData
Full-text position data (needed for highlighting full-text results). -
ftLexer
Current full-text lexer. -
ftPos
public int ftPosFull-text token positions (needed for highlighting full-text results). -
scoring
public boolean scoringScoring flag. -
collations
Available collations. -
locks
User-defined locks. -
tailCalls
public int tailCallsNumber of successive tail calls. -
maxCalls
public int maxCallsMaximum number of successive tail calls (will be set before compilation). -
varIDs
public int varIDsCounter for variable IDs. -
modParsed
Parsed modules, containing the file path and module uri. -
ctxItem
Initial context value. -
root
Root expression of the query.
-
-
Constructor Details
-
QueryContext
Constructor.- Parameters:
parent- parent context
-
QueryContext
Constructor.- Parameters:
context- database context
-
-
Method Details
-
parse
Parses the specified query.- Parameters:
query- query stringuri- base URI (may benull)- Returns:
- main module
- Throws:
QueryException- query exception
-
parse
Parses the specified query.- Parameters:
query- query stringlibrary- library/main moduleuri- base URI (may benull)- Returns:
- main module
- Throws:
QueryException- query exception
-
parseMain
Parses the specified query.- Parameters:
query- query stringuri- base URI (may benull)- Returns:
- main module
- Throws:
QueryException- query exception
-
parseMain
Parses the specified query.- Parameters:
query- query stringuri- base URI (may benull)sc- static context (may benull)- Returns:
- main module
- Throws:
QueryException- query exception
-
parseLibrary
Parses the specified module.- Parameters:
query- query stringuri- base URI (may benull)- Returns:
- name of module
- Throws:
QueryException- query exception
-
mainModule
Sets the main module (root expression).- Parameters:
rt- main module
-
compile
Compiles and optimizes the expression.- Throws:
QueryException- query exception
-
iter
Returns a result iterator.- Returns:
- result iterator
- Throws:
QueryException- query exception
-
value
Returns the result.- Returns:
- result iterator
- Throws:
QueryException- query exception
-
next
Checks if evaluation has been stopped and returns the next item of an iterator.- Parameters:
iter- iterator- Returns:
- item or
null - Throws:
QueryException- query exception
-
updates
Returns a reference to the updates container.- Returns:
- updates container
-
addLocks
public void addLocks()Description copied from class:JobAdds the strings (databases, special identifiers) for which locks need to be acquired. -
context
Binds the context value, using the same rules as forbinding variables.- Parameters:
value- value to be boundtype- type (may benull)sc- static context- Throws:
QueryException- query exception
-
context
Binds the context value.- Parameters:
value- value to be boundsc- static context
-
bind
Binds a value to a global variable. The specified type is interpreted as follows:- If
"json"is specified, the value is converted according to the rules specified inJsonXQueryConverter. - Otherwise, the type is cast to the specified XDM type.
Value, it is directly assigned. Otherwise, it is cast to the XQuery data model, using a Java/XQuery mapping.- Parameters:
name- name of variablevalue- value to be boundtype- type (may benull)sc- static context- Throws:
QueryException- query exception
- If
-
bind
Binds a value to a global variable.- Parameters:
name- name of variablevalue- value to be boundsc- static context- Throws:
QueryException- query exception
-
bind
Binds a value to a global variable.- Parameters:
name- name of variablevalue- value to be bound
-
evalInfo
Adds some evaluation info.- Parameters:
string- evaluation info
-
info
Returns info on query compilation and evaluation.- Returns:
- query info
-
serParams
Returns query-specific or default serialization parameters.- Returns:
- serialization parameters
-
ftOpt
Returns the current full-text options. Creates a new instance if called for the first time.- Returns:
- full-text options
-
ftOpt
Assigns full-text options.- Parameters:
opt- full-text options
-
plan
Creates and returns an XML query plan (expression tree) for this query.- Parameters:
full- include comprehensive information- Returns:
- query plan
-
updating
public void updating()Indicates that the query contains updating expressions. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
shortInfo
Description copied from class:JobReturns short progress information. Can be overwritten to give more specific feedback. -
get
Gets the value currently bound to the given variable.- Parameters:
var- variable- Returns:
- bound value
-
set
Binds an expression to a local variable.- Parameters:
var- variablevalue- expression to be bound- Throws:
QueryException- exception
-
registerTailCall
Registers a tail-called function and its arguments to this query context.- Parameters:
fn- function to callarg- arguments to pass tofn
-
pollTailCall
Returns and clears the currently registered tail-call function.- Returns:
- function to call if present,
nullotherwise
-
pollTailArgs
Returns and clears registered arguments of a tail-called function.- Returns:
- argument values if a tail call was registered,
nullotherwise
-
dateTime
Initializes the static date and time context of a query if not done yet.- Returns:
- self reference
- Throws:
QueryException- query exception
-
toString
-