Package org.basex.core
Class Context
java.lang.Object
org.basex.core.Context
This class serves as a central database context.
It references the currently opened database, options, client sessions, users and other meta data.
Next, the instance of this class will be passed on to all operations, as it organizes concurrent
data access, ensuring that no job will concurrently write to the same data instances.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ClientBlockerBlocked clients.Copied nodesnullif database is closed..final DatabasesDatabases list.final DatasOpened databases.intFocused node.final JobPoolJob pool.final LockingLocking.final LogLog.Marked nodes.final MainOptionsOptions.final EXPathRepoEXPath package repository.final SessionsClient sessions.final StaticOptionsStatic options.final UsersUsers. -
Constructor Summary
ConstructorsConstructorDescriptionContext()Default constructor, which is usually called once in the lifetime of a project.Context(boolean file) Default constructor, which is usually called once in the lifetime of a project.Constructor, called by clients, and adopting the variables of the specified context.Context(Context ctx, ClientInfo client) Constructor, called by clients, and adopting the variables of the main context.Context(StaticOptions soptions) Private constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns the host and port of a client.Returns the name of the current client or user.voidclose()Closes the database context.voidcloseDB()Closes the current database context.current()Returns the current node context.voidSets the current node context.data()Returns the current data reference.getExternal(Class<?> clz) Returns an external object.voidInvalidates the current node set.listDBs()Returns all databases for which the current user has read access.Returns all databases for which the current user has read access.voidSets the specified data instance as current database.booleanChecks if the current user has the specified permission.booleanChecks if the specified database is pinned.booleanroot()Returnstrueif a data reference exists and if the current node set contains all documents.voidSets the current context and marked node set and resets the focus.voidsetExternal(Object object) Assigns an external object.user()Returns the user of this context.voidSets the user of this context.
-
Field Details
-
blocker
Blocked clients. -
jobs
Job pool. -
options
Options. -
soptions
Static options. -
sessions
Client sessions. -
datas
Opened databases. -
users
Users. -
repo
EXPath package repository. -
databases
Databases list. -
log
Log. -
locking
Locking. -
marked
Marked nodes.nullif database is closed. -
copied
Copied nodesnullif database is closed.. -
focused
public int focusedFocused node.
-
-
Constructor Details
-
Context
public Context()Default constructor, which is usually called once in the lifetime of a project. -
Context
public Context(boolean file) Default constructor, which is usually called once in the lifetime of a project.- Parameters:
file- retrieve options from disk
-
Context
Constructor, called by clients, and adopting the variables of the specified context. Theusermust be set after calling this method.- Parameters:
ctx- main context
-
Context
Constructor, called by clients, and adopting the variables of the main context. Theusermust be set after calling this method.- Parameters:
ctx- main contextclient- client info (can benull)
-
Context
Private constructor.- Parameters:
soptions- static options
-
-
Method Details
-
user
Returns the user of this context.- Returns:
- user (can be
nullif it has not yet been assigned
-
user
Sets the user of this context. This method can only be called once.- Parameters:
us- user
-
close
public void close()Closes the database context. Must only be called on the global database context, and not on client instances. -
root
public boolean root()Returnstrueif a data reference exists and if the current node set contains all documents.- Returns:
- result of check
-
data
Returns the current data reference.- Returns:
- data reference
-
current
Returns the current node context.- Returns:
- node set, or
nullif no database is opened
-
current
Sets the current node context. Discards the input if it contains all document nodes of the currently opened database.- Parameters:
curr- node set
-
openDB
Sets the specified data instance as current database.- Parameters:
dt- data reference
-
closeDB
public void closeDB()Closes the current database context. -
set
Sets the current context and marked node set and resets the focus.- Parameters:
curr- context setmark- marked nodes
-
invalidate
public void invalidate()Invalidates the current node set. Will be recreated once it is requested. -
pinned
Checks if the specified database is pinned.- Parameters:
db- name of database- Returns:
- result of check
-
perm
Checks if the current user has the specified permission.- Parameters:
perm- requested permissiondb- database pattern (can benull)- Returns:
- result of check
-
clientAddress
Returns the host and port of a client.- Returns:
- address (or
null)
-
clientName
Returns the name of the current client or user.- Returns:
- user name (or
null)
-
listDBs
Returns all databases for which the current user has read access.- Returns:
- resulting list
-
listDBs
Returns all databases for which the current user has read access.- Parameters:
pattern- database pattern (can benull)- Returns:
- resulting list
-
setExternal
Assigns an external object.- Parameters:
object- external object
-
getExternal
Returns an external object.- Parameters:
clz- class of external object- Returns:
- object or
null
-