org.h2.engine
Class SessionRemote

java.lang.Object
  extended by org.h2.engine.SessionWithState
      extended by org.h2.engine.SessionRemote
All Implemented Interfaces:
SessionFactory, SessionInterface, DataHandler

public class SessionRemote
extends SessionWithState
implements SessionFactory, DataHandler

The client side part of a session when using the server mode. This object communicates with a Session on the server side.


Field Summary
static int CHANGE_ID
           
static int COMMAND_CLOSE
           
static int COMMAND_COMMIT
           
static int COMMAND_EXECUTE_QUERY
           
static int COMMAND_EXECUTE_UPDATE
           
static int COMMAND_GET_META_DATA
           
static int RESULT_CLOSE
           
static int RESULT_FETCH_ROWS
           
static int RESULT_RESET
           
static int SESSION_CANCEL_STATEMENT
           
static int SESSION_CHECK_KEY
           
static int SESSION_CLOSE
           
static int SESSION_PREPARE
           
static int SESSION_PREPARE_READ_PARAMS
           
static int SESSION_SET_ID
           
static int STATUS_CLOSED
           
static int STATUS_ERROR
           
static int STATUS_OK
           
static int STATUS_OK_STATE_CHANGED
           
 
Fields inherited from class org.h2.engine.SessionWithState
sessionState, sessionStateChanged
 
Constructor Summary
SessionRemote()
           
 
Method Summary
 int allocateObjectId(boolean needFresh, boolean dataFile)
          Get the next object id.
 void autoCommitIfCluster()
          Calls COMMIT if the session is in cluster mode.
 boolean autoReconnect(int count)
          Automatically re-connect if necessary and if configured to do so.
 void cancel()
          Cancel the current or next command (called when closing a connection).
 void cancelStatement(int id)
          Cancel the statement with the given id.
 void checkClosed()
          Check if this session is closed and throws an exception if so.
 void checkPowerOff()
          Check if the simulated power failure occurred.
 void checkWritingAllowed()
          Check if writing is allowed.
 void close()
          Roll back pending transactions and close the session.
 int compareTypeSave(Value a, Value b)
          Compare two values.
 SessionInterface createSession(ConnectionInfo ci)
          Create a new session.
 java.lang.String createTempFile()
          Create a temporary file and return the file name.
 void done(Transfer transfer)
          Called to flush the output after data has been sent to the server and just before receiving data.
 void freeUpDiskSpace()
          Free up disk space if possible.
 int getChecksum(byte[] data, int start, int end)
          Calculate the checksum for the byte array.
 int getClientVersion()
           
 int getCurrentId()
           
 java.lang.String getDatabasePath()
          Get the database path.
 DataHandler getDataHandler()
          Get the data handler object.
 int getLastReconnect()
           
 java.lang.String getLobCompressionAlgorithm(int type)
          Get the compression algorithm used for large objects.
 SmallLRUCache<java.lang.String,java.lang.String[]> getLobFileListCache()
          Get the lob file list cache if it is used.
 boolean getLobFilesInDirectories()
          Checks if the lob files stored in directories.
 java.lang.Object getLobSyncObject()
          Get the synchronization object for lob operations.
 int getMaxLengthInplaceLob()
          Get the maximum length of a in-place large object
 int getNextId()
           
 int getPowerOffCount()
          Get the number of disk operations before power failure is simulated.
 TempFileDeleter getTempFileDeleter()
          Get the temp file deleter mechanism.
 Trace getTrace()
          Get the trace writer.
 void handleInvalidChecksum()
          Called when the checksum was invalid.
 boolean isClosed()
          Check if close was called.
 boolean isClustered()
          Returns true if the connection is in cluster mode.
 boolean isReconnectNeeded(boolean write)
          Check if the database changed and therefore reconnecting is required.
 FileStore openFile(java.lang.String name, java.lang.String mode, boolean mustExist)
          Open a file at the given location.
 CommandInterface prepareCommand(java.lang.String sql, int fetchSize)
          Parse a command and prepare it for execution.
 SessionInterface reconnect()
          Close the connection and open a new connection.
 void removeServer(java.io.IOException e, int i, int count)
          Remove a server from the list of cluster nodes and disables the cluster mode.
 void setAutoCommit(boolean autoCommit)
           
 void setPowerOffCount(int count)
          Set the number of disk operations before power failure is simulated.
 void traceOperation(java.lang.String operation, int id)
          Write the operation to the trace system if debug trace is enabled.
 
