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
assignStream
(OutputStream out, InputStream in, Configuration conf, Long threadId) void
authenticationHandler
(Credential credential) protected void
Throw an exception if client is closedvoid
close()
Close clientvoid
closePrepare
(Prepare prepare) Close prepare commandprivate void
createSessionVariableQuery
(Context context) Create session variable if configuration requires additional commands.protected void
Closing socket in case of Connection error after socket creation.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
load server timezone and ensure this corresponds to client timezoneboolean
isClosed()
Is client closedboolean
is current client writer or read-onlyprivate 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
void
reset()
Reset connectionint
sendQuery
(ClientMessage message) Send client message to servervoid
setReadOnly
(boolean readOnly) Switch to a writer/read-only connection, no effet on mono-connectionvoid
setSocketTimeout
(int milliseconds) Set socket timeoutsslWrapper
(HostAddress hostAddress, Socket socket, long clientCapabilities, byte exchangeCharset, Context context, Writer writer) Create SSL wrapperprivate static boolean
validateFingerPrint
(AuthenticationPlugin authPlugin, byte[] validationHash, byte[] fingerPrint, Credential credential, byte[] seed)
-
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
-
authenticationHandler
- Parameters:
credential
- credential- 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
-
sslWrapper
public SSLSocket sslWrapper(HostAddress hostAddress, Socket socket, long clientCapabilities, byte exchangeCharset, 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
-
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
Create session variable if configuration requires additional commands.- Parameters:
context
- context- Returns:
- sql setting session command
-
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
-