Package org.mariadb.jdbc.client.impl
Class StandardClient
- java.lang.Object
-
- org.mariadb.jdbc.client.impl.StandardClient
-
- All Implemented Interfaces:
AutoCloseable
,org.mariadb.jdbc.client.Client
- Direct Known Subclasses:
ReplayClient
public class StandardClient extends Object implements org.mariadb.jdbc.client.Client, AutoCloseable
Connection client
-
-
Field Summary
Fields Modifier and Type Field Description protected org.mariadb.jdbc.client.Context
context
connection contextprotected ExceptionFactory
exceptionFactory
connection exception factoryprotected Writer
writer
packet writer
-
Constructor Summary
Constructors Constructor Description StandardClient(Configuration conf, HostAddress hostAddress, ReentrantLock lock, boolean skipPostCommands)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort(Executor executor)
Abort current connectionprotected void
checkNotClosed()
Throw an exception if client is closedvoid
close()
Close clientvoid
closePrepare(Prepare prepare)
Close prepare commandString
createSessionVariableQuery(String serverTz)
Create session variable if configuration requires additional commands.protected void
destroySocket()
Closing socket in case of Connection error after socket creation.List<org.mariadb.jdbc.client.Completion>
execute(org.mariadb.jdbc.message.ClientMessage message, boolean canRedo)
Send client message and read resultList<org.mariadb.jdbc.client.Completion>
execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, boolean canRedo)
Send client message and read resultList<org.mariadb.jdbc.client.Completion>
execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)
Send client message and read resultList<org.mariadb.jdbc.client.Completion>
executePipeline(org.mariadb.jdbc.message.ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)
Send client messages pipelining and read resultorg.mariadb.jdbc.client.Context
getContext()
Get connection contextExceptionFactory
getExceptionFactory()
Get connection exception factoryHostAddress
getHostAddress()
Get connection hostint
getSocketTimeout()
get socket timeoutboolean
isClosed()
Is client closedboolean
isPrimary()
is current client writer or read-onlyorg.mariadb.jdbc.client.Completion
readPacket(org.mariadb.jdbc.message.ClientMessage message)
Read a MySQL packet from socketorg.mariadb.jdbc.client.Completion
readPacket(Statement stmt, org.mariadb.jdbc.message.ClientMessage message, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)
Read server response packet.void
readResponse(org.mariadb.jdbc.message.ClientMessage message)
Read server responseList<org.mariadb.jdbc.client.Completion>
readResponse(Statement stmt, org.mariadb.jdbc.message.ClientMessage message, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)
Read server responses for a client messagevoid
readStreamingResults(List<org.mariadb.jdbc.client.Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)
Read resultsvoid
reset()
Reset connectionint
sendQuery(org.mariadb.jdbc.message.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 timeout
-
-
-
Field Detail
-
context
protected org.mariadb.jdbc.client.Context context
connection context
-
exceptionFactory
protected final ExceptionFactory exceptionFactory
connection exception factory
-
writer
protected Writer writer
packet writer
-
-
Constructor Detail
-
StandardClient
public StandardClient(Configuration conf, HostAddress hostAddress, ReentrantLock lock, boolean skipPostCommands) throws SQLException
Constructor- Parameters:
conf
- configurationhostAddress
- hostlock
- thread lockerskipPostCommands
- must connection post command be skipped- Throws:
SQLException
- if connection fails
-
-
Method Detail
-
destroySocket
protected void destroySocket()
Closing socket in case of Connection error after socket creation.
-
createSessionVariableQuery
public String createSessionVariableQuery(String serverTz)
Create session variable if configuration requires additional commands.- Parameters:
serverTz
- server timezone- Returns:
- sql setting session command
-
setReadOnly
public void setReadOnly(boolean readOnly) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Switch to a writer/read-only connection, no effet on mono-connection- Specified by:
setReadOnly
in interfaceorg.mariadb.jdbc.client.Client
- Parameters:
readOnly
- must use read-only connection- Throws:
SQLException
- if any error occurs
-
sendQuery
public int sendQuery(org.mariadb.jdbc.message.ClientMessage message) throws SQLException
Send client message to server- Parameters:
message
- client message- Returns:
- number of command send
- Throws:
SQLException
- if socket error occurs
-
execute
public List<org.mariadb.jdbc.client.Completion> execute(org.mariadb.jdbc.message.ClientMessage message, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Send client message and read result- Specified by:
execute
in interfaceorg.mariadb.jdbc.client.Client
- Parameters:
message
- client messagecanRedo
- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException
- if execution fails
-
execute
public List<org.mariadb.jdbc.client.Completion> execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Send client message and read result- Specified by:
execute
in interfaceorg.mariadb.jdbc.client.Client
- Parameters:
message
- client messagestmt
- statementcanRedo
- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException
- if execution fails
-
executePipeline
public List<org.mariadb.jdbc.client.Completion> executePipeline(org.mariadb.jdbc.message.ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Send client messages pipelining and read result- Specified by:
executePipeline
in interfaceorg.mariadb.jdbc.client.Client
- 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<org.mariadb.jdbc.client.Completion> execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Send client message and read result- Specified by:
execute
in interfaceorg.mariadb.jdbc.client.Client
- 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<org.mariadb.jdbc.client.Completion> readResponse(Statement stmt, org.mariadb.jdbc.message.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
public void readResponse(org.mariadb.jdbc.message.ClientMessage message) throws SQLException
Read server response- Parameters:
message
- client message that was sent- Throws:
SQLException
- if any error occurs
-
closePrepare
public void closePrepare(Prepare prepare) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Close prepare command- Specified by:
closePrepare
in interfaceorg.mariadb.jdbc.client.Client
- Parameters:
prepare
- prepare command- Throws:
SQLException
- if any error occurs
-
readStreamingResults
public void readStreamingResults(List<org.mariadb.jdbc.client.Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Read results- Specified by:
readStreamingResults
in interfaceorg.mariadb.jdbc.client.Client
- 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
-
readPacket
public org.mariadb.jdbc.client.Completion readPacket(org.mariadb.jdbc.message.ClientMessage message) throws SQLException
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 org.mariadb.jdbc.client.Completion readPacket(Statement stmt, org.mariadb.jdbc.message.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:
- server response packets
-
checkNotClosed
protected void checkNotClosed() throws SQLException
Throw an exception if client is closed- Throws:
SQLException
- if closed
-
isClosed
public boolean isClosed()
Description copied from interface:org.mariadb.jdbc.client.Client
Is client closed- Specified by:
isClosed
in interfaceorg.mariadb.jdbc.client.Client
- Returns:
- close flag
-
getContext
public org.mariadb.jdbc.client.Context getContext()
Description copied from interface:org.mariadb.jdbc.client.Client
Get connection context- Specified by:
getContext
in interfaceorg.mariadb.jdbc.client.Client
- Returns:
- connection context
-
abort
public void abort(Executor executor) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Abort current connection- Specified by:
abort
in interfaceorg.mariadb.jdbc.client.Client
- Parameters:
executor
- executor- Throws:
SQLException
- if any error occurs
-
getSocketTimeout
public int getSocketTimeout()
Description copied from interface:org.mariadb.jdbc.client.Client
get socket timeout- Specified by:
getSocketTimeout
in interfaceorg.mariadb.jdbc.client.Client
- Returns:
- socket timeout
-
setSocketTimeout
public void setSocketTimeout(int milliseconds) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.Client
Set socket timeout- Specified by:
setSocketTimeout
in interfaceorg.mariadb.jdbc.client.Client
- Parameters:
milliseconds
- timeout- Throws:
SQLException
- if any error occurs
-
close
public void close()
Description copied from interface:org.mariadb.jdbc.client.Client
Close client- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceorg.mariadb.jdbc.client.Client
-
isPrimary
public boolean isPrimary()
Description copied from interface:org.mariadb.jdbc.client.Client
is current client writer or read-only- Specified by:
isPrimary
in interfaceorg.mariadb.jdbc.client.Client
- Returns:
- is primary
-
getExceptionFactory
public ExceptionFactory getExceptionFactory()
Description copied from interface:org.mariadb.jdbc.client.Client
Get connection exception factory- Specified by:
getExceptionFactory
in interfaceorg.mariadb.jdbc.client.Client
- Returns:
- connection exception factory
-
getHostAddress
public HostAddress getHostAddress()
Description copied from interface:org.mariadb.jdbc.client.Client
Get connection host- Specified by:
getHostAddress
in interfaceorg.mariadb.jdbc.client.Client
- Returns:
- connection host
-
reset
public void reset()
Description copied from interface:org.mariadb.jdbc.client.Client
Reset connection- Specified by:
reset
in interfaceorg.mariadb.jdbc.client.Client
-
-