Class ConnectionHelper


  • public final class ConnectionHelper
    extends Object
    Connection creation helper class
    • Constructor Detail

      • ConnectionHelper

        public ConnectionHelper()
    • Method Detail

      • createSocket

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

        public static Socket connectSocket​(Configuration conf,
                                           HostAddress hostAddress)
                                    throws SQLException
        Connect socket
        Parameters:
        conf - configuration
        hostAddress - host to connect
        Returns:
        socket
        Throws:
        SQLException - if hostname is required and not provided, or socket cannot be created
      • setSocketOption

        public static void setSocketOption​(Configuration conf,
                                           Socket socket)
                                    throws IOException
        Set socket option
        Parameters:
        conf - configuration
        socket - socket
        Throws:
        IOException - if any socket error occurs
      • initializeClientCapabilities

        public static long initializeClientCapabilities​(Configuration configuration,
                                                        long serverCapabilities)
        Initialize client capability according to configuration and server capabilities.
        Parameters:
        configuration - configuration
        serverCapabilities - server capabilities
        Returns:
        client capabilities
      • 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,
                                                 Writer writer,
                                                 Reader reader,
                                                 org.mariadb.jdbc.client.Context context)
                                          throws IOException,
                                                 SQLException
        Authentication swtich handler
        Parameters:
        credential - credential
        writer - socket writer
        reader - socket reader
        context - connection context
        Throws:
        IOException - if any socket error occurs
        SQLException - if any other kind of issue occurs
      • loadCredential

        public static Credential loadCredential​(CredentialPlugin credentialPlugin,
                                                Configuration configuration,
                                                HostAddress hostAddress)
                                         throws SQLException
        Load user/password plugin if configured to.
        Parameters:
        credentialPlugin - configuration credential plugin
        configuration - configuration
        hostAddress - current connection host address
        Returns:
        credentials
        Throws:
        SQLException - if configured credential plugin fail
      • sslWrapper

        public static SSLSocket sslWrapper​(HostAddress hostAddress,
                                           Socket socket,
                                           long clientCapabilities,
                                           byte exchangeCharset,
                                           org.mariadb.jdbc.client.Context context,
                                           Writer writer)
                                    throws IOException,
                                           SQLException
        Create SSL wrapper
        Parameters:
        hostAddress - host
        socket - socket
        clientCapabilities - client capabilities
        exchangeCharset - connection charset
        context - connection context
        writer - socket writer
        Returns:
        SSLsocket
        Throws:
        IOException - if any socket error occurs
        SQLException - for any other kind of error