Package org.mariadb.jdbc.client.impl
Class StandardClient
java.lang.Object
org.mariadb.jdbc.client.impl.StandardClient
- All Implemented Interfaces:
AutoCloseable
,Client
- Direct Known Subclasses:
ReplayClient
Connection client
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AuthenticationPlugin
private byte[]
private boolean
private final MutableByte
private Configuration
protected Context
connection contextprivate final boolean
protected final ExceptionFactory
connection exception factoryprivate HostAddress
private final ClosableLock
private static final Logger
private Reader
private static final Pattern
private final MutableByte
private Socket
private int
private ClientMessage
private Statement
protected Writer
packet writer -
Constructor Summary
ConstructorsConstructorDescriptionStandardClient
(Configuration conf, HostAddress hostAddress, ClosableLock lock, boolean skipPostCommands) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
Abort current connectionprivate void
addAutoCommitCommand
(Context context, List<String> commands) private void
addCharsetCommand
(Context context, List<String> commands) private void
addCustomSessionVariables
(List<String> commands) private void
addFixedOffsetTimeZone
(ZoneId connectionZoneId, List<String> commands) private void
addReadOnlyCommand
(Context context, List<String> commands) private void
addSessionTrackingCommand
(Context context, List<String> commands) private void
addTimeZoneCommand
(Context context, List<String> commands) private void
addTransactionIsolationCommand
(Context context, List<String> commands) private void
addTruncationCommand
(List<String> commands) private void
assignStream
(OutputStream out, InputStream in, Configuration conf, Long threadId) void
authenticationHandler
(Credential credential, HostAddress hostAddress) private String
buildFinalQuery
(List<String> commands) protected void
Throw an exception if client is closedvoid
close()
Close clientvoid
closePrepare
(Prepare prepare) Close prepare commandprivate void
private void
configureSslSocket
(SSLSocket sslSocket, Configuration conf) private void
private void
createAuthPlugin
(InitialHandshakePacket handshake, Credential credential, String authType) createSessionVariableQuery
(Context context) Creates a query string for setting session variables based on context and configuration.private SSLSocket
createSslSocket
(Configuration conf, TlsSocketPlugin socketPlugin, TrustManager[] trustManagers) protected void
Closing socket in case of Connection error after socket creation.private String
determineAuthType
(InitialHandshakePacket handshake) private SslMode
execute
(ClientMessage message, boolean canRedo) Send client message and read resultexecute
(ClientMessage message, Statement stmt, boolean canRedo) Send client message and read resultexecute
(ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) Send client message and read resultexecutePipeline
(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) Send client messages pipelining and read resultGet connection contextGet connection exception factoryGet connection hostGet current socket IP or null (for Pipe / unix socket)int
get socket timeoutprivate void
handleAuthentication
(InitialHandshakePacket handshake, long clientCapabilities) private void
private void
private InitialHandshakePacket
private SSLSocket
handleSSLConnection
(InitialHandshakePacket handshake, long clientCapabilities) private void
handleSslHandshake
(SSLSocket sslSocket, TrustManager[] trustManagers) private void
private void
load server timezone and ensure this corresponds to client timezoneprivate void
initializeContext
(InitialHandshakePacket handshake, long clientCapabilities) private boolean
isAutoCommitUpdateRequired
(Context context, boolean canRelyOnConnectionFlag) boolean
isClosed()
Is client closedprivate boolean
isDefaultCharsetSufficient
(Context context) boolean
is current client writer or read-onlyprivate boolean
isReliableConnectionFlag
(Context context) private boolean
isSessionTrackingSupported
(Context context) private void
readPacket
(ClientMessage message) Read a MySQL packet from socketreadPacket
(Statement stmt, ClientMessage message, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) Read server response packet.void
readResponse
(ClientMessage message) Read server responsereadResponse
(Statement stmt, ClientMessage message, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) Read server responses for a client messageprivate void
readResults
(Statement stmt, ClientMessage message, List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) void
readStreamingResults
(List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) Read resultsvoid
private boolean
requiresHostnameVerification
(SslMode sslMode) void
reset()
Reset connectionprivate void
sendHandshakeResponse
(InitialHandshakePacket handshake, long clientCapabilities, Credential credential, String authType) int
sendQuery
(ClientMessage message) Send client message to serverprivate void
sendSslRequest
(InitialHandshakePacket handshake, long clientCapabilities) void
setReadOnly
(boolean readOnly) Switch to a writer/read-only connection, no effet on mono-connectionvoid
setSocketTimeout
(int milliseconds) Set socket timeoutprivate long
setupClientCapabilities
(InitialHandshakePacket handshake) private void
setupCompression
(InputStream in, OutputStream out, long clientCapabilities, long threadId) private void
setupConnection
(boolean skipPostCommands) private void
private void
updateThreadIds
(InitialHandshakePacket handshake) private static boolean
validateFingerPrint
(AuthenticationPlugin authPlugin, byte[] validationHash, byte[] fingerPrint, Credential credential, byte[] seed) private void
private void
verifyHostname
(SSLSocket sslSocket, TlsSocketPlugin socketPlugin)
-
Field Details
-
logger
-
exceptionFactory
connection exception factory -
REDIRECT_PATTERN
-
socket
-
sequence
-
compressionSequence
-
lock
-
conf
-
authPlugin
-
hostAddress
-
disablePipeline
private final boolean disablePipeline -
context
connection context -
writer
packet writer -
closed
private boolean closed -
reader
-
certFingerprint
private byte[] certFingerprint -
streamStmt
-
streamMsg
-
socketTimeout
private int socketTimeout -
redirectConsumer
-
-
Constructor Details
-
StandardClient
public StandardClient(Configuration conf, HostAddress hostAddress, ClosableLock lock, boolean skipPostCommands) throws SQLException Constructor- Parameters:
conf
- configurationhostAddress
- hostlock
- thread lockerskipPostCommands
- must connection post command be skipped- Throws:
SQLException
- if connection fails
-
-
Method Details
-
setupConnection
- Throws:
SQLException
IOException
-
setupCompression
private void setupCompression(InputStream in, OutputStream out, long clientCapabilities, long threadId) -
handleSSLConnection
private SSLSocket handleSSLConnection(InitialHandshakePacket handshake, long clientCapabilities) throws SQLException, IOException - Throws:
SQLException
IOException
-
updateThreadIds
-
determineSslMode
-
validateServerSslCapability
- Throws:
SQLException
-
sendSslRequest
private void sendSslRequest(InitialHandshakePacket handshake, long clientCapabilities) throws IOException - Throws:
IOException
-
createSslSocket
private SSLSocket createSslSocket(Configuration conf, TlsSocketPlugin socketPlugin, TrustManager[] trustManagers) throws SQLException, IOException - Throws:
SQLException
IOException
-
configureSslSocket
- Throws:
SQLException
-
handleSslHandshake
private void handleSslHandshake(SSLSocket sslSocket, TrustManager[] trustManagers) throws IOException - Throws:
IOException
-
requiresHostnameVerification
-
verifyHostname
- Throws:
SQLException
-
configureTimeout
- Throws:
SQLException
-
handleServerHandshake
- Throws:
SQLException
IOException
-
throwHandshakeError
- Throws:
SQLException
-
setupClientCapabilities
-
initializeContext
-
handleAuthentication
private void handleAuthentication(InitialHandshakePacket handshake, long clientCapabilities) throws IOException, SQLException - Throws:
IOException
SQLException
-
determineAuthType
-
handleConnectionError
- Throws:
SQLException
-
handleTimeoutError
- Throws:
SQLTimeoutException
-
handleIOError
- Throws:
SQLException
-
sendHandshakeResponse
private void sendHandshakeResponse(InitialHandshakePacket handshake, long clientCapabilities, Credential credential, String authType) throws IOException - Throws:
IOException
-
createAuthPlugin
private void createAuthPlugin(InitialHandshakePacket handshake, Credential credential, String authType) -
authenticationHandler
public void authenticationHandler(Credential credential, HostAddress hostAddress) throws IOException, SQLException - Parameters:
credential
- credentialhostAddress
- host address- Throws:
IOException
- if any socket error occursSQLException
- if any other kind of issue occurs
-
validateFingerPrint
private static boolean validateFingerPrint(AuthenticationPlugin authPlugin, byte[] validationHash, byte[] fingerPrint, Credential credential, byte[] seed) -
redirect
-
assignStream
-
destroySocket
protected void destroySocket()Closing socket in case of Connection error after socket creation. -
handleTimezone
load server timezone and ensure this corresponds to client timezone- Throws:
SQLException
- if any socket error.
-
postConnectionQueries
- Throws:
SQLException
-
createSessionVariableQuery
Creates a query string for setting session variables based on context and configuration.- Parameters:
context
- the connection context- Returns:
- query string for setting session variables, or null if no variables need to be set
-
addAutoCommitCommand
-
isReliableConnectionFlag
-
isAutoCommitUpdateRequired
-
addTruncationCommand
-
addSessionTrackingCommand
-
isSessionTrackingSupported
-
addTimeZoneCommand
-
addFixedOffsetTimeZone
-
addTransactionIsolationCommand
-
addReadOnlyCommand
-
addCharsetCommand
-
isDefaultCharsetSufficient
-
addCustomSessionVariables
-
buildFinalQuery
-
setReadOnly
Description copied from interface:Client
Switch to a writer/read-only connection, no effet on mono-connection- Specified by:
setReadOnly
in interfaceClient
- Parameters:
readOnly
- must use read-only connection- Throws:
SQLException
- if any error occurs
-
sendQuery
Send client message to server- Parameters:
message
- client message- Returns:
- number of command send
- Throws:
SQLException
- if socket error occurs
-
execute
Description copied from interface:Client
Send client message and read result- Specified by:
execute
in interfaceClient
- Parameters:
message
- client messagecanRedo
- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException
- if execution fails
-
execute
public List<Completion> execute(ClientMessage message, Statement stmt, boolean canRedo) throws SQLException Description copied from interface:Client
Send client message and read result- Specified by:
execute
in interfaceClient
- Parameters:
message
- client messagestmt
- statementcanRedo
- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException
- if execution fails
-
executePipeline
public List<Completion> executePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException Description copied from interface:Client
Send client messages pipelining and read result- Specified by:
executePipeline
in interfaceClient
- Parameters:
messages
- client messagestmt
- statementfetchSize
- fetch sizemaxRows
- maximum number of rows. 0 = allresultSetConcurrency
- concurrencyresultSetType
- result-set typecloseOnCompletion
- close statement on completioncanRedo
- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException
- if any error occurs
-
execute
public List<Completion> execute(ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException Description copied from interface:Client
Send client message and read result- Specified by:
execute
in interfaceClient
- Parameters:
message
- client messagestmt
- statementfetchSize
- fetch sizemaxRows
- maximum number of rows. 0 = allresultSetConcurrency
- concurrencyresultSetType
- result-set typecloseOnCompletion
- close statement on completioncanRedo
- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException
- if any error occurs
-
readResponse
public List<Completion> readResponse(Statement stmt, ClientMessage message, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException Read server responses for a client message- Parameters:
stmt
- statement that issue the messagemessage
- client message sentfetchSize
- fetch sizemaxRows
- maximum number of rowsresultSetConcurrency
- concurrencyresultSetType
- result-set typecloseOnCompletion
- close statement on resultset completion- Returns:
- list of result
- Throws:
SQLException
- if any error occurs
-
readResponse
Read server response- Parameters:
message
- client message that was sent- Throws:
SQLException
- if any error occurs
-
closePrepare
Description copied from interface:Client
Close prepare command- Specified by:
closePrepare
in interfaceClient
- Parameters:
prepare
- prepare command- Throws:
SQLException
- if any error occurs
-
readStreamingResults
public void readStreamingResults(List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException Description copied from interface:Client
Read results- Specified by:
readStreamingResults
in interfaceClient
- Parameters:
completions
- List that will have the new resultsfetchSize
- fetch sizemaxRows
- maximum number of rows. 0 = allresultSetConcurrency
- concurrencyresultSetType
- result-set typecloseOnCompletion
- close statement on completion- Throws:
SQLException
- if any error occurs
-
readResults
private void readResults(Statement stmt, ClientMessage message, List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException - Throws:
SQLException
-
readPacket
Read a MySQL packet from socket- Parameters:
message
- client message issuing the result- Returns:
- a mysql result
- Throws:
SQLException
- if any error occurs
-
readPacket
public Completion readPacket(Statement stmt, ClientMessage message, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException Read server response packet.- Parameters:
stmt
- current statement (null if internal)message
- current messagefetchSize
- default fetch sizemaxRows
- maximum row numberresultSetConcurrency
- concurrencyresultSetType
- typecloseOnCompletion
- must resultset close statement on completion- Returns:
- Completion
- Throws:
SQLException
- if any exception- See Also:
-
checkNotClosed
Throw an exception if client is closed- Throws:
SQLException
- if closed
-
closeSocket
private void closeSocket() -
isClosed
public boolean isClosed()Description copied from interface:Client
Is client closed -
getContext
Description copied from interface:Client
Get connection context- Specified by:
getContext
in interfaceClient
- Returns:
- connection context
-
abort
Description copied from interface:Client
Abort current connection- Specified by:
abort
in interfaceClient
- Parameters:
executor
- executor- Throws:
SQLException
- if any error occurs
-
getSocketTimeout
public int getSocketTimeout()Description copied from interface:Client
get socket timeout- Specified by:
getSocketTimeout
in interfaceClient
- Returns:
- socket timeout
-
setSocketTimeout
Description copied from interface:Client
Set socket timeout- Specified by:
setSocketTimeout
in interfaceClient
- Parameters:
milliseconds
- timeout- Throws:
SQLException
- if any error occurs
-
close
public void close()Description copied from interface:Client
Close client- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceClient
-
getSocketIp
Description copied from interface:Client
Get current socket IP or null (for Pipe / unix socket)- Specified by:
getSocketIp
in interfaceClient
- Returns:
- Socket current IP
-
isPrimary
public boolean isPrimary()Description copied from interface:Client
is current client writer or read-only -
getExceptionFactory
Description copied from interface:Client
Get connection exception factory- Specified by:
getExceptionFactory
in interfaceClient
- Returns:
- connection exception factory
-
getHostAddress
Description copied from interface:Client
Get connection host- Specified by:
getHostAddress
in interfaceClient
- Returns:
- connection host
-
reset
public void reset()Description copied from interface:Client
Reset connection
-