public abstract class AbstractConnectProtocol extends java.lang.Object implements Protocol
Modifier and Type | Field and Description |
---|---|
Results |
activeStreamingResult |
protected int |
autoIncrementIncrement |
protected boolean |
connected |
private HostAddress |
currentHost |
protected java.lang.String |
database |
protected boolean |
eofDeprecated |
protected boolean |
explicitClosed |
private GlobalStateInfo |
globalInfo |
boolean |
hasWarnings |
private boolean |
hostFailed |
private 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 boolean |
serverMariaDb |
protected ServerPrepareStatementCache |
serverPrepareStatementCache |
short |
serverStatus |
protected long |
serverThreadId |
private java.lang.String |
serverVersion |
private 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,
GlobalStateInfo globalInfo,
java.util.concurrent.locks.ReentrantLock lock)
Get a protocol instance.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Force closes socket and stream readers/writers.
|
private void |
abortActiveStream() |
private void |
additionalData(java.util.Map<java.lang.String,java.lang.String> serverData) |
private void |
authentication(byte exchangeCharset,
long clientCapabilities,
byte packetSeq,
ReadInitialHandShakePacket greetingPacket) |
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).
|
private void |
cleanMemory() |
void |
close()
Closes socket and stream readers/writers Attempts graceful shutdown.
|
private static void |
closeSocket(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(int serverLanguage)
Default collation used for string exchanges with server.
|
private void |
enabledSslCipherSuites(javax.net.ssl.SSLSocket sslSocket)
Set ssl socket cipher according to options.
|
private 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) |
private void |
forceAbort() |
Results |
getActiveStreamingResult() |
java.lang.String |
getDatabase() |
java.lang.String |
getHost() |
HostAddress |
getHostAddress() |
java.util.concurrent.locks.ReentrantLock |
getLock() |
int |
getMajorServerVersion() |
int |
getMinorServerVersion() |
Options |
getOptions() |
boolean |
getPinGlobalTxToPhysicalConnection() |
int |
getPort() |
FailoverProxy |
getProxy() |
PacketInputStream |
getReader() |
boolean |
getReadonly() |
long |
getServerThreadId() |
java.lang.String |
getServerVersion() |
java.net.Socket |
getSocket() |
java.util.TimeZone |
getTimeZone() |
java.lang.String |
getTraces()
Get a String containing readable information about last 10 send/received packets.
|
UrlParser |
getUrlParser() |
java.lang.String |
getUsername() |
PacketOutputStream |
getWriter() |
private void |
handleConnectionPhases(java.lang.String host) |
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.
|
boolean |
isServerMariaDb() |
private void |
loadCalendar(java.lang.String srvTimeZone,
java.lang.String srvSystemTimeZone) |
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(java.util.Map<java.lang.String,java.lang.String> serverData) |
void |
readPipelineCheckMaster() |
private void |
readRequestSessionVariables(java.util.Map<java.lang.String,java.lang.String> serverData) |
void |
removeActiveStreamingResult()
Remove exception result and since totally fetched, set fetch size to 0.
|
void |
removeHasMoreResults()
Remove flag has more results.
|
private void |
requestSessionDataWithShow(java.util.Map<java.lang.String,java.lang.String> serverData) |
private void |
sendCreateDatabaseIfNotExist(java.lang.String quotedDb) |
private void |
sendPipelineAdditionalData()
Send all additional needed values.
|
private 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) |
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, executeBatchClient, executeBatchServer, executeBatchStmt, executePreparedQuery, executeQuery, executeQuery, executeQuery, executeQuery, forceReleasePrepareStatement, forceReleaseWaitingPrepareStatement, getAutocommit, getAutoIncrementIncrement, getCatalog, getMaxRows, getResult, getTimeout, getTransactionIsolationLevel, handleIoException, interrupt, inTransaction, isInterrupted, isValid, ping, prepare, prolog, prologProxy, releasePrepareStatement, reset, resetDatabase, resetStateAfterFailover, rollback, setActiveFutureTask, setCatalog, setLocalInfileInputStream, setMaxRows, setTimeout, setTransactionIsolation, stopIfInterrupted
private static final byte[] SESSION_QUERY
private static final byte[] IS_MASTER_QUERY
private static final 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
private final LruTraceCache traceCache
private final GlobalStateInfo globalInfo
public boolean hasWarnings
public Results activeStreamingResult
public short serverStatus
protected int autoIncrementIncrement
protected java.net.Socket socket
protected PacketOutputStream writer
protected boolean readOnly
protected PacketInputStream reader
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 HostAddress currentHost
private boolean hostFailed
private java.lang.String serverVersion
private boolean serverMariaDb
private int majorVersion
private int minorVersion
private int patchVersion
private java.util.TimeZone timeZone
public AbstractConnectProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, java.util.concurrent.locks.ReentrantLock lock)
urlParser
- connection URL informationglobalInfo
- server global variables informationlock
- the lock for thread synchronisationprivate static void closeSocket(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, java.net.Socket socket)
public void close()
public void abort()
private void forceAbort()
private void abortActiveStream()
public void skip() throws java.sql.SQLException
private void cleanMemory()
public void setServerStatus(short serverStatus)
setServerStatus
in interface Protocol
public void removeHasMoreResults()
removeHasMoreResults
in interface Protocol
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.io.IOException
- if socket exception occurprivate void sendSessionInfos() throws java.io.IOException
java.io.IOException
private void sendRequestSessionVariables() throws java.io.IOException
java.io.IOException
private void readRequestSessionVariables(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.sql.SQLException
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(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.sql.SQLException
java.sql.SQLException
private void requestSessionDataWithShow(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.sql.SQLException
java.sql.SQLException
private void additionalData(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
private void ensureClosingSocketOnException()
public boolean isClosed()
private void handleConnectionPhases(java.lang.String host) throws java.sql.SQLException
java.sql.SQLException
private void authentication(byte exchangeCharset, long clientCapabilities, byte packetSeq, ReadInitialHandShakePacket greetingPacket) throws java.sql.SQLException, java.io.IOException
java.sql.SQLException
java.io.IOException
private long initializeClientCapabilities(long serverCapabilities)
private void loadCalendar(java.lang.String srvTimeZone, java.lang.String srvSystemTimeZone) throws java.sql.SQLException
java.sql.SQLException
public boolean checkIfMaster() throws java.sql.SQLException
checkIfMaster
in interface Protocol
java.sql.SQLException
- if requesting infos for server fail.private byte decideLanguage(int serverLanguage)
serverLanguage
- server default collationpublic 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
private void sendPipelineCheckMaster() throws java.io.IOException
java.io.IOException
- in case of socket error.public void readPipelineCheckMaster() throws java.sql.SQLException
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
private void parseVersion()
public int getMajorServerVersion()
getMajorServerVersion
in interface Protocol
public int getMinorServerVersion()
getMinorServerVersion
in interface Protocol
private void enabledSslProtocolSuites(javax.net.ssl.SSLSocket sslSocket) throws java.sql.SQLException
sslSocket
- current sslSocketjava.sql.SQLException
- if protocol isn't a supported protocolprivate 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
public long getServerThreadId()
getServerThreadId
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