Class Session

java.lang.Object
org.basex.api.client.Session
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ClientSession, LocalSession

public abstract class Session extends Object implements Closeable

This class defines methods for executing commands, either locally or via the client/server architecture.

The results of database commands are returned as strings. If an output stream is specified in the constructor or with setOutputStream(OutputStream), results are instead serialized to that stream.

The class is implemented by the ClientSession and LocalSession classes.

Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Details

    • out

      protected OutputStream out
      Client output stream.
    • info

      protected String info
      Command info.
  • Method Details

    • execute

      public final String execute(Command command) throws IOException
      Executes a Command and returns the result as string or serializes it to the specified output stream.
      Parameters:
      command - command to be executed
      Returns:
      result or null reference
      Throws:
      IOException - I/O exception
    • execute

      public final String execute(String command) throws IOException
      Executes a command and returns the result as string or serializes it to the specified output stream.
      Parameters:
      command - command to be parsed
      Returns:
      result or null reference
      Throws:
      IOException - I/O exception
    • query

      public abstract Query query(String query) throws IOException
      Returns a query object for the specified query string.
      Parameters:
      query - query string
      Returns:
      query
      Throws:
      IOException - I/O exception
    • create

      public abstract void create(String name, InputStream input) throws IOException
      Creates a database.
      Parameters:
      name - name of database
      input - xml input
      Throws:
      IOException - I/O exception
    • add

      public abstract void add(String path, InputStream input) throws IOException
      Adds a document to the opened database.
      Parameters:
      path - target path
      input - xml input
      Throws:
      IOException - I/O exception
    • replace

      public abstract void replace(String path, InputStream input) throws IOException
      Replaces a document in an open database.
      Parameters:
      path - document(s) to replace
      input - new content
      Throws:
      IOException - I/O exception
    • store

      public abstract void store(String path, InputStream input) throws IOException
      Stores raw data in an open database.
      Parameters:
      path - target path
      input - binary input
      Throws:
      IOException - I/O exception
    • info

      public final String info()
      Returns command info as a string, regardless of whether an output stream was specified.
      Returns:
      command info
    • setOutputStream

      public final void setOutputStream(OutputStream output)
      Specifies an output stream. The output stream can be invalidated by passing on null as argument.
      Parameters:
      output - client output stream
    • getOutputStream

      public OutputStream getOutputStream()
      Returns the assigned output stream.
      Returns:
      client output stream
    • execute

      protected abstract void execute(String command, OutputStream output) throws IOException
      Executes a command and prints the result to the specified output stream.
      Parameters:
      command - command to be parsed
      output - output stream
      Throws:
      IOException - I/O exception
    • execute

      protected abstract void execute(Command command, OutputStream output) throws IOException
      Executes a command and prints the result to the specified output stream.
      Parameters:
      command - command to be executed
      output - output stream
      Throws:
      IOException - I/O exception