Package org.basex.api.client
Class ClientSession
java.lang.Object
org.basex.api.client.Session
org.basex.api.client.ClientSession
- All Implemented Interfaces:
Closeable,AutoCloseable
This class contains methods to execute database commands via the client/server architecture.
Commands are sent to the server instance over a socket connection:
- A socket instance is created by the constructor.
- The
execute(java.lang.String, java.io.OutputStream)method sends database commands to the server. All strings are encoded as UTF8 and suffixed by a zero byte. - If the command has been successfully executed, the result string is read.
- Next, the command info string is read.
- A last byte is next sent to indicate if command execution was successful (0) or not (1).
-
close()closes the session by sending theCommands.Cmd.EXITcommand to the server.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionClientSession(String host, int port, String username, String password) Constructor, specifying the server host:port combination and login data.ClientSession(String host, int port, String username, String password, OutputStream output) Constructor, specifying the server host:port combination, login data and an output stream.ClientSession(Context context, String username, String password) Constructor, specifying login data.ClientSession(Context context, String username, String password, OutputStream output) Constructor, specifying login data and an output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(String path, InputStream input) Adds a document to the opened database.voidclose()voidcreate(String name, InputStream input) Creates a database.protected voidexecute(String command, OutputStream output) Executes a command and prints the result to the specified output stream.protected voidexecute(Command command, OutputStream output) Executes a command and prints the result to the specified output stream.Returns a query object for the specified query string.voidreplace(String path, InputStream input) Replaces a document in an open database.voidstore(String path, InputStream input) Stores raw data in an open database.toString()Methods inherited from class org.basex.api.client.Session
execute, execute, getOutputStream, info, setOutputStream
-
Constructor Details
-
ClientSession
Constructor, specifying login data.- Parameters:
context- database contextusername- user namepassword- password (plain text)- Throws:
IOException- I/O exception
-
ClientSession
public ClientSession(Context context, String username, String password, OutputStream output) throws IOException Constructor, specifying login data and an output stream.- Parameters:
context- database contextusername- user namepassword- password (plain text)output- client output; if set tonull, results will be returned as strings- Throws:
IOException- I/O exception
-
ClientSession
Constructor, specifying the server host:port combination and login data.- Parameters:
host- server nameport- server portusername- user namepassword- password (plain text)- Throws:
IOException- I/O exception
-
ClientSession
public ClientSession(String host, int port, String username, String password, OutputStream output) throws IOException Constructor, specifying the server host:port combination, login data and an output stream.- Parameters:
host- server nameport- server portusername- user namepassword- password (plain text)output- client output; if set tonull, results will be returned as strings- Throws:
IOException- I/O exception
-
-
Method Details
-
create
Description copied from class:SessionCreates a database.- Specified by:
createin classSession- Parameters:
name- name of databaseinput- xml input- Throws:
IOException- I/O exception
-
add
Description copied from class:SessionAdds a document to the opened database.- Specified by:
addin classSession- Parameters:
path- target pathinput- xml input- Throws:
IOException- I/O exception
-
replace
Description copied from class:SessionReplaces a document in an open database.- Specified by:
replacein classSession- Parameters:
path- document(s) to replaceinput- new content- Throws:
IOException- I/O exception
-
store
Description copied from class:SessionStores raw data in an open database.- Specified by:
storein classSession- Parameters:
path- target pathinput- binary input- Throws:
IOException- I/O exception
-
query
Description copied from class:SessionReturns a query object for the specified query string.- Specified by:
queryin classSession- Parameters:
query- query string- Returns:
- query
- Throws:
IOException- I/O exception
-
close
- Throws:
IOException
-
execute
Description copied from class:SessionExecutes a command and prints the result to the specified output stream.- Specified by:
executein classSession- Parameters:
command- command to be parsedoutput- output stream- Throws:
IOException- I/O exception
-
execute
Description copied from class:SessionExecutes a command and prints the result to the specified output stream.- Specified by:
executein classSession- Parameters:
command- command to be executedoutput- output stream- Throws:
IOException- I/O exception
-
toString
-