Methods inherited from class org.h2.engine.SessionWithState
readSessionState, recreateSessionState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_PREPARE

public static final int SESSION_PREPARE
See Also:
Constant Field Values

SESSION_CLOSE

public static final int SESSION_CLOSE
See Also:
Constant Field Values

COMMAND_EXECUTE_QUERY

public static final int COMMAND_EXECUTE_QUERY
See Also:
Constant Field Values

COMMAND_EXECUTE_UPDATE

public static final int COMMAND_EXECUTE_UPDATE
See Also:
Constant Field Values

COMMAND_CLOSE

public static final int COMMAND_CLOSE
See Also:
Constant Field Values

RESULT_FETCH_ROWS

public static final int RESULT_FETCH_ROWS
See Also:
Constant Field Values

RESULT_RESET

public static final int RESULT_RESET
See Also:
Constant Field Values

RESULT_CLOSE

public static final int RESULT_CLOSE
See Also:
Constant Field Values

COMMAND_COMMIT

public static final int COMMAND_COMMIT
See Also:
Constant Field Values

CHANGE_ID

public static final int CHANGE_ID
See Also:
Constant Field Values

COMMAND_GET_META_DATA

public static final int COMMAND_GET_META_DATA
See Also:
Constant Field Values

SESSION_PREPARE_READ_PARAMS

public static final int SESSION_PREPARE_READ_PARAMS
See Also:
Constant Field Values

SESSION_SET_ID

public static final int SESSION_SET_ID
See Also:
Constant Field Values

SESSION_CANCEL_STATEMENT

public static final int SESSION_CANCEL_STATEMENT
See Also:
Constant Field Values

SESSION_CHECK_KEY

public static final int SESSION_CHECK_KEY
See Also:
Constant Field Values

STATUS_ERROR

public static final int STATUS_ERROR
See Also:
Constant Field Values

STATUS_OK

public static final int STATUS_OK
See Also:
Constant Field Values

STATUS_CLOSED

public static final int STATUS_CLOSED
See Also:
Constant Field Values

STATUS_OK_STATE_CHANGED

public static final int STATUS_OK_STATE_CHANGED
See Also:
Constant Field Values
Constructor Detail

SessionRemote

public SessionRemote()
Method Detail

cancel

public void cancel()
Description copied from interface: SessionInterface
Cancel the current or next command (called when closing a connection).

Specified by:
cancel in interface SessionInterface

cancelStatement

public void cancelStatement(int id)
Cancel the statement with the given id.

Parameters:
id - the statement id

setAutoCommit

public void setAutoCommit(boolean autoCommit)

autoCommitIfCluster

public void autoCommitIfCluster()
                         throws java.sql.SQLException
Calls COMMIT if the session is in cluster mode.

Throws:
java.sql.SQLException

getPowerOffCount

public int getPowerOffCount()
Description copied from interface: SessionInterface
Get the number of disk operations before power failure is simulated. This is used for testing. If not set, 0 is returned

Specified by:
getPowerOffCount in interface SessionInterface
Returns:
the number of operations, or 0

setPowerOffCount

public void setPowerOffCount(int count)
                      throws java.sql.SQLException
Description copied from interface: SessionInterface
Set the number of disk operations before power failure is simulated. To disable the countdown, use 0.

Specified by:
setPowerOffCount in interface SessionInterface
Parameters:
count - the number of operations
Throws:
java.sql.SQLException

createSession

