Class AbstractConnectProtocol

    • Field Detail

      • SESSION_QUERY

        private static final byte[] SESSION_QUERY
      • IS_MASTER_QUERY

        private static final byte[] IS_MASTER_QUERY
      • CHECK_GALERA_STATE_QUERY

        protected static final java.lang.String CHECK_GALERA_STATE_QUERY
        See Also:
        Constant Field Values
      • 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
      • 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
      • socketTimeout

        protected int socketTimeout
      • galeraAllowedStates

        protected final java.util.List<java.lang.String> galeraAllowedStates
      • 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
    • Constructor Detail

      • AbstractConnectProtocol

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

      • createSocket

        private static java.net.Socket createSocket​(java.lang.String host,
                                                    int port,
                                                    Options options)
                                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • initializeClientCapabilities

        private static long initializeClientCapabilities​(Options options,
                                                         long serverCapabilities,
                                                         java.lang.String database)
      • enabledSslProtocolSuites

        private static void enabledSslProtocolSuites​(javax.net.ssl.SSLSocket sslSocket,
                                                     Options options)
                                              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 static void enabledSslCipherSuites​(javax.net.ssl.SSLSocket sslSocket,
                                                   Options options)
                                            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
      • 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
      • connect

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

        private void createConnection​(HostAddress hostAddress,
                                      java.lang.String username)
                               throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • destroySocket

        public void destroySocket()
        Closing socket in case of Connection error after socket creation.
      • sslWrapper

        private void sslWrapper​(java.lang.String host,
                                java.net.Socket socket,
                                Options options,
                                long serverCapabilities,
                                long clientCapabilities,
                                byte exchangeCharset,
                                long serverThreadId)
                         throws java.sql.SQLException,
                                java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • authenticationHandler

        private void authenticationHandler​(byte exchangeCharset,
                                           long clientCapabilities,
                                           java.lang.String authenticationPluginType,
                                           byte[] seed,
                                           Options options,
                                           java.lang.String database,
                                           Credential credential,
                                           java.lang.String host)
                                    throws java.sql.SQLException,
                                           java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • compressionHandler

        private void compressionHandler​(Options options)
      • assignStream

        private void assignStream​(java.net.Socket socket,
                                  Options options)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • galeraStateValidation

        private void galeraStateValidation()
                                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • postConnectionQueries

        private void postConnectionQueries()
                                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • 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
      • isClosed

        public boolean isClosed()
        Is the connection closed.
        Specified by:
        isClosed in interface Protocol
        Returns:
        true if the connection is closed
      • 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
      • shouldReconnectWithoutProxy

        public boolean shouldReconnectWithoutProxy()
        Indicate for Old reconnection if can reconnect without throwing exception.
        Specified by:
        shouldReconnectWithoutProxy in interface Protocol
        Returns:
        true if can reconnect without issue
      • 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​(java.lang.String serverVersion)
      • 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