org.basex.query
Class QueryContext

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

public final class QueryContext
extends Proc

This class organizes both static and dynamic properties that are specific to a single query.

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

Field Summary
 java.util.HashMap<QNm,Expr> bindings
          Externally bound variables.
 TokenObjMap<Collation> collations
          Available collations.
 Context context
          Database context.
 MainModule ctxItem
          Initial context value.
 Item date
          Current Date.
 StringList dbOptions
          Local options (key/value pairs), set by option declarations.
 Item dtm
          Current DateTime.
 byte ftoknum
          Full-text token counter (needed for highlighting of full-text results).
 FTPosData ftpos
          Full-text position data (needed for highlighting of full-text results).
 FTLexer fttoken
          Current full-text token.
 StaticFuncs funcs
          Functions.
 java.util.HashMap<java.lang.String,java.lang.Object> globalOpt
          Global options (will be set after query execution).
 java.lang.Object http
          HTTP context.
 boolean leaf
          Compilation flag: current node has leaves.
 int maxCalls
          Maximum number of successive tail calls.
 ModuleLoader modules
          Module loader.
 ValueBuilder output
          Pending output.
 long pos
          Current context position.
 StringList readLocks
          Strings to lock defined by lock:read option.
 QueryResources resource
          Query resources.
 StaticContext sc
          Static context of an expression.
 long size
          Current context size.
 QueryStack stack
          The evaluation stack.
 java.util.HashMap<java.lang.String,IO> stop
          Cached stop word files.
 int tailCalls
          Number of successive tail calls.
 java.util.HashMap<java.lang.String,IO> thes
          Cached thesaurus files.
 Item time
          Current Time.
 Updates updates
          Pending updates.
 Value value
          Current context value.
 int varIDs
          Counter for variable IDs.
 Variables vars
          Static variables.
 StringList writeLocks
          Strings to lock defined by lock:write option.
 Item zone
          Current timezone.
 
Fields inherited from class org.basex.core.Proc
listen, updating
 
Constructor Summary
QueryContext(Context ctx)
          Constructor.
 
Method Summary
 void analyze()
          Compiles all used functions and the root expression.
 void bind(java.lang.String name, java.lang.Object val, java.lang.String type)
          Binds a value to a global variable.
 void close()
          Closes the query context.
 void compile()
          Compiles and optimizes the expression.
 void compInfo(java.lang.String string, java.lang.Object... ext)
          Adds some compilation info.
 void context(java.lang.Object val, java.lang.String type)
          Binds a value to the context item, using the same rules as for binding variables.
 Data data()
          Returns the current data reference of the context value, or null.
 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.
 void evalInfo(java.lang.String string)
          Adds some evaluation info.
 FTOpt ftOpt()
          Returns the current full-text options.
 void ftOpt(FTOpt opt)
          Sets full-text options.
 Value get(Var var)
          Gets the value currently bound to the given variable.
 java.lang.String info()
          Returns info on query compilation and evaluation.
 QueryContext initDateTime()
          Initializes the static date and time context of a query if not done yet.
 Iter iter()
          Returns a result iterator.
 Iter iter(Expr e)
          Evaluates the specified expression and returns an iterator.
 JDBCConnections jdbc()
          Returns JDBC connections.
 void mainModule(MainModule rt)
          Sets the main module (root expression).
 LibraryModule parseLibrary(java.lang.String qu, java.lang.String path)
          Parses the specified module.
 MainModule parseMain(java.lang.String qu, java.lang.String path)
          Parses the specified query.
 double prog()
          Returns a progress value (0 - 1).
 SerializerProp serParams(boolean optional)
          Returns the serialization parameters used for and specified by this query.
 ClientSessions sessions()
          Returns client sessions.
 void set(Var vr, Value vl, InputInfo ii)
          Binds an expression to a local variable.
 java.lang.String tit()
          Returns short information on this process.
 Value update()
          Performs updates.
 void updating(boolean up)
          Sets the updating flag.
 Value value()
          Returns the result value.
 Value value(Expr expr)
          Evaluates the specified expression and returns an iterator.
 
Methods inherited from class org.basex.core.Proc
abort, checkStop, detail, listen, proc, progress, registered, registered, startTimeout, stop, stopTimeout, title
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sc

public StaticContext sc
Static context of an expression.


vars

public final Variables vars
Static variables.


funcs

public final StaticFuncs funcs
Functions.


bindings

public final java.util.HashMap<QNm,Expr> bindings
Externally bound variables.


resource

public final QueryResources resource
Query resources.


context

public final Context context
Database context.


http

public java.lang.Object http
HTTP context.


stop

public java.util.HashMap<java.lang.String,IO> stop
Cached stop word files.


thes

public java.util.HashMap<java.lang.String,IO> thes
Cached thesaurus files.


dbOptions

public final StringList dbOptions
Local options (key/value pairs), set by option declarations.


globalOpt

public final java.util.HashMap<java.lang.String,java.lang.Object> globalOpt
Global options (will be set after query execution).


