Package org.mariadb.jdbc.client.impl
Class ConnectionHelper
- java.lang.Object
-
- org.mariadb.jdbc.client.impl.ConnectionHelper
-
public final class ConnectionHelper extends Object
Connection creation helper class
-
-
Constructor Summary
Constructors Constructor Description ConnectionHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
authenticationHandler(Credential credential, Writer writer, Reader reader, org.mariadb.jdbc.client.Context context)
Authentication swtich handlerstatic Socket
connectSocket(Configuration conf, HostAddress hostAddress)
Connect socketstatic Socket
createSocket(Configuration conf, HostAddress hostAddress)
Create socket accordingly to options.static byte
decideLanguage(InitialHandshakePacket handshake)
Default collation used for string exchanges with server.static long
initializeClientCapabilities(Configuration configuration, long serverCapabilities)
Initialize client capability according to configuration and server capabilities.static Credential
loadCredential(CredentialPlugin credentialPlugin, Configuration configuration, HostAddress hostAddress)
Load user/password plugin if configured to.static void
setSocketOption(Configuration conf, Socket socket)
Set socket optionstatic SSLSocket
sslWrapper(HostAddress hostAddress, Socket socket, long clientCapabilities, byte exchangeCharset, org.mariadb.jdbc.client.Context context, Writer writer)
Create SSL wrapperstatic Socket
standardSocket(Configuration conf, HostAddress hostAddress)
Use standard socket implementation.
-
-
-
Method Detail
-
createSocket
public static Socket createSocket(Configuration conf, HostAddress hostAddress) throws IOException, SQLException
Create socket accordingly to options.- Parameters:
conf
- Url optionshostAddress
- host ( mandatory but for named pipe / unix socket)- Returns:
- a nex socket
- Throws:
IOException
- if connection error occurSQLException
- in case of configuration error
-
standardSocket
public static Socket standardSocket(Configuration conf, HostAddress hostAddress) throws IOException, SQLException
Use standard socket implementation.- Parameters:
conf
- url optionshostAddress
- host to connect- Returns:
- socket
- Throws:
IOException
- in case of error establishing socket.SQLException
- in case host is null
-
connectSocket
public static Socket connectSocket(Configuration conf, HostAddress hostAddress) throws SQLException
Connect socket- Parameters:
conf
- configurationhostAddress
- 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
- configurationsocket
- 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
- configurationserverCapabilities
- 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
- credentialwriter
- socket writerreader
- socket readercontext
- connection context- Throws:
IOException
- if any socket error occursSQLException
- 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 pluginconfiguration
- configurationhostAddress
- 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
- hostsocket
- socketclientCapabilities
- client capabilitiesexchangeCharset
- connection charsetcontext
- connection contextwriter
- socket writer- Returns:
- SSLsocket
- Throws:
IOException
- if any socket error occursSQLException
- for any other kind of error
-
-