org.basex.server
Class ClientSession

java.lang.Object
  extended by org.basex.server.Session
      extended by org.basex.server.ClientSession

public class ClientSession
extends Session

This class offers methods to execute database commands via the client/server architecture. Commands are sent to the server instance over a socket connection:

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

Field Summary
protected  java.util.Map<java.lang.String,EventNotifier> notifiers
          Event notifications.
protected  java.io.InputStream sin
          Server input.
protected  PrintOutput sout
          Server output (buffered).
 
Fields inherited from class org.basex.server.Session
out
 
Constructor Summary
ClientSession(Context context, java.lang.String user, java.lang.String pass)
          Constructor, specifying login data.
ClientSession(Context context, java.lang.String user, java.lang.String pass, java.io.OutputStream output)
          Constructor, specifying login data and an output stream.
ClientSession(java.lang.String host, int port, java.lang.String user, java.lang.String pass)
          Constructor, specifying the server host:port combination and login data.
ClientSession(java.lang.String host, int port, java.lang.String user, java.lang.String pass, java.io.OutputStream output)
          Constructor, specifying the server host:port combination, login data and an output stream.
 
Method Summary
 void add(java.lang.String path, java.io.InputStream input)
          Adds a document to the opened database.
 void close()
          Closes the session.
 void create(java.lang.String name, java.io.InputStream input)
          Creates a database.
protected  java.lang.String exec(ServerCmd cmd, java.lang.String arg, java.io.OutputStream os)
          Executes a command and sends the result to the specified output stream.
protected  void execute(Command cmd, java.io.OutputStream os)
          Executes a command and prints the result to the specified output stream.
protected  void execute(java.lang.String cmd, java.io.OutputStream os)
          Executes a command and prints the result to the specified output stream.
protected static boolean ok(BufferInput bi)
          Checks the next success flag.
 ClientQuery query(java.lang.String query)
          Returns a query object for the specified query string.
protected static void receive(BufferInput bi, java.io.OutputStream os)
          Retrieves data from the server.
 void replace(java.lang.String path, java.io.InputStream input)
          Replaces a document in an open database.
protected  void send(ServerCmd cmd, java.io.InputStream input, java.lang.String... strings)
          Sends the specified command, string arguments and input.
protected  void send(java.lang.String s)
          Sends a string to the server.
 void store(java.lang.String path, java.io.InputStream input)
          Stores raw data in an open database.
 java.lang.String toString()
           
 void unwatch(java.lang.String name)
          Unwatches an event.
 void watch(java.lang.String name, EventNotifier notifier)
          Watches an event.
 
Methods inherited from class org.basex.server.Session
execute, execute, getOutputStream, info, setOutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

notifiers

protected final java.util.Map<java.lang.String,EventNotifier> notifiers
Event notifications.


sout

protected final PrintOutput sout
Server output (buffered).


sin

protected final java.io.InputStream sin
Server input.

Constructor Detail

ClientSession

public ClientSession(Context context,
                     java.lang.String user,
                     java.lang.String pass)
              throws java.io.IOException
Constructor, specifying login data.

Parameters:
context - database context
user - user name
pass - password
Throws:
java.io.IOException - I/O exception

ClientSession

public ClientSession(Context context,
                     java.lang.String user,
                     java.lang.String pass,
                     java.io.OutputStream output)
              throws java.io.IOException
Constructor, specifying login data and an output stream.

Parameters:
context - database context
user - user name
pass - password
output - client output; if set to null, results will be returned as strings.
Throws:
java.io.IOException - I/O exception

ClientSession

public ClientSession(java.lang.String host,
                     int port,
                     java.lang.String user,
                     java.lang.String pass)
              throws java.io.IOException
Constructor, specifying the server host:port combination and login data.

Parameters:
host - server name
port - server port
user - user name
pass - password
Throws:
java.io.IOException - I/O exception

ClientSession

public ClientSession(java.lang.String host,
                     int port,
                     java.lang.String user,
                     java.lang.String pass,
                     java.io.OutputStream output)
              throws java.io.IOException