value

public Value value
Current context value.


pos

public long pos
Current context position.


size

public long size
Current context size.


collations

public TokenObjMap<Collation> collations
Available collations.


fttoken

public FTLexer fttoken
Current full-text token.


ftpos

public FTPosData ftpos
Full-text position data (needed for highlighting of full-text results).


ftoknum

public byte ftoknum
Full-text token counter (needed for highlighting of full-text results).


date

public Item date
Current Date.


dtm

public Item dtm
Current DateTime.


time

public Item time
Current Time.


zone

public Item zone
Current timezone.


readLocks

public StringList readLocks
Strings to lock defined by lock:read option.


writeLocks

public StringList writeLocks
Strings to lock defined by lock:write option.


updates

public Updates updates
Pending updates.


output

public final ValueBuilder output
Pending output.


leaf

public boolean leaf
Compilation flag: current node has leaves.


tailCalls

public int tailCalls
Number of successive tail calls.


maxCalls

public final int maxCalls
Maximum number of successive tail calls.


varIDs

public int varIDs
Counter for variable IDs.


ctxItem

public MainModule ctxItem
Initial context value.


modules

public final ModuleLoader modules
Module loader.


stack

public final QueryStack stack
The evaluation stack.

Constructor Detail

QueryContext

public QueryContext(Context ctx)
Constructor.

Parameters:
ctx - database context
Method Detail

parseMain

public MainModule parseMain(java.lang.String qu,
                            java.lang.String path)
                     throws QueryException
Parses the specified query.

Parameters:
qu - input query
path - file path (may be null)
Returns:
main module
Throws:
QueryException - query exception

parseLibrary

public LibraryModule parseLibrary(java.lang.String qu,
                                  java.lang.String path)
                           throws QueryException
Parses the specified module.

Parameters:
qu - input query
path - file path (may be null)
Returns:
name of module
Throws:
QueryException - query exception

mainModule

public void mainModule(MainModule rt)
Sets the main module (root expression).

Parameters:
rt - main module

compile

public void compile()
             throws QueryException
Compiles and optimizes the expression.

Throws:
QueryException - query exception

analyze

public void analyze()
             throws QueryException
Compiles all used functions and the root expression.

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 value.

Returns:
result value
Throws:
QueryException - query exception

update

public Value update()
             throws QueryException
Performs updates.

Returns:
resulting value
Throws:
QueryException - query exception

iter

public Iter iter(Expr e)
          throws QueryException
Evaluates the specified expression and returns an iterator.

Parameters:
e - expression to be evaluated
Returns:
iterator
Throws:
QueryException - query exception

value

public Value value(Expr expr)
            throws QueryException
Evaluates the specified expression and returns an iterator.

Parameters:
expr - expression to be evaluated
Returns:
iterator
Throws:
QueryException - query exception

data

public Data data()
Returns the current data reference of the context value, or null.

Returns:
data reference

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

context

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

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

bind

public void bind(java.lang.String name,
                 java.lang.Object val,
                 java.lang.String type)
          throws QueryException
Binds a value to a global variable. The specified type is interpreted as follows: If the value is an XQuery value Value, it is directly assigned. Otherwise, it is cast to the XQuery data model, using a Java/XQuery mapping.

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

compInfo

public void compInfo(java.lang.String string,
                     java.lang.Object... ext)
Adds some compilation info.

Parameters:
string - evaluation info
ext - text text extensions

evalInfo

public void evalInfo(java.lang.String string)
Adds some evaluation info.

Parameters:
string - evaluation info

info

public java.lang.String info()
Returns info on query compilation and evaluation.

Returns:
query info

jdbc

public JDBCConnections jdbc()
Returns JDBC connections.

Returns:
jdbc connections

sessions

public ClientSessions sessions()
Returns client sessions.

Returns:
client session

serParams

public SerializerProp serParams(boolean optional)
Returns the serialization parameters used for and specified by this query.

Parameters:
optional - if true, a null reference is returned if no parameters have been specified
Returns:
serialization parameters

ftOpt

public FTOpt ftOpt()
Returns the current full-text options. Creates a new instance if called first.

Returns:
full-text options

ftOpt

public void ftOpt(FTOpt opt)
Sets full-text options.

Parameters:
opt - full-text options

updating

public void updating(boolean up)
Sets the updating flag.

Parameters:
up - updating flag

close

public void close()
Closes the query context.


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

prog

public double prog()
Description copied from class: Proc
Returns a progress value (0 - 1). Can be overwritten to give more detailed information.

Overrides:
prog in class Proc
Returns:
header information

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 vr,
                Value vl,
                InputInfo ii)
         throws QueryException
Binds an expression to a local variable.

Parameters:
vr - variable
vl - expression to be bound
ii - input info
Throws:
QueryException - exception

initDateTime

public QueryContext initDateTime()
                          throws QueryException
Initializes the static date and time context of a query if not done yet.

Returns:
self reference
Throws:
QueryException - query exception