Package org.h2.engine

Class 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.
    • 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 class Session
        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 class Session
        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).
        Specified by:
        cancel in class Session
      • 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 class Session
        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 class Session
        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
      • 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 remove
        count - 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 class Session
        Parameters:
        sql - the SQL statement
        fetchSize - 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.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in class Session
      • getTrace

        public Trace getTrace()
        Description copied from class: Session
        Get the trace object
        Specified by:
        getTrace in class Session
        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
      • 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.
        Specified by:
        isClosed in class Session
        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
      • 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
      • 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 class: Session
        Get the data handler object.
        Specified by:
        getDataHandler in class Session
        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()
      • 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
      • 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 class Session
        Parameters:
        v - the value
        Returns:
        the specified value
      • isRemote

        public boolean isRemote()
        Description copied from class: Session
        Check if this session is remote or embedded.
        Specified by:
        isRemote in class Session
        Returns:
        true if this session is remote
      • getCurrentSchemaName

        public java.lang.String getCurrentSchemaName()
        Description copied from class: Session
        Get current schema.
        Specified by:
        getCurrentSchemaName in class Session
        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 class Session
        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 class Session
        Parameters:
        networkConnectionInfo - the network connection information
      • setIsolationLevel

        public void setIsolationLevel​(IsolationLevel isolationLevel)
        Description copied from class: Session
        Sets the isolation level.
        Specified by:
        setIsolationLevel in class Session
        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 class Session
        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 class Session
        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 interface CastDataProvider
        Returns:
        the current timestamp for CURRENT_TIMESTAMP(9)
      • getDatabaseMeta

        public DatabaseMeta getDatabaseMeta()
        Description copied from class: Session
        Returns database meta information.
        Specified by:
        getDatabaseMeta in class Session
        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 class Session
        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 interface CastDataProvider
        Returns:
        are ENUM values 0-based