Class AbstractConnectProtocol

    • Field Detail

      • SESSION_QUERY

        private static final byte[] SESSION_QUERY
      • IS_MASTER_QUERY

        private static final byte[] IS_MASTER_QUERY
      • logger

        private static final Logger logger
      • lock

        protected final java.util.concurrent.locks.ReentrantLock lock
      • urlParser

        protected final UrlParser urlParser
      • options

        protected final Options options
      • username

        private final java.lang.String username
      • password

        private final java.lang.String password
      • hasWarnings

        public boolean hasWarnings
      • activeStreamingResult

        public Results activeStreamingResult
      • serverStatus

        public short serverStatus
      • autoIncrementIncrement

        protected int autoIncrementIncrement
      • socket

        protected java.net.Socket socket
      • readOnly

        protected boolean readOnly
      • connected

        protected volatile boolean connected
      • explicitClosed

        protected boolean explicitClosed
      • database

        protected java.lang.String database
      • serverThreadId

        protected long serverThreadId
      • eofDeprecated

        protected boolean eofDeprecated
      • serverCapabilities

        protected long serverCapabilities
      • hostFailed

        private boolean hostFailed
      • serverVersion

        private java.lang.String serverVersion
      • serverMariaDb

        private boolean serverMariaDb
      • majorVersion

        private int majorVersion
      • minorVersion

        private int minorVersion
      • patchVersion

        private int patchVersion
      • timeZone

        private java.util.TimeZone timeZone
      • socketTimeout

        protected int socketTimeout
    • Constructor Detail

      • AbstractConnectProtocol

        public AbstractConnectProtocol​(UrlParser urlParser,
                                       GlobalStateInfo globalInfo,
                                       java.util.concurrent.locks.ReentrantLock lock)
        Get a protocol instance.
        Parameters:
        urlParser - connection URL information
        globalInfo - server global variables information
        lock - the lock for thread synchronisation
    • Method Detail

      • close

        public void close()
        Closes socket and stream readers/writers Attempts graceful shutdown.
        Specified by:
        close in interface Protocol
      • abort

        public void abort()
        Force closes socket and stream readers/writers.
        Specified by:
        abort in interface Protocol
      • forceAbort

        private void forceAbort()
      • abortActiveStream

        private void abortActiveStream()
      • skip

        public void skip()
                  throws java.sql.SQLException
        Skip packets not read that are not needed. Packets are read according to needs. If some data have not been read before next execution, skip it. Lock must be set before using this method
        Specified by:
        skip in interface Protocol
        Throws:
        java.sql.SQLException - exception
      • cleanMemory

        private void cleanMemory()
      • setServerStatus

        public void setServerStatus​(short serverStatus)
        Specified by:
        setServerStatus in interface Protocol
      • removeHasMoreResults

        public void removeHasMoreResults()
        Remove flag has more results.
        Specified by:
        removeHasMoreResults in interface Protocol
      • initializeSocketOption

        private void initializeSocketOption()
        InitializeSocketOption.
      • connect

        public void connect()
                     throws java.sql.SQLException
        Connect to currentHost.
        Specified by:
        connect in interface Protocol
        Throws:
        java.sql.SQLException - exception
      • connect

        private void connect​(java.lang.String host,
                             int port)
                      throws java.sql.SQLException,
                             java.io.IOException
        Connect the client and perform handshake.
        Parameters:
        host - host
        port - port
        Throws:
        java.sql.SQLException - handshake error, e.g wrong user or password
        java.io.IOException - connection error (host/port not available)
      • sendPipelineAdditionalData

        private void sendPipelineAdditionalData()
                                         throws java.io.IOException
        Send all additional needed values. Command are send one after the other, assuming that command are less than 65k (minimum hosts TCP/IP buffer size)
        Throws:
        java.io.IOException - if socket exception occur
      • sendSessionInfos

        private void sendSessionInfos()
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • sendRequestSessionVariables

        private void sendRequestSessionVariables()
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readRequestSessionVariables

        private void readRequestSessionVariables​(java.util.Map<java.lang.String,​java.lang.String> serverData)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • sendCreateDatabaseIfNotExist

        private void sendCreateDatabaseIfNotExist​(java.lang.String quotedDb)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • sendUseDatabaseIfNotExist

        private void sendUseDatabaseIfNotExist​(java.lang.String quotedDb)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readPipelineAdditionalData

        private void readPipelineAdditionalData​(java.util.Map<java.lang.String,​java.lang.String> serverData)
                                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • requestSessionDataWithShow

        private void requestSessionDataWithShow​(java.util.Map<java.lang.String,​java.lang.String> serverData)
                                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • additionalData

        private void additionalData​(java.util.Map<java.lang.String,​java.lang.String> serverData)
                             throws java.io.IOException,
                                    java.sql.SQLException
        Throws:
        java.io.IOException
        java.sql.SQLException
      • ensureClosingSocketOnException

        private void ensureClosingSocketOnException()
      • isClosed

        public boolean isClosed()
        Is the connection closed.
        Specified by:
        isClosed in interface Protocol
        Returns:
        true if the connection is closed
      • handleConnectionPhases

        private void handleConnectionPhases​(java.lang.String host)
                                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • authentication

        private void authentication​(byte exchangeCharset,
                                    long clientCapabilities,
                                    byte packetSeq,
                                    ReadInitialHandShakePacket greetingPacket)
                             throws java.sql.SQLException,
                                    java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • initializeClientCapabilities

        private long initializeClientCapabilities​(long serverCapabilities)
      • loadCalendar

        private void loadCalendar​(java.lang.String srvTimeZone,
                                  java.lang.String srvSystemTimeZone)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • checkIfMaster

        public boolean checkIfMaster()
                              throws java.sql.SQLException
        Check that current connection is a master connection (not read-only).
        Specified by:
        checkIfMaster in interface Protocol
        Returns:
        true if master
        Throws:
        java.sql.SQLException - if requesting infos for server fail.
      • decideLanguage

        private byte decideLanguage​(int serverLanguage)
        Default collation used for string exchanges with server.
        Parameters:
        serverLanguage - server default collation
        Returns:
        collation byte
      • readEofPacket

        public void readEofPacket()
                           throws java.sql.SQLException,
                                  java.io.IOException
        Check that next read packet is a End-of-file packet.
        Specified by:
        readEofPacket in interface Protocol
        Throws:
        java.sql.SQLException - if not a End-of-file packet
        java.io.IOException - if connection error occur
      • skipEofPacket

        public void skipEofPacket()
                           throws java.sql.SQLException,
                                  java.io.IOException
        Check that next read packet is a End-of-file packet.
        Specified by:
        skipEofPacket in interface Protocol
        Throws:
        java.sql.SQLException - if not a End-of-file packet
        java.io.IOException - if connection error occur
      • isMasterConnection

        public boolean isMasterConnection()
        Indicate if current protocol is a master protocol.
        Specified by:
        isMasterConnection in interface Protocol
        Returns:
        is master flag
      • sendPipelineCheckMaster

        private void sendPipelineCheckMaster()
                                      throws java.io.IOException
        Send query to identify if server is master.
        Throws:
        java.io.IOException - in case of socket error.
      • readPipelineCheckMaster

        public void readPipelineCheckMaster()
                                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • connectWithoutProxy

        public void connectWithoutProxy()
                                 throws java.sql.SQLException
        Connect without proxy. (use basic failover implementation)
        Specified by:
        connectWithoutProxy in interface Protocol
        Throws:
        java.sql.SQLException - exception
      • setReadonly

        public void setReadonly​(boolean readOnly)
        Specified by:
        setReadonly in interface Protocol
      • getHost

        public java.lang.String getHost()
        Specified by:
        getHost in interface Protocol
      • getPort

        public int getPort()
        Specified by:
        getPort in interface Protocol
      • getDatabase

        public java.lang.String getDatabase()
        Specified by:
        getDatabase in interface Protocol
      • getUsername

        public java.lang.String getUsername()
        Specified by:
        getUsername in interface Protocol
      • parseVersion

        private void parseVersion()
      • enabledSslProtocolSuites

        private void enabledSslProtocolSuites​(javax.net.ssl.SSLSocket sslSocket)
                                       throws java.sql.SQLException
        Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1". MariaDB versions ≥ 10.0.15 and ≥ 5.5.41 supports TLSv1.2 if compiled with openSSL (default). MySQL community versions ≥ 5.7.10 is compile with yaSSL, so max TLS is TLSv1.1.
        Parameters:
        sslSocket - current sslSocket
        Throws:
        java.sql.SQLException - if protocol isn't a supported protocol
      • enabledSslCipherSuites

        private void enabledSslCipherSuites​(javax.net.ssl.SSLSocket sslSocket)
                                     throws java.sql.SQLException
        Set ssl socket cipher according to options.
        Parameters:
        sslSocket - current ssl socket
        Throws:
        java.sql.SQLException - if a cipher isn't known
      • versionGreaterOrEqual

        public boolean versionGreaterOrEqual​(int major,
                                             int minor,
                                             int patch)
        Utility method to check if database version is greater than parameters.
        Specified by:
        versionGreaterOrEqual in interface Protocol
        Parameters:
        major - major version
        minor - minor version
        patch - patch version
        Returns:
        true if version is greater than parameters
      • hasWarnings

        public boolean hasWarnings()
        Has warnings.
        Specified by:
        hasWarnings in interface Protocol
        Returns:
        true if as warnings.
      • isConnected

        public boolean isConnected()
        Is connected.
        Specified by:
        isConnected in interface Protocol
        Returns:
        true if connected
      • getSocket

        public java.net.Socket getSocket()
        Specified by:
        getSocket in interface Protocol
      • getTimeZone

        public java.util.TimeZone getTimeZone()
        Specified by:
        getTimeZone in interface Protocol
      • setHasWarnings

        public void setHasWarnings​(boolean hasWarnings)
        Specified by:
        setHasWarnings in interface Protocol
      • removeActiveStreamingResult

        public void removeActiveStreamingResult()
        Remove exception result and since totally fetched, set fetch size to 0.
        Specified by:
        removeActiveStreamingResult in interface Protocol
      • getLock

        public java.util.concurrent.locks.ReentrantLock getLock()
        Specified by:
        getLock in interface Protocol
      • executeQuery

        public abstract void executeQuery​(java.lang.String sql)
                                   throws java.sql.SQLException
        Specified by:
        executeQuery in interface Protocol
        Throws:
        java.sql.SQLException
      • changeSocketTcpNoDelay

        public void changeSocketTcpNoDelay​(boolean setTcpNoDelay)
        Change Socket TcpNoDelay option.
        Specified by:
        changeSocketTcpNoDelay in interface Protocol
        Parameters:
        setTcpNoDelay - value to set.
      • changeSocketSoTimeout

        public void changeSocketSoTimeout​(int setSoTimeout)
                                   throws java.net.SocketException
        Specified by:
        changeSocketSoTimeout in interface Protocol
        Throws:
        java.net.SocketException
      • getTraces

        public java.lang.String getTraces()
        Get a String containing readable information about last 10 send/received packets.
        Specified by:
        getTraces in interface Protocol
        Returns:
        String value