Class Context

java.lang.Object
org.basex.core.Context

public final class Context extends Object
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 Details

    • blocker

      public final ClientBlocker blocker
      Blocked clients.
    • jobs

      public final JobPool jobs
      Job pool.
    • options

      public final MainOptions options
      Options.
    • soptions

      public final StaticOptions soptions
      Static options.
    • sessions

      public final Sessions sessions
      Client sessions.
    • datas

      public final Datas datas
      Opened databases.
    • users

      public final Users users
      Users.
    • repo

      public final EXPathRepo repo
      EXPath package repository.
    • databases

      public final Databases databases
      Databases list.
    • log

      public final Log log
      Log.
    • locking

      public final Locking locking
      Locking.
    • marked

      public DBNodes marked
      Marked nodes. null if database is closed.
    • copied

      public DBNodes copied
      Copied nodes null if database is closed..
    • focused

      public int focused
      Focused 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

      public Context(Context ctx)
      Constructor, called by clients, and adopting the variables of the specified context. The user must be set after calling this method.
      Parameters:
      ctx - main context
    • Context

      public Context(Context ctx, ClientInfo client)
      Constructor, called by clients, and adopting the variables of the main context. The user must be set after calling this method.
      Parameters:
      ctx - main context
      client - client info (can be null)
    • Context

      public Context(StaticOptions soptions)
      Private constructor.
      Parameters:
      soptions - static options
  • Method Details

    • user

      public User user()
      Returns the user of this context.
      Returns:
      user (can be null if it has not yet been assigned
    • user

      public void user(User us)
      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()
      Returns true if a data reference exists and if the current node set contains all documents.
      Returns:
      result of check
    • data

      public Data data()
      Returns the current data reference.
      Returns:
      data reference
    • current

      public DBNodes current()
      Returns the current node context.
      Returns:
      node set, or null if no database is opened
    • current

      public void current(DBNodes curr)
      Sets the current node context. Discards the input if it contains all document nodes of the currently opened database.
      Parameters:
      curr - node set
    • openDB

      public void openDB(Data dt)
      Sets the specified data instance as current database.
      Parameters:
      dt - data reference
    • closeDB

      public void closeDB()
      Closes the current database context.
    • set

      public void set(DBNodes curr, DBNodes mark)
      Sets the current context and marked node set and resets the focus.
      Parameters:
      curr - context set
      mark - marked nodes
    • invalidate

      public void invalidate()
      Invalidates the current node set. Will be recreated once it is requested.
    • pinned

      public boolean pinned(String db)
      Checks if the specified database is pinned.
      Parameters:
      db - name of database
      Returns:
      result of check
    • perm

      public boolean perm(Perm perm, String db)
      Checks if the current user has the specified permission.
      Parameters:
      perm - requested permission
      db - database pattern (can be null)
      Returns:
      result of check
    • clientAddress

      public String clientAddress()
      Returns the host and port of a client.
      Returns:
      address (or null)
    • clientName

      public String clientName()
      Returns the name of the current client or user.
      Returns:
      user name (or null)
    • listDBs

      public StringList listDBs()
      Returns all databases for which the current user has read access.
      Returns:
      resulting list
    • listDBs

      public StringList listDBs(String pattern)
      Returns all databases for which the current user has read access.
      Parameters:
      pattern - database pattern (can be null)
      Returns:
      resulting list
    • setExternal

      public void setExternal(Object object)
      Assigns an external object.
      Parameters:
      object - external object
    • getExternal

      public Object getExternal(Class<?> clz)
      Returns an external object.
      Parameters:
      clz - class of external object
      Returns:
      object or null