Package org.basex.query
Class QueryContext
- java.lang.Object
-
- org.basex.core.jobs.Job
-
- org.basex.query.QueryContext
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class QueryContext extends Job implements Closeable
This class organizes both static and dynamic properties that are specific to a single query.- Author:
- BaseX Team 2005-22, BSD License, Christian Gruen
-
-
Field Summary
Fields Modifier and Type Field Description TokenObjMap<Collation>
collations
Available collations.Context
context
Database context.ContextScope
contextScope
Context scope.boolean
finalContext
Indicates if context scope exists and is final.QueryFocus
focus
Current query focus.FTLexer
ftLexer
Current full-text lexer.int
ftPos
Full-text token positions (needed for highlighting full-text results).FTPosData
ftPosData
Full-text position data (needed for highlighting full-text results).StaticFuncs
functions
Functions.QueryInfo
info
Query info.LockList
locks
User-defined locks.MainModule
main
Main module (root expression).int
maxCalls
Maximum number of successive tail calls (will be set before compilation).TokenMap
modParsed
Parsed modules, containing the file path and module uri.QueryContext
parent
Parent query context.QueryResources
resources
Query resources.boolean
scoring
Scoring flag.QueryStack
stack
The evaluation stack.int
tailCalls
Number of successive tail calls.QueryThreads
threads
Query threads.Updates
updates
Update container; will be created if the first update is evaluated.int
varIDs
Counter for variable IDs.Variables
vars
Static variables.
-
Constructor Summary
Constructors Constructor Description QueryContext(Context context)
Constructor.QueryContext(Context context, QueryContext parent, QueryResources resources, QueryInfo info)
Constructor.QueryContext(QueryContext parent)
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
assign(StaticFunc func, Expr... args)
Creates a function call for the specified function and assigns it as root expression.void
bind(String name, Object value, String type, StaticContext sc)
Binds a value to a global variable or the context value.void
close()
void
compile()
Compiles the expression.QueryDateTime
dateTime()
Initializes the static date and time context of a query if not done yet.void
evalInfo(String string)
Adds some evaluation info.FTOpt
ftOpt()
Returns the current full-text options.void
ftOpt(FTOpt opt)
Assigns full-text options.Value
get(Var var)
Gets the value currently bound to the given variable.Iter
iter()
Returns a result iterator.Item
next(Iter iter)
Checks if evaluation has been stopped and returns the next item of an iterator.void
optimize()
Optimizes the expression.SerializerOptions
parameters()
Returns query-specific or default serialization parameters.AModule
parse(String query, String uri)
Parses the specified query.LibraryModule
parseLibrary(String query, String uri)
Parses the specified module.MainModule
parseMain(String query, String uri)
Parses the specified query.MainModule
parseMain(String query, String uri, StaticContext sc)
Parses the specified query and assigns the root expression.Value[]
pollTailArgs()
Returns and clears registered arguments of a tail-called function.XQFunction
pollTailCall()
Returns and clears the currently registered tail-call function.void
registerTailCall(XQFunction fn, Value[] arg)
Registers a tail-called function and its arguments to this query context.void
set(Var var, Value value)
Binds an expression to a local variable.String
shortInfo()
Returns short progress information.StringList
suggest(String query, Data data)
Collects suggestions for completing a path expression.String
toString()
FElem
toXml(boolean full)
Creates and returns an XML query plan (expression tree) for this query.Updates
updates()
Returns the updates container.void
updating()
Indicates that the query contains updating expressions.Value
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 Detail
-
stack
public final QueryStack stack
The evaluation stack.
-
vars
public final Variables vars
Static variables.
-
functions
public final StaticFuncs functions
Functions.
-
resources
public final QueryResources resources
Query resources.
-
parent
public final QueryContext parent
Parent query context.
-
context
public final Context context
Database context.
-
info
public final QueryInfo info
Query info.
-
threads
public final QueryThreads threads
Query threads.
-
locks
public final LockList locks
User-defined locks.
-
focus
public QueryFocus focus
Current query focus.
-
updates
public Updates updates
Update container; will be created if the first update is evaluated.
-
ftPosData
public FTPosData ftPosData
Full-text position data (needed for highlighting full-text results).
-
ftLexer
public FTLexer ftLexer
Current full-text lexer.
-
ftPos
public int ftPos
Full-text token positions (needed for highlighting full-text results).
-
scoring
public boolean scoring
Scoring flag.
-
collations
public TokenObjMap<Collation> collations
Available collations.
-
tailCalls
public int tailCalls
Number of successive tail calls.
-
maxCalls
public int maxCalls
Maximum number of successive tail calls (will be set before compilation).
-
varIDs
public int varIDs
Counter for variable IDs.
-
modParsed
public final TokenMap modParsed
Parsed modules, containing the file path and module uri.
-
main
public MainModule main
Main module (root expression).
-
contextScope
public ContextScope contextScope
Context scope.
-
finalContext
public boolean finalContext
Indicates if context scope exists and is final.
-
-
Constructor Detail
-
QueryContext
public QueryContext(QueryContext parent)
Constructor.- Parameters:
parent
- parent context
-
QueryContext
public QueryContext(Context context)
Constructor.- Parameters:
context
- database context
-
QueryContext
public QueryContext(Context context, QueryContext parent, QueryResources resources, QueryInfo info)
Constructor.- Parameters:
context
- database contextparent
- parent context (can benull
)info
- query info (can benull
)resources
- resources (can benull
)
-
-
Method Detail
-
parse
public AModule parse(String query, String uri) throws QueryException
Parses the specified query.- Parameters:
query
- query stringuri
- base URI (can benull
)- Returns:
- module
- Throws:
QueryException
- query exception
-
suggest
public StringList suggest(String query, Data data)
Collects suggestions for completing a path expression.- Parameters:
query
- query stringdata
- data reference- Returns:
- list of suggestions, followed by valid input string
-
parseMain
public MainModule parseMain(String query, String uri) throws QueryException
Parses the specified query.- Parameters:
query
- query stringuri
- base URI (can benull
)- Returns:
- main module
- Throws:
QueryException
- query exception
-
parseMain
public MainModule parseMain(String query, String uri, StaticContext sc) throws QueryException
Parses the specified query and assigns the root expression.- Parameters:
query
- query stringuri
- base URI (can benull
)sc
- static context (can benull
)- Returns:
- main module
- Throws:
QueryException
- query exception
-
parseLibrary
public LibraryModule parseLibrary(String query, String uri) throws QueryException
Parses the specified module.- Parameters:
query
- query stringuri
- base URI (can benull
)- Returns:
- library module
- Throws:
QueryException
- query exception
-
assign
public void assign(StaticFunc func, Expr... args) throws QueryException
Creates a function call for the specified function and assigns it as root expression.- Parameters:
func
- user-defined functionargs
- arguments- Throws:
QueryException
- query exception
-
compile
public void compile() throws QueryException
Compiles the expression. Performs static optimizations.- Throws:
QueryException
- query exception
-
optimize
public void optimize() throws QueryException
Optimizes the expression. Performs dynamic optimizations.- 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 the result.- Returns:
- result iterator
- Throws:
QueryException
- query exception
-
next
public Item next(Iter iter) throws QueryException
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
public Updates updates()
Returns the updates container.- Returns:
- updates container
-
addLocks
public void addLocks()
Description copied from class:Job
Collects lock strings (databases, special identifiers) when registering a query.
-
bind
public void bind(String name, Object value, String type, StaticContext sc) 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. 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.
- Parameters:
name
- name of variable; context value if empty string ornull
value
- value to be bound (object or XQueryValue
)type
- type (may benull
)sc
- static context- Throws:
QueryException
- query exception
- If
-
evalInfo
public void evalInfo(String string)
Adds some evaluation info.- Parameters:
string
- evaluation info
-
parameters
public SerializerOptions parameters()
Returns query-specific or default serialization parameters.- Returns:
- serialization parameters
-
ftOpt
public FTOpt ftOpt()
Returns the current full-text options. Creates a new instance if called for the first time.- Returns:
- full-text options
-
ftOpt
public void ftOpt(FTOpt opt)
Assigns full-text options.- Parameters:
opt
- full-text options
-
toXml
public FElem toXml(boolean full)
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
shortInfo
public String shortInfo()
Description copied from class:Job
Returns short progress information. Can be overwritten to give more specific feedback.
-
get
public Value get(Var var)
Gets the value currently bound to the given variable.- Parameters:
var
- variable- Returns:
- bound value
-
set
public void set(Var var, Value value) throws QueryException
Binds an expression to a local variable.- Parameters:
var
- variablevalue
- expression to be bound- Throws:
QueryException
- exception
-
registerTailCall
public void registerTailCall(XQFunction fn, Value[] arg)
Registers a tail-called function and its arguments to this query context.- Parameters:
fn
- function to callarg
- arguments to pass tofn
-
pollTailCall
public XQFunction pollTailCall()
Returns and clears the currently registered tail-call function.- Returns:
- function to call if present,
null
otherwise
-
pollTailArgs
public Value[] pollTailArgs()
Returns and clears registered arguments of a tail-called function.- Returns:
- argument values if a tail call was registered,
null
otherwise
-
dateTime
public QueryDateTime dateTime() throws QueryException
Initializes the static date and time context of a query if not done yet.- Returns:
- self reference
- Throws:
QueryException
- query exception
-
-