org.h2.engine

## Class SessionRemote

- java.lang.Object
- - org.h2.engine.SessionRemote

All Implemented Interfaces:
  java.io.Closeable, java.lang.AutoCloseable, SessionInterface, DataHandler

    public class SessionRemote
    extends java.lang.Object
    implements 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

Fields
`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` `LOB_READ`
`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_HAS_PENDING_TRANSACTION`
`static int` `SESSION_PREPARE`
`static int` `SESSION_PREPARE_READ_PARAMS`
`static int` `SESSION_PREPARE_READ_PARAMS2`
`static int` `SESSION_SET_AUTOCOMMIT`
`static int` `SESSION_SET_ID`
`protected java.util.ArrayList<java.lang.String>` `sessionState`
`protected boolean` `sessionStateChanged`
`static int` `STATUS_CLOSED`
`static int` `STATUS_ERROR`
`static int` `STATUS_OK`
`static int` `STATUS_OK_STATE_CHANGED`

### Constructor Summary

Constructors
Constructor and Description
`SessionRemote(ConnectionInfo ci)`

### Method Summary

Methods
`void` `addTemporaryLob(Value v)` Add a temporary LOB, which is closed when the session commits.
`void` `autoCommitIfCluster()` Calls COMMIT if the session is in cluster mode.
`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.
`SessionInterface` `connectEmbeddedOrServer(boolean openNew)` Open a new (remote or embedded) session.
`void` `done(Transfer transfer)` Called to flush the output after data has been sent to the server and just before receiving data.
`boolean` `getAutoCommit()` Check if this session is in auto-commit mode.
`int` `getClientVersion()`
`java.util.ArrayList<java.lang.String>` `getClusterServers()` Get the list of the cluster servers for this session.
`CompareMode` `getCompareMode()` Return compare mode.
`int` `getCurrentId()`
`java.lang.String` `getCurrentSchemaName()` Get current schema.
`java.lang.String` `getDatabasePath()` Get the database path.
`DataHandler` `getDataHandler()` Get the data handler object.
`IsolationLevel` `getIsolationLevel()` Returns the isolation level.
`JavaObjectSerializer` `getJavaObjectSerializer()` Return the serializer to be used for java objects being stored in column of type OTHER.
`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.
`LobStorageInterface` `getLobStorage()` Get the lob storage mechanism to use.
`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 object
`boolean` `hasPendingTransaction()` Check whether this session has a pending transaction.
`boolean` `isClosed()` Check if close was called.
`boolean` `isClustered()` Returns true if the connection was opened in cluster mode.
`boolean` `isRemote()` Check if this session is remote or embedded.
`boolean` `isSupportsGeneratedKeys()` Returns is this session supports generated keys.
`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.
`int` `readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length)` Read from a lob.
`void` `readSessionState()` Read the session state if necessary.
`protected void` `recreateSessionState()` Re-create the session state using the stored sessionState list.
`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)` Set the auto-commit mode.
`void` `setAutoCommitFromServer(boolean autoCommit)`
`void` `setCurrentSchemaName(java.lang.String schema)` Set current schema.
`void` `setIsolationLevel(IsolationLevel isolationLevel)` Sets the isolation level.
`void` `setNetworkConnectionInfo(NetworkConnectionInfo networkConnectionInfo)` Sets the network connection information if possible.
`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 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

#### SESSION_SET_AUTOCOMMIT

    public static final int SESSION_SET_AUTOCOMMIT

See Also:
  Constant Field Values

#### SESSION_HAS_PENDING_TRANSACTION

    public static final int SESSION_HAS_PENDING_TRANSACTION

See Also:
  Constant Field Values

#### LOB_READ

    public static final int LOB_READ

See Also:
  Constant Field Values

#### SESSION_PREPARE_READ_PARAMS2

    public static final int SESSION_PREPARE_READ_PARAMS2

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

#### sessionState

    protected java.util.ArrayList<java.lang.String> sessionState

#### sessionStateChanged

    protected boolean sessionStateChanged

### Constructor Detail

#### SessionRemote

    public SessionRemote(ConnectionInfo ci)

### Method Detail

#### getClusterServers

    public java.util.ArrayList<java.lang.String> getClusterServers()

Description copied from interface: `SessionInterface`
Get the list of the cluster servers for this session.

Specified by:
  `getClusterServers` in interface `SessionInterface`
Returns:
  A list of "ip:port" strings for the cluster servers in this session.

#### hasPendingTransaction

    public boolean hasPendingTransaction()

Description copied from interface: `SessionInterface`
Check whether this session has a pending transaction.

Specified by:
  `hasPendingTransaction` in interface `SessionInterface`
Returns:
  true if it has

#### 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

#### getClientVersion

    public int getClientVersion()

#### getAutoCommit

    public boolean getAutoCommit()

Description copied from interface: `SessionInterface`
Check if this session is in auto-commit mode.

Specified by:
  `getAutoCommit` in interface `SessionInterface`
Returns:
  true if the session is in auto-commit mode

#### setAutoCommit

    public void setAutoCommit(boolean autoCommit)

Description copied from interface: `SessionInterface`
Set the auto-commit mode. This call doesn't commit the current transaction.

Specified by:
  `setAutoCommit` in interface `SessionInterface`
Parameters:
  `autoCommit` - the new value

#### setAutoCommitFromServer

    public void setAutoCommitFromServer(boolean autoCommit)

#### autoCommitIfCluster

    public void autoCommitIfCluster()

Calls COMMIT if the session is in cluster mode.

#### 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)

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

#### connectEmbeddedOrServer

    public SessionInterface connectEmbeddedOrServer(boolean openNew)

Open a new (remote or embedded) session.

Parameters:
  `openNew` - whether to open a new session in any case
Returns:
  the session

#### removeServer

    public void removeServer(java.io.IOException e,
                    int i,
                    int count)

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

#### prepareCommand

    public CommandInterface prepareCommand(java.lang.String sql,
                                  int fetchSize)

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

#### checkClosed

    public void checkClosed()

Check if this session is closed and throws an exception if so.

Throws:
  `DbException` - if the session is closed

#### close

    public void close()

Description copied from interface: `SessionInterface`
Roll back pending transactions and close the session.

Specified by:
  `close` in interface `java.io.Closeable`
Specified by:
  `close` in interface `java.lang.AutoCloseable`
Specified by:
  `close` in interface `SessionInterface`

#### getTrace

    public Trace getTrace()

Description copied from interface: `SessionInterface`
Get the trace object

Specified by:
  `getTrace` in interface `SessionInterface`
Returns:
  the trace object

#### getNextId

    public int getNextId()

#### getCurrentId

    public int getCurrentId()

#### done

    public void done(Transfer transfer)
              throws 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:
  `DbException` - 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 was opened 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

#### 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`