public SessionInterface createSession(ConnectionInfo ci)
                               throws java.sql.SQLException
Description copied from interface: SessionFactory
Create a new session.

Specified by:
createSession in interface SessionFactory
Parameters:
ci - the connection parameters
Returns:
the new session
Throws:
java.sql.SQLException

removeServer

public void removeServer(java.io.IOException e,
                         int i,
                         int count)
                  throws java.sql.SQLException
Remove a server from the list of cluster nodes and disables the cluster mode.

Parameters:
e - the exception (used for debugging)
i - the index of the server to remove
count - the retry count index
Throws:
java.sql.SQLException

prepareCommand

public CommandInterface prepareCommand(java.lang.String sql,
                                       int fetchSize)
                                throws java.sql.SQLException
Description copied from interface: SessionInterface
Parse a command and prepare it for execution.

Specified by:
prepareCommand in interface SessionInterface
Parameters:
sql - the SQL statement
fetchSize - the number of rows to fetch in one step
Returns:
the prepared command
Throws:
java.sql.SQLException

autoReconnect

public boolean autoReconnect(int count)
                      throws java.sql.SQLException
Automatically re-connect if necessary and if configured to do so.

Parameters:
count - the retry count index
Returns:
true if reconnected
Throws:
java.sql.SQLException

checkClosed

public void checkClosed()
                 throws java.sql.SQLException
Check if this session is closed and throws an exception if so.

Throws:
java.sql.SQLException - if the session is closed

close

public void close()
           throws java.sql.SQLException
Description copied from interface: SessionInterface
Roll back pending transactions and close the session.

Specified by:
close in interface SessionInterface
Throws:
java.sql.SQLException

getTrace

public Trace getTrace()
Description copied from interface: DataHandler
Get the trace writer.

Specified by:
getTrace in interface SessionInterface
Specified by:
getTrace in interface DataHandler
Returns:
the trace writer

getNextId

public int getNextId()

getCurrentId

public int getCurrentId()

done

public void done(Transfer transfer)
          throws java.sql.SQLException,
                 java.io.IOException
Called to flush the output after data has been sent to the server and just before receiving data. This method also reads the status code from the server and throws any exception the server sent.

Parameters:
transfer - the transfer object
Throws:
java.sql.SQLException - if the server sent an exception
java.io.IOException - if there is a communication problem between client and server

isClustered

public boolean isClustered()
Returns true if the connection is in cluster mode.

Returns:
true if it is

isClosed

public boolean isClosed()
Description copied from interface: SessionInterface
Check if close was called.

Specified by:
isClosed in interface SessionInterface
Returns:
if the session has been closed

traceOperation

public void traceOperation(java.lang.String operation,
                           int id)
Write the operation to the trace system if debug trace is enabled.

Parameters:
operation - the operation performed
id - the id of the operation

allocateObjectId

public int allocateObjectId(boolean needFresh,
                            boolean dataFile)
Description copied from interface: DataHandler
Get the next object id. This method is not required if LOB_FILES_IN_DIRECTORIES is enabled.

Specified by:
allocateObjectId in interface DataHandler
Parameters:
needFresh - if a fresh id is required
dataFile - true if the id is for the data file
Returns:
the new id

checkPowerOff

public void checkPowerOff()
Description copied from interface: DataHandler
Check if the simulated power failure occurred. This call will decrement the countdown.

Specified by:
checkPowerOff in interface DataHandler

checkWritingAllowed

public void checkWritingAllowed()
Description copied from interface: DataHandler
Check if writing is allowed.

Specified by:
checkWritingAllowed in interface DataHandler

compareTypeSave

public int compareTypeSave(Value a,
                           Value b)
Description copied from interface: DataHandler
Compare two values.

Specified by:
compareTypeSave in interface DataHandler
Parameters:
a - the first value
b - the second value
Returns:
0 for equal, 1 if a is larger than b, and -1 otherwise

createTempFile

public java.lang.String createTempFile()
                                throws java.sql.SQLException