Constructor, specifying the server host:port combination, login data and an output stream.

Parameters:
host - server name
port - server port
user - user name
pass - password
output - client output; if set to null, results will be returned as strings.
Throws:
java.io.IOException - I/O exception
Method Detail

create

public void create(java.lang.String name,
                   java.io.InputStream input)
            throws java.io.IOException
Description copied from class: Session
Creates a database.

Specified by:
create in class Session
Parameters:
name - name of database
input - xml input
Throws:
java.io.IOException - I/O exception

add

public void add(java.lang.String path,
                java.io.InputStream input)
         throws java.io.IOException
Description copied from class: Session
Adds a document to the opened database.

Specified by:
add in class Session
Parameters:
path - target path
input - xml input
Throws:
java.io.IOException - I/O exception

replace

public void replace(java.lang.String path,
                    java.io.InputStream input)
             throws java.io.IOException
Description copied from class: Session
Replaces a document in an open database.

Specified by:
replace in class Session
Parameters:
path - document(s) to replace
input - new content
Throws:
java.io.IOException - I/O exception

store

public void store(java.lang.String path,
                  java.io.InputStream input)
           throws java.io.IOException
Description copied from class: Session
Stores raw data in an open database.

Specified by:
store in class Session
Parameters:
path - target path
input - binary input
Throws:
java.io.IOException - I/O exception

query

public ClientQuery query(java.lang.String query)
                  throws java.io.IOException
Description copied from class: Session
Returns a query object for the specified query string.

Specified by:
query in class Session
Parameters:
query - query string
Returns:
query
Throws:
java.io.IOException - I/O exception

close

public void close()
           throws java.io.IOException
Description copied from class: Session
Closes the session.

Specified by:
close in class Session
Throws:
java.io.IOException - I/O exception

execute

protected void execute(java.lang.String cmd,
                       java.io.OutputStream os)
                throws java.io.IOException
Description copied from class: Session
Executes a command and prints the result to the specified output stream.

Specified by:
execute in class Session
Parameters:
cmd - command to be parsed
os - output stream
Throws:
java.io.IOException - I/O exception

execute

protected void execute(Command cmd,
                       java.io.OutputStream os)
                throws java.io.IOException
Description copied from class: Session
Executes a command and prints the result to the specified output stream.

Specified by:
execute in class Session
Parameters:
cmd - command to be executed
os - output stream
Throws:
java.io.IOException - I/O exception

watch

public void watch(java.lang.String name,
                  EventNotifier notifier)
           throws java.io.IOException
Watches an event.

Parameters:
name - event name
notifier - event notification
Throws:
java.io.IOException - I/O exception

unwatch

public void unwatch(java.lang.String name)
             throws java.io.IOException
Unwatches an event.

Parameters:
name - event name
Throws:
java.io.IOException - I/O exception

ok

protected static boolean ok(BufferInput bi)
                     throws java.io.IOException
Checks the next success flag.

Parameters:
bi - buffer input
Returns:
value of check
Throws:
java.io.IOException - I/O exception

send

protected void send(ServerCmd cmd,
                    java.io.InputStream input,
                    java.lang.String... strings)
             throws java.io.IOException
Sends the specified command, string arguments and input.

Parameters:
cmd - command
input - input stream
strings - string arguments
Throws:
java.io.IOException - I/O exception

receive

protected static void receive(BufferInput bi,
                              java.io.OutputStream os)
                       throws java.io.IOException
Retrieves data from the server.

Parameters:
bi - buffered server input
os - output stream
Throws:
java.io.IOException - I/O exception

send

protected void send(java.lang.String s)
             throws java.io.IOException
Sends a string to the server.

Parameters:
s - string to be sent
Throws:
java.io.IOException - I/O exception

exec

protected java.lang.String exec(ServerCmd cmd,
                                java.lang.String arg,
                                java.io.OutputStream os)
                         throws java.io.IOException
Executes a command and sends the result to the specified output stream.

Parameters:
cmd - server command
arg - argument
os - target output stream
Returns:
string
Throws:
java.io.IOException - I/O exception

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object