public abstract class AbstractConnectProtocol extends java.lang.Object implements Protocol
Modifier and Type | Field and Description |
---|---|
Results |
activeStreamingResult |
protected int |
autoIncrementIncrement |
protected boolean |
connected |
protected HostAddress |
currentHost |
protected java.lang.String |
database |
int |
dataTypeMappingFlags |
protected boolean |
eofDeprecated |
protected boolean |
explicitClosed |
boolean |
hasWarnings |
private boolean |
hostFailed |
static byte[] |
IS_MASTER_QUERY |
protected java.util.concurrent.locks.ReentrantLock |
lock |
private static Logger |
logger |
private int |
majorVersion |
private int |
minorVersion |
protected Options |
options |
private java.lang.String |
password |
private int |
patchVersion |
protected FailoverProxy |
proxy |
protected PacketInputStream |
reader |
protected boolean |
readOnly |
protected long |
serverCapabilities |
private java.util.Map<java.lang.String,java.lang.String> |
serverData |
private boolean |
serverMariaDb |
protected ServerPrepareStatementCache |
serverPrepareStatementCache |
short |
serverStatus |
protected long |
serverThreadId |
private java.lang.String |
serverVersion |
static byte[] |
SESSION_QUERY |
protected java.net.Socket |
socket |
private java.util.TimeZone |
timeZone |
private LruTraceCache |
traceCache |
protected UrlParser |
urlParser |
private java.lang.String |
username |
protected PacketOutputStream |
writer |
Constructor and Description |
---|
AbstractConnectProtocol(UrlParser urlParser,
java.util.concurrent.locks.ReentrantLock lock)
Get a protocol instance.
|
Modifier and Type | Method and Description |
---|---|
private void |
additionalData() |
private void |
authentication(byte exchangeCharset,
long clientCapabilities,
byte[] seed,
byte packetSeq,
java.lang.String plugin) |
void |
changeSocketSoTimeout(int setSoTimeout) |
void |
changeSocketTcpNoDelay(boolean setTcpNoDelay)
Change Socket TcpNoDelay option.
|
boolean |
checkIfMaster()
Check that current connection is a master connection (not read-only)
|
void |
close()
Closes socket and stream readers/writers Attempts graceful shutdown.
|
protected static void |
close(PacketInputStream packetInputStream,
PacketOutputStream packetOutputStream,
java.net.Socket socket) |
void |
connect()
Connect to currentHost.
|
private void |
connect(java.lang.String host,
int port)
Connect the client and perform handshake.
|
void |
connectWithoutProxy()
Connect without proxy.
|
private byte |
decideLanguage(byte serverLanguage) |
protected void |
enabledSslCipherSuites(javax.net.ssl.SSLSocket sslSocket)
Set ssl socket cipher according to options.
|
protected void |
enabledSslProtocolSuites(javax.net.ssl.SSLSocket sslSocket)
Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1".
|
private void |
ensureClosingSocketOnException() |
abstract void |
executeQuery(java.lang.String sql) |
Results |
getActiveStreamingResult() |
java.lang.String |
getDatabase() |
int |
getDataTypeMappingFlags() |
java.lang.String |
getHost() |
HostAddress |
getHostAddress() |
java.util.concurrent.locks.ReentrantLock |
getLock() |
int |
getMajorServerVersion() |
int |
getMinorServerVersion() |
Options |
getOptions() |
java.lang.String |
getPassword() |
boolean |
getPinGlobalTxToPhysicalConnection() |
int |
getPort() |
FailoverProxy |
getProxy() |
PacketInputStream |
getReader() |
boolean |
getReadonly() |
java.lang.String |
getServerData(java.lang.String code) |
long |
getServerThreadId() |
java.lang.String |
getServerVersion() |
private javax.net.ssl.SSLSocketFactory |
getSslSocketFactory() |
java.util.TimeZone |
getTimeZone() |
java.lang.String |
getTraces() |
UrlParser |
getUrlParser() |
java.lang.String |
getUsername() |
PacketOutputStream |
getWriter() |
private void |
handleConnectionPhases() |
boolean |
hasMoreResults() |
boolean |
hasWarnings()
Has warnings.
|
private long |
initializeClientCapabilities(long serverCapabilities) |
private void |
initializeSocketOption()
InitializeSocketOption.
|
boolean |
isClosed()
Is the connection closed.
|
boolean |
isConnected()
Is connected.
|
boolean |
isEofDeprecated() |
boolean |
isExplicitClosed() |
boolean |
isMasterConnection()
Indicate if current protocol is a master protocol.
|
private boolean |
isServerLanguageUtf8mb4(byte serverLanguage) |
boolean |
isServerMariaDb() |
private void |
loadCalendar() |
private javax.net.ssl.KeyManager |
loadClientCerts(java.lang.String keyStoreUrl,
java.lang.String keyStorePassword,
java.lang.String keyPassword) |
boolean |
mustBeMasterConnection() |
boolean |
noBackslashEscapes() |
private void |
parseVersion() |
ServerPrepareStatementCache |
prepareStatementCache() |
void |
readEofPacket()
Check that next read packet is a End-of-file packet.
|
private void |
readPipelineAdditionalData() |
void |
readPipelineCheckMaster() |
private void |
readRequestSessionVariables() |
void |
removeActiveStreamingResult()
Remove exception result and since totally fetched, set fetch size to 0.
|
void |
removeHasMoreResults() |
private void |
requestSessionDataWithShow() |
private void |
sendCreateDatabaseIfNotExist(java.lang.String quotedDb) |
private void |
sendPipelineAdditionalData()
Send all additional needed values.
|
void |
sendPipelineCheckMaster()
Send query to identify if server is master.
|
private void |
sendRequestSessionVariables() |
private void |
sendSessionInfos() |
private void |
sendUseDatabaseIfNotExist(java.lang.String quotedDb) |
boolean |
sessionStateAware() |
void |
setActiveStreamingResult(Results activeStreamingResult) |
private void |
setDataTypeMappingFlags() |
void |
setHasWarnings(boolean hasWarnings) |
void |
setHostAddress(HostAddress host) |
void |
setHostFailedWithoutProxy() |
void |
setProxy(FailoverProxy proxy) |
void |
setReadonly(boolean readOnly) |
void |
setServerStatus(short serverStatus) |
boolean |
shouldReconnectWithoutProxy() |
void |
skip()
Skip packets not read that are not needed.
|
void |
skipEofPacket()
Check that next read packet is a End-of-file packet.
|
boolean |
versionGreaterOrEqual(int major,
int minor,
int patch)
Utility method to check if database version is greater than parameters.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPrepareInCache, cancelCurrentQuery, closeExplicit, executeBatch, executeBatchMulti, executeBatchMultiple, executeBatchRewrite, executePreparedQuery, executeQuery, executeQuery, executeQuery, executeQuery, forceReleasePrepareStatement, forceReleaseWaitingPrepareStatement, getAutocommit, getAutoIncrementIncrement, getMaxRows, getResult, getTimeout, getTransactionIsolationLevel, handleIoException, inTransaction, isInterrupted, ping, prepare, prepareAndExecute, prepareAndExecutes, prolog, prologProxy, releasePrepareStatement, resetStateAfterFailover, rollback, setActiveFutureTask, setCatalog, setInternalMaxRows, setLocalInfileInputStream, setMaxRows, setTimeout, setTransactionIsolation, stopIfInterrupted
public static final byte[] SESSION_QUERY
public static final byte[] IS_MASTER_QUERY
private static Logger logger
protected final java.util.concurrent.locks.ReentrantLock lock
protected final UrlParser urlParser
protected final Options options
private final java.lang.String username
private final java.lang.String password
public boolean hasWarnings
public Results activeStreamingResult
public int dataTypeMappingFlags
public short serverStatus
protected int autoIncrementIncrement
protected java.net.Socket socket
protected PacketOutputStream writer
protected boolean readOnly
protected PacketInputStream reader
protected HostAddress currentHost
protected FailoverProxy proxy
protected volatile boolean connected
protected boolean explicitClosed
protected java.lang.String database
protected long serverThreadId
protected ServerPrepareStatementCache serverPrepareStatementCache
protected boolean eofDeprecated
protected long serverCapabilities
private boolean hostFailed
private java.lang.String serverVersion
private boolean serverMariaDb
private int majorVersion
private int minorVersion
private int patchVersion
private java.util.Map<java.lang.String,java.lang.String> serverData
private java.util.TimeZone timeZone
private LruTraceCache traceCache
public AbstractConnectProtocol(UrlParser urlParser, java.util.concurrent.locks.ReentrantLock lock)
urlParser
- connection URL infoslock
- the lock for thread synchronisationprotected static void close(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, java.net.Socket socket) throws java.sql.SQLException
java.sql.SQLException
public void close()
public void skip() throws java.sql.SQLException
Lock must be set before using this method
public void setServerStatus(short serverStatus)
setServerStatus
in interface Protocol
public void removeHasMoreResults()
removeHasMoreResults
in interface Protocol
private javax.net.ssl.SSLSocketFactory getSslSocketFactory() throws java.sql.SQLException
java.sql.SQLException
private javax.net.ssl.KeyManager loadClientCerts(java.lang.String keyStoreUrl, java.lang.String keyStorePassword, java.lang.String keyPassword) throws java.sql.SQLException
java.sql.SQLException
private void initializeSocketOption()
public void connect() throws java.sql.SQLException
private void connect(java.lang.String host, int port) throws java.sql.SQLException, java.io.IOException
host
- hostport
- portjava.sql.SQLException
- handshake error, e.g wrong user or passwordjava.io.IOException
- connection error (host/port not available)private void sendPipelineAdditionalData() throws java.io.IOException, java.sql.SQLException
java.io.IOException
- if socket exception occurjava.sql.SQLException
- if query exception occurprivate void sendSessionInfos() throws java.io.IOException
java.io.IOException
private void sendRequestSessionVariables() throws java.io.IOException
java.io.IOException
private void readRequestSessionVariables() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void sendCreateDatabaseIfNotExist(java.lang.String quotedDb) throws java.io.IOException
java.io.IOException
private void sendUseDatabaseIfNotExist(java.lang.String quotedDb) throws java.io.IOException
java.io.IOException
private void readPipelineAdditionalData() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void requestSessionDataWithShow() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void additionalData() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void ensureClosingSocketOnException()
public boolean isClosed()
private void handleConnectionPhases() throws java.sql.SQLException
java.sql.SQLException
private void authentication(byte exchangeCharset, long clientCapabilities, byte[] seed, byte packetSeq, java.lang.String plugin) throws java.sql.SQLException, java.io.IOException
java.sql.SQLException
java.io.IOException
private long initializeClientCapabilities(long serverCapabilities)
private void loadCalendar() throws java.sql.SQLException
java.sql.SQLException
public java.lang.String getServerData(java.lang.String code)
public boolean checkIfMaster() throws java.sql.SQLException
checkIfMaster
in interface Protocol
java.sql.SQLException
- if requesting infos for server fail.private boolean isServerLanguageUtf8mb4(byte serverLanguage)
private byte decideLanguage(byte serverLanguage)
public void readEofPacket() throws java.sql.SQLException, java.io.IOException
readEofPacket
in interface Protocol
java.sql.SQLException
- if not a End-of-file packetjava.io.IOException
- if connection error occurpublic void skipEofPacket() throws java.sql.SQLException, java.io.IOException
skipEofPacket
in interface Protocol
java.sql.SQLException
- if not a End-of-file packetjava.io.IOException
- if connection error occurpublic void setHostFailedWithoutProxy()
setHostFailedWithoutProxy
in interface Protocol
public UrlParser getUrlParser()
getUrlParser
in interface Protocol
public boolean isMasterConnection()
isMasterConnection
in interface Protocol
public void sendPipelineCheckMaster() throws java.io.IOException
java.io.IOException
- in case of socket error.public void readPipelineCheckMaster() throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
public boolean mustBeMasterConnection()
mustBeMasterConnection
in interface Protocol
public boolean noBackslashEscapes()
noBackslashEscapes
in interface Protocol
public void connectWithoutProxy() throws java.sql.SQLException
connectWithoutProxy
in interface Protocol
java.sql.SQLException
- exceptionpublic boolean shouldReconnectWithoutProxy()
shouldReconnectWithoutProxy
in interface Protocol
public java.lang.String getServerVersion()
getServerVersion
in interface Protocol
public boolean getReadonly()
getReadonly
in interface Protocol
public void setReadonly(boolean readOnly)
setReadonly
in interface Protocol
public HostAddress getHostAddress()
getHostAddress
in interface Protocol
public void setHostAddress(HostAddress host)
setHostAddress
in interface Protocol
public FailoverProxy getProxy()
public void setProxy(FailoverProxy proxy)
public java.lang.String getDatabase()
getDatabase
in interface Protocol
public java.lang.String getUsername()
getUsername
in interface Protocol
public java.lang.String getPassword()
getPassword
in interface Protocol
private void parseVersion()
public int getMajorServerVersion()
getMajorServerVersion
in interface Protocol
public int getMinorServerVersion()
getMinorServerVersion
in interface Protocol
protected void enabledSslProtocolSuites(javax.net.ssl.SSLSocket sslSocket) throws java.sql.SQLException
sslSocket
- current sslSocketjava.sql.SQLException
- if protocol isn't a supported protocolprotected void enabledSslCipherSuites(javax.net.ssl.SSLSocket sslSocket) throws java.sql.SQLException
sslSocket
- current ssl socketjava.sql.SQLException
- if a cipher isn't knownpublic boolean versionGreaterOrEqual(int major, int minor, int patch)
versionGreaterOrEqual
in interface Protocol
major
- major versionminor
- minor versionpatch
- patch versionpublic boolean getPinGlobalTxToPhysicalConnection()
getPinGlobalTxToPhysicalConnection
in interface Protocol
public boolean hasWarnings()
hasWarnings
in interface Protocol
public boolean isConnected()
isConnected
in interface Protocol
private void setDataTypeMappingFlags()
public long getServerThreadId()
getServerThreadId
in interface Protocol
public int getDataTypeMappingFlags()
getDataTypeMappingFlags
in interface Protocol
public boolean isExplicitClosed()
isExplicitClosed
in interface Protocol
public java.util.TimeZone getTimeZone()
getTimeZone
in interface Protocol
public Options getOptions()
getOptions
in interface Protocol
public void setHasWarnings(boolean hasWarnings)
setHasWarnings
in interface Protocol
public Results getActiveStreamingResult()
getActiveStreamingResult
in interface Protocol
public void setActiveStreamingResult(Results activeStreamingResult)
setActiveStreamingResult
in interface Protocol
public void removeActiveStreamingResult()
removeActiveStreamingResult
in interface Protocol
public java.util.concurrent.locks.ReentrantLock getLock()
public boolean hasMoreResults()
hasMoreResults
in interface Protocol
public ServerPrepareStatementCache prepareStatementCache()
prepareStatementCache
in interface Protocol
public abstract void executeQuery(java.lang.String sql) throws java.sql.SQLException
executeQuery
in interface Protocol
java.sql.SQLException
public void changeSocketTcpNoDelay(boolean setTcpNoDelay)
changeSocketTcpNoDelay
in interface Protocol
setTcpNoDelay
- value to set.public void changeSocketSoTimeout(int setSoTimeout) throws java.net.SocketException
changeSocketSoTimeout
in interface Protocol
java.net.SocketException
public boolean isServerMariaDb()
isServerMariaDb
in interface Protocol
public PacketInputStream getReader()
public PacketOutputStream getWriter()
public boolean isEofDeprecated()
isEofDeprecated
in interface Protocol
public boolean sessionStateAware()
sessionStateAware
in interface Protocol