#### 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

#### openFile

    public FileStore openFile(java.lang.String name,
                     java.lang.String mode,
                     boolean mustExist)

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

#### 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

#### 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

#### 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

#### getLobStorage

    public LobStorageInterface getLobStorage()

Description copied from interface: `DataHandler`
Get the lob storage mechanism to use.

Specified by:
  `getLobStorage` in interface `DataHandler`
Returns:
  the lob storage mechanism

#### readLob

    public int readLob(long lobId,
              byte[] hmac,
              long offset,
              byte[] buff,
              int off,
              int length)

Description copied from interface: `DataHandler`
Read from a lob.

Specified by:
  `readLob` in interface `DataHandler`
Parameters:
  `lobId` - the lob id
  `hmac` - the message authentication code
  `offset` - the offset within the lob
  `buff` - the target buffer
  `off` - the offset within the target buffer
  `length` - the number of bytes to read
Returns:
  the number of bytes read

#### getJavaObjectSerializer

    public JavaObjectSerializer getJavaObjectSerializer()

Description copied from interface: `DataHandler`
Return the serializer to be used for java objects being stored in column of type OTHER.

Specified by:
  `getJavaObjectSerializer` in interface `DataHandler`
Returns:
  the serializer to be used for java objects being stored in column of type OTHER

#### addTemporaryLob

    public void addTemporaryLob(Value v)

Description copied from interface: `SessionInterface`
Add a temporary LOB, which is closed when the session commits.

Specified by:
  `addTemporaryLob` in interface `SessionInterface`
Parameters:
  `v` - the value

#### getCompareMode

    public CompareMode getCompareMode()

Description copied from interface: `DataHandler`
Return compare mode.

Specified by:
  `getCompareMode` in interface `DataHandler`
Returns:
  Compare mode.

#### isRemote

    public boolean isRemote()

Description copied from interface: `SessionInterface`
Check if this session is remote or embedded.

Specified by:
  `isRemote` in interface `SessionInterface`
Returns:
  true if this session is remote

#### getCurrentSchemaName

    public java.lang.String getCurrentSchemaName()

Description copied from interface: `SessionInterface`
Get current schema.

Specified by:
  `getCurrentSchemaName` in interface `SessionInterface`
Returns:
  the current schema name

#### setCurrentSchemaName

    public void setCurrentSchemaName(java.lang.String schema)

Description copied from interface: `SessionInterface`
Set current schema.

Specified by:
  `setCurrentSchemaName` in interface `SessionInterface`
Parameters:
  `schema` - the schema name

#### isSupportsGeneratedKeys

    public boolean isSupportsGeneratedKeys()

Description copied from interface: `SessionInterface`
Returns is this session supports generated keys.

Specified by:
  `isSupportsGeneratedKeys` in interface `SessionInterface`
Returns:
  `true` if generated keys are supported, `false` if only `SCOPE_IDENTITY()` is supported

#### setNetworkConnectionInfo

    public void setNetworkConnectionInfo(NetworkConnectionInfo networkConnectionInfo)

Description copied from interface: `SessionInterface`
Sets the network connection information if possible.

Specified by:
  `setNetworkConnectionInfo` in interface `SessionInterface`
Parameters:
  `networkConnectionInfo` - the network connection information

#### getIsolationLevel

    public IsolationLevel getIsolationLevel()

Description copied from interface: `SessionInterface`
Returns the isolation level.

Specified by:
  `getIsolationLevel` in interface `SessionInterface`
Returns:
  the isolation level

#### setIsolationLevel

    public void setIsolationLevel(IsolationLevel isolationLevel)

Description copied from interface: `SessionInterface`
Sets the isolation level.

Specified by:
  `setIsolationLevel` in interface `SessionInterface`
Parameters:
  `isolationLevel` - the isolation level to set

#### recreateSessionState

    protected void recreateSessionState()

Re-create the session state using the stored sessionState list.

#### readSessionState

    public void readSessionState()

Read the session state if necessary.