Class ConnectionHelper


  • public final class ConnectionHelper
    extends java.lang.Object
    Connection creation helper class
    • 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
        Connect socket
        Parameters:
        conf - configuration
        hostAddress - host to connect
        Returns:
        socket
        Throws:
        java.sql.SQLException - if hostname is required and not provided, or socket cannot be created
      • initializeClientCapabilities

        public static long initializeClientCapabilities​(Configuration configuration,
                                                        long serverCapabilities,
                                                        HostAddress hostAddress)
        Initialize client capability according to configuration and server capabilities.
        Parameters:
        configuration - configuration
        serverCapabilities - server capabilities
        hostAddress - host address server
        Returns:
        client capabilities
      • loadCredential

        public static Credential loadCredential​(CredentialPlugin credentialPlugin,
                                                Configuration configuration,
                                                HostAddress hostAddress)
                                         throws java.sql.SQLException
        Load user/password plugin if configured to.
        Parameters:
        credentialPlugin - configuration credential plugin
        configuration - configuration
        hostAddress - current connection host address
        Returns:
        credentials
        Throws:
        java.sql.SQLException - if configured credential plugin fail
      • 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