Description copied from interface: DataHandler
Create a temporary file and return the file name.

Specified by:
createTempFile in interface DataHandler
Returns:
the file name
Throws:
java.sql.SQLException

freeUpDiskSpace

public void freeUpDiskSpace()
Description copied from interface: DataHandler
Free up disk space if possible. This method is called if more space is needed.

Specified by:
freeUpDiskSpace in interface DataHandler

getChecksum

public int getChecksum(byte[] data,
                       int start,
                       int end)
Description copied from interface: DataHandler
Calculate the checksum for the byte array.

Specified by:
getChecksum in interface DataHandler
Parameters:
data - the byte array
start - the starting offset
end - the end offset
Returns:
the checksum

getDatabasePath

public java.lang.String getDatabasePath()
Description copied from interface: DataHandler
Get the database path.

Specified by:
getDatabasePath in interface DataHandler
Returns:
the database path

getLobCompressionAlgorithm

public java.lang.String getLobCompressionAlgorithm(int type)
Description copied from interface: DataHandler
Get the compression algorithm used for large objects.

Specified by:
getLobCompressionAlgorithm in interface DataHandler
Parameters:
type - the data type (CLOB or BLOB)
Returns:
the compression algorithm, or null

getMaxLengthInplaceLob

public int getMaxLengthInplaceLob()
Description copied from interface: DataHandler
Get the maximum length of a in-place large object

Specified by:
getMaxLengthInplaceLob in interface DataHandler
Returns:
the maximum size

handleInvalidChecksum

public void handleInvalidChecksum()
                           throws java.sql.SQLException
Description copied from interface: DataHandler
Called when the checksum was invalid.

Specified by:
handleInvalidChecksum in interface DataHandler
Throws:
java.sql.SQLException - if this should not be ignored

openFile

public FileStore openFile(java.lang.String name,
                          java.lang.String mode,
                          boolean mustExist)
                   throws java.sql.SQLException
Description copied from interface: DataHandler
Open a file at the given location.

Specified by:
openFile in interface DataHandler
Parameters:
name - the file name
mode - the mode
mustExist - whether the file must already exist
Returns:
the file
Throws:
java.sql.SQLException

getDataHandler

public DataHandler getDataHandler()
Description copied from interface: SessionInterface
Get the data handler object.

Specified by:
getDataHandler in interface SessionInterface
Returns:
the data handler

getLobSyncObject

public java.lang.Object getLobSyncObject()
Description copied from interface: DataHandler
Get the synchronization object for lob operations.

Specified by:
getLobSyncObject in interface DataHandler
Returns:
the synchronization object

getLobFilesInDirectories

public boolean getLobFilesInDirectories()
Description copied from interface: DataHandler
Checks if the lob files stored in directories.

Specified by:
getLobFilesInDirectories in interface DataHandler
Returns:
true if lob files are stored in directories.

getLobFileListCache

public SmallLRUCache<java.lang.String,java.lang.String[]> getLobFileListCache()
Description copied from interface: DataHandler
Get the lob file list cache if it is used.

Specified by:
getLobFileListCache in interface DataHandler
Returns:
the cache or null

getClientVersion

public int getClientVersion()

getLastReconnect

public int getLastReconnect()

getTempFileDeleter

public TempFileDeleter getTempFileDeleter()
Description copied from interface: DataHandler
Get the temp file deleter mechanism.

Specified by:
getTempFileDeleter in interface DataHandler
Returns:
the temp file deleter

isReconnectNeeded

public boolean isReconnectNeeded(boolean write)
Description copied from interface: SessionInterface
Check if the database changed and therefore reconnecting is required.

Specified by:
isReconnectNeeded in interface SessionInterface
Parameters:
write - if the next operation may be writing
Returns:
true if reconnecting is required

reconnect

public SessionInterface reconnect()
Description copied from interface: SessionInterface
Close the connection and open a new connection.

Specified by:
reconnect in interface SessionInterface
Returns:
the new connection