Class ConnectionHelper


  • public final class ConnectionHelper
    extends java.lang.Object
    • Constructor Detail

      • ConnectionHelper

        public ConnectionHelper()
    • Method Detail

      • createSocket

        public static java.net.Socket createSocket​(Configuration conf,
                                                   HostAddress hostAddress)
                                            throws java.io.IOException,
                                                   java.sql.SQLException
        Create socket accordingly to options.
        Parameters:
        conf - Url options
        hostAddress - host ( mandatory but for named pipe / unix socket)
        Returns:
        a nex socket
        Throws:
        java.io.IOException - if connection error occur
        java.sql.SQLException - in case of configuration error
      • standardSocket

        public static java.net.Socket standardSocket​(Configuration conf,
                                                     HostAddress hostAddress)
                                              throws java.io.IOException,
                                                     java.sql.SQLException
        Use standard socket implementation.
        Parameters:
        conf - url options
        hostAddress - host to connect
        Returns:
        socket
        Throws:
        java.io.IOException - in case of error establishing socket.
        java.sql.SQLException - in case host is null
      • connectSocket

        public static java.net.Socket connectSocket​(Configuration conf,
                                                    HostAddress hostAddress)
                                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • initializeClientCapabilities

        public static long initializeClientCapabilities​(Configuration configuration,
                                                        long serverCapabilities)
      • decideLanguage

        public static byte decideLanguage​(InitialHandshakePacket handshake)
        Default collation used for string exchanges with server. Always return 4 bytes utf8 collation for server that permit it.
        Parameters:
        handshake - initial handshake packet
        Returns:
        collation byte
      • authenticationHandler

        public static void authenticationHandler​(Credential credential,
                                                 PacketWriter writer,
                                                 PacketReader reader,
                                                 Context context)
                                          throws java.sql.SQLException,
                                                 java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • sslWrapper

        public static javax.net.ssl.SSLSocket sslWrapper​(HostAddress hostAddress,
                                                         java.net.Socket socket,
                                                         long clientCapabilities,
                                                         byte exchangeCharset,
                                                         Context context,
                                                         PacketWriter writer)
                                                  throws java.sql.SQLException,
                                                         java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • enabledSslProtocolSuites

        static void enabledSslProtocolSuites​(javax.net.ssl.SSLSocket sslSocket,
                                             Configuration conf)
                                      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's community versions ≥ 5.7.10 is compiled with yaSSL, so max TLS is TLSv1.1.
        Parameters:
        sslSocket - current sslSocket
        Throws:
        java.sql.SQLException - if protocol isn't a supported protocol
      • enabledSslCipherSuites

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