Package org.h2.engine
Class SessionRemote
- java.lang.Object
-
- org.h2.engine.Session
-
- org.h2.engine.SessionRemote
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,CastDataProvider
,DataHandler
public final class SessionRemote extends Session implements DataHandler
The client side part of a session when using the server mode. This object communicates with a Session on the server side.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.h2.engine.Session
Session.DynamicSettings, Session.StaticSettings
-
-
Field Summary
-
Fields inherited from class org.h2.engine.Session
sessionStateChanged, staticSettings
-
-
Constructor Summary
Constructors Constructor Description SessionRemote(ConnectionInfo ci)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ValueLob
addTemporaryLob(ValueLob v)
Add a temporary LOB, which is closed when the session commits.void
autoCommitIfCluster()
Calls COMMIT if the session is in cluster mode.private 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.private void
checkClusterDisableAutoCommit(java.lang.String serverList)
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.Session
connectEmbeddedOrServer(boolean openNew)
Open a new (remote or embedded) session.private void
connectServer(ConnectionInfo ci)
ValueTimestampTimeZone
currentTimestamp()
Returns the current timestamp with maximum resolution.TimeZoneProvider
currentTimeZone()
Returns the current time zone.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()
Returns the TCP protocol version of remote connection.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.DatabaseMeta
getDatabaseMeta()
Returns database meta information.java.lang.String
getDatabasePath()
Get the database path.DataHandler
getDataHandler()
Get the data handler object.Session.DynamicSettings
getDynamicSettings()
Returns dynamic settings.private java.lang.String
getFilePrefix(java.lang.String dir)
IsolationLevel
getIsolationLevel()
Returns the isolation level.JavaObjectSerializer
getJavaObjectSerializer()
Returns the custom Java object serializer, ornull
.int
getLastReconnect()
SmallLRUCache<java.lang.String,java.lang.String[]>
getLobFileListCache()
Get the lob file list cache if it is used.LobStorageFrontend
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 objectMode
getMode()
Returns the database mode.int
getNextId()
private CommandInterface
getSettingsCommand(java.lang.String args)
Session.StaticSettings
getStaticSettings()
Returns static settings.TempFileDeleter
getTempFileDeleter()
Get the temp file deleter mechanism.Trace
getTrace()
Get the trace objectboolean
hasPendingTransaction()
Check whether this session has a pending transaction.private Transfer
initTransfer(ConnectionInfo ci, java.lang.String db, java.lang.String server)
boolean
isClosed()
Check if close was called.boolean
isClustered()
Returns true if the connection was opened in cluster mode.boolean
isOldInformationSchema()
Returns whether INFORMATION_SCHEMA contains old-style tables.boolean
isRemote()
Check if this session is remote or embedded.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.static DbException
readException(Transfer transfer)
Reads an exception.int
readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length)
Read from a lob.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)
private void
setAutoCommitSend(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.private void
switchOffCluster()
void
traceOperation(java.lang.String operation, int id)
Write the operation to the trace system if debug trace is enabled.boolean
zeroBasedEnums()
Returns are ENUM values 0-based.-
Methods inherited from class org.h2.engine.Session
readSessionState, recreateSessionState, resetThreadLocalSession, setThreadLocalSession
-
-
-
-
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_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
-
GET_JDBC_META
public static final int GET_JDBC_META
- 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
-
traceSystem
private TraceSystem traceSystem
-
trace
private Trace trace
-
transferList
private java.util.ArrayList<Transfer> transferList
-
nextId
private int nextId
-
autoCommit
private boolean autoCommit
-
connectionInfo
private ConnectionInfo connectionInfo
-
databaseName
private java.lang.String databaseName
-
cipher
private java.lang.String cipher
-
fileEncryptionKey
private byte[] fileEncryptionKey
-
lobSyncObject
private final java.lang.Object lobSyncObject
-
sessionId
private java.lang.String sessionId
-
clientVersion
private int clientVersion
-
autoReconnect
private boolean autoReconnect
-
lastReconnect
private int lastReconnect
-
embedded
private Session embedded
-
eventListener
private DatabaseEventListener eventListener
-
lobStorage
private LobStorageFrontend lobStorage
-
cluster
private boolean cluster
-
tempFileDeleter
private TempFileDeleter tempFileDeleter
-
javaObjectSerializer
private JavaObjectSerializer javaObjectSerializer
-
compareMode
private final CompareMode compareMode
-
oldInformationSchema
private final boolean oldInformationSchema
-
currentSchemaName
private java.lang.String currentSchemaName
-
dynamicSettings
private volatile Session.DynamicSettings dynamicSettings
-
-
Constructor Detail
-
SessionRemote
public SessionRemote(ConnectionInfo ci)
-
-
Method Detail
-
getClusterServers
public java.util.ArrayList<java.lang.String> getClusterServers()
Description copied from class:Session
Get the list of the cluster servers for this session.- Specified by:
getClusterServers
in classSession
- Returns:
- A list of "ip:port" strings for the cluster servers in this session.
-
initTransfer
private Transfer initTransfer(ConnectionInfo ci, java.lang.String db, java.lang.String server) throws java.io.IOException
- Throws:
java.io.IOException
-
hasPendingTransaction
public boolean hasPendingTransaction()
Description copied from class:Session
Check whether this session has a pending transaction.- Specified by:
hasPendingTransaction
in classSession
- Returns:
- true if it has
-
cancel
public void cancel()
Description copied from class:Session
Cancel the current or next command (called when closing a connection).
-
cancelStatement
public void cancelStatement(int id)
Cancel the statement with the given id.- Parameters:
id
- the statement id
-
checkClusterDisableAutoCommit
private void checkClusterDisableAutoCommit(java.lang.String serverList)
-
getClientVersion
public int getClientVersion()
Returns the TCP protocol version of remote connection.- Returns:
- the TCP protocol version
-
getAutoCommit
public boolean getAutoCommit()
Description copied from class:Session
Check if this session is in auto-commit mode.- Specified by:
getAutoCommit
in classSession
- Returns:
- true if the session is in auto-commit mode
-
setAutoCommit
public void setAutoCommit(boolean autoCommit)
Description copied from class:Session
Set the auto-commit mode. This call doesn't commit the current transaction.- Specified by:
setAutoCommit
in classSession
- Parameters:
autoCommit
- the new value
-
setAutoCommitFromServer
public void setAutoCommitFromServer(boolean autoCommit)
-
setAutoCommitSend
private void setAutoCommitSend(boolean autoCommit)
-
autoCommitIfCluster
public void autoCommitIfCluster()
Calls COMMIT if the session is in cluster mode.
-
getFilePrefix
private java.lang.String getFilePrefix(java.lang.String dir)
-
connectEmbeddedOrServer
public Session connectEmbeddedOrServer(boolean openNew)
Open a new (remote or embedded) session.- Parameters:
openNew
- whether to open a new session in any case- Returns:
- the session
-
connectServer
private void connectServer(ConnectionInfo ci)
-
switchOffCluster
private void switchOffCluster()
-
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 removecount
- the retry count index
-
prepareCommand
public CommandInterface prepareCommand(java.lang.String sql, int fetchSize)
Description copied from class:Session
Parse a command and prepare it for execution.- Specified by:
prepareCommand
in classSession
- Parameters:
sql
- the SQL statementfetchSize
- the number of rows to fetch in one step- Returns:
- the prepared command
-
autoReconnect
private boolean autoReconnect(int count)
Automatically re-connect if necessary and if configured to do so.- Parameters:
count
- the retry count index- Returns:
- true if reconnected
-
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 class:Session
Roll back pending transactions and close the session.
-
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 exceptionjava.io.IOException
- if there is a communication problem between client and server
-
readException
public static DbException readException(Transfer transfer) throws java.io.IOException
Reads an exception.- Parameters:
transfer
- the transfer object- Returns:
- the exception
- Throws:
java.io.IOException
- on I/O exception
-
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 class:Session
Check if close was called.
-
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 performedid
- 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 interfaceDataHandler
-
checkWritingAllowed
public void checkWritingAllowed()
Description copied from interface:DataHandler
Check if writing is allowed.- Specified by:
checkWritingAllowed
in interfaceDataHandler
-
getDatabasePath
public java.lang.String getDatabasePath()
Description copied from interface:DataHandler
Get the database path.- Specified by:
getDatabasePath
in interfaceDataHandler
- Returns:
- the database path
-
getMaxLengthInplaceLob
public int getMaxLengthInplaceLob()
Description copied from interface:DataHandler
Get the maximum length of a in-place large object- Specified by:
getMaxLengthInplaceLob
in interfaceDataHandler
- 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 interfaceDataHandler
- Parameters:
name
- the file namemode
- the modemustExist
- whether the file must already exist- Returns:
- the file
-
getDataHandler
public DataHandler getDataHandler()
Description copied from class:Session
Get the data handler object.- Specified by:
getDataHandler
in classSession
- 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 interfaceDataHandler
- 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 interfaceDataHandler
- 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 interfaceDataHandler
- Returns:
- the temp file deleter
-
getLobStorage
public LobStorageFrontend getLobStorage()
Description copied from interface:DataHandler
Get the lob storage mechanism to use.- Specified by:
getLobStorage
in interfaceDataHandler
- 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 interfaceDataHandler
- Parameters:
lobId
- the lob idhmac
- the message authentication codeoffset
- the offset within the lobbuff
- the target bufferoff
- the offset within the target bufferlength
- the number of bytes to read- Returns:
- the number of bytes read
-
getJavaObjectSerializer
public JavaObjectSerializer getJavaObjectSerializer()
Description copied from interface:CastDataProvider
Returns the custom Java object serializer, ornull
.- Specified by:
getJavaObjectSerializer
in interfaceCastDataProvider
- Returns:
- the custom Java object serializer, or
null
-
addTemporaryLob
public ValueLob addTemporaryLob(ValueLob v)
Description copied from class:Session
Add a temporary LOB, which is closed when the session commits.- Specified by:
addTemporaryLob
in classSession
- Parameters:
v
- the value- Returns:
- the specified value
-
getCompareMode
public CompareMode getCompareMode()
Description copied from interface:DataHandler
Return compare mode.- Specified by:
getCompareMode
in interfaceDataHandler
- Returns:
- Compare mode.
-
isRemote
public boolean isRemote()
Description copied from class:Session
Check if this session is remote or embedded.
-
getCurrentSchemaName
public java.lang.String getCurrentSchemaName()
Description copied from class:Session
Get current schema.- Specified by:
getCurrentSchemaName
in classSession
- Returns:
- the current schema name
-
setCurrentSchemaName
public void setCurrentSchemaName(java.lang.String schema)
Description copied from class:Session
Set current schema.- Specified by:
setCurrentSchemaName
in classSession
- Parameters:
schema
- the schema name
-
setNetworkConnectionInfo
public void setNetworkConnectionInfo(NetworkConnectionInfo networkConnectionInfo)
Description copied from class:Session
Sets the network connection information if possible.- Specified by:
setNetworkConnectionInfo
in classSession
- Parameters:
networkConnectionInfo
- the network connection information
-
getIsolationLevel
public IsolationLevel getIsolationLevel()
Description copied from class:Session
Returns the isolation level.- Specified by:
getIsolationLevel
in classSession
- Returns:
- the isolation level
-
setIsolationLevel
public void setIsolationLevel(IsolationLevel isolationLevel)
Description copied from class:Session
Sets the isolation level.- Specified by:
setIsolationLevel
in classSession
- Parameters:
isolationLevel
- the isolation level to set
-
getStaticSettings
public Session.StaticSettings getStaticSettings()
Description copied from class:Session
Returns static settings. These settings cannot be changed during lifecycle of session.- Specified by:
getStaticSettings
in classSession
- Returns:
- static settings
-
getDynamicSettings
public Session.DynamicSettings getDynamicSettings()
Description copied from class:Session
Returns dynamic settings. These settings can be changed during lifecycle of session.- Specified by:
getDynamicSettings
in classSession
- Returns:
- dynamic settings
-
getSettingsCommand
private CommandInterface getSettingsCommand(java.lang.String args)
-
currentTimestamp
public ValueTimestampTimeZone currentTimestamp()
Description copied from interface:CastDataProvider
Returns the current timestamp with maximum resolution. The value must be the same within a transaction or within execution of a command.- Specified by:
currentTimestamp
in interfaceCastDataProvider
- Returns:
- the current timestamp for CURRENT_TIMESTAMP(9)
-
currentTimeZone
public TimeZoneProvider currentTimeZone()
Description copied from interface:CastDataProvider
Returns the current time zone.- Specified by:
currentTimeZone
in interfaceCastDataProvider
- Returns:
- the current time zone
-
getMode
public Mode getMode()
Description copied from interface:CastDataProvider
Returns the database mode.- Specified by:
getMode
in interfaceCastDataProvider
- Returns:
- the database mode
-
getDatabaseMeta
public DatabaseMeta getDatabaseMeta()
Description copied from class:Session
Returns database meta information.- Specified by:
getDatabaseMeta
in classSession
- Returns:
- database meta information
-
isOldInformationSchema
public boolean isOldInformationSchema()
Description copied from class:Session
Returns whether INFORMATION_SCHEMA contains old-style tables.- Specified by:
isOldInformationSchema
in classSession
- Returns:
- whether INFORMATION_SCHEMA contains old-style tables
-
zeroBasedEnums
public boolean zeroBasedEnums()
Description copied from interface:CastDataProvider
Returns are ENUM values 0-based.- Specified by:
zeroBasedEnums
in interfaceCastDataProvider
- Returns:
- are ENUM values 0-based
-
-