Class AbstractConnectProtocol
java.lang.Object
org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol
- All Implemented Interfaces:
Protocol
- Direct Known Subclasses:
AbstractQueryProtocol
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected boolean
private HostAddress
protected String
protected boolean
protected boolean
private final GlobalStateInfo
boolean
private boolean
private static final byte[]
protected final ReentrantLock
private static final Logger
private int
private int
protected final Options
private final String
private int
protected FailoverProxy
protected PacketInputStream
protected boolean
protected long
private boolean
protected ServerPrepareStatementCache
short
protected long
private String
private static final byte[]
protected Socket
protected int
private TimeZone
private final LruTraceCache
protected final UrlParser
private final String
protected PacketOutputStream
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractConnectProtocol
(UrlParser urlParser, GlobalStateInfo globalInfo, ReentrantLock lock) Get a protocol instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Force closes socket and stream readers/writers.private void
private void
additionalData
(Map<String, 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
Check that current connection is a master connection (not read-only).private void
void
close()
Closes socket and stream readers/writers Attempts graceful shutdown.private static void
closeSocket
(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, Socket socket) void
connect()
Connect to currentHost.private void
Connect the client and perform handshake.void
Connect without proxy.private byte
decideLanguage
(int serverLanguage) Default collation used for string exchanges with server.private void
enabledSslCipherSuites
(SSLSocket sslSocket) Set ssl socket cipher according to options.private void
enabledSslProtocolSuites
(SSLSocket sslSocket) Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1".private void
abstract void
executeQuery
(String sql) private void
getHost()
getLock()
int
int
boolean
int
getPort()
getProxy()
boolean
long
Get a String containing readable information about last 10 send/received packets.private void
handleConnectionPhases
(String host) boolean
boolean
Has warnings.private long
initializeClientCapabilities
(long serverCapabilities) private void
InitializeSocketOption.boolean
isClosed()
Is the connection closed.boolean
Is connected.boolean
boolean
boolean
Indicate if current protocol is a master protocol.boolean
private void
loadCalendar
(String srvTimeZone, String srvSystemTimeZone) boolean
boolean
private void
void
Check that next read packet is a End-of-file packet.private void
readPipelineAdditionalData
(Map<String, String> serverData) void
private void
readRequestSessionVariables
(Map<String, String> serverData) void
Remove exception result and since totally fetched, set fetch size to 0.void
Remove flag has more results.private void
requestSessionDataWithShow
(Map<String, String> serverData) private void
sendCreateDatabaseIfNotExist
(String quotedDb) private void
Send all additional needed values.private void
Send query to identify if server is master.private void
private void
private void
sendUseDatabaseIfNotExist
(String quotedDb) boolean
void
setActiveStreamingResult
(Results activeStreamingResult) void
setHasWarnings
(boolean hasWarnings) void
setHostAddress
(HostAddress host) void
void
setProxy
(FailoverProxy proxy) void
setReadonly
(boolean readOnly) void
setServerStatus
(short serverStatus) boolean
void
skip()
Skip packets not read that are not needed.void
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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.mariadb.jdbc.internal.protocol.Protocol
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
-
Field Details
-
SESSION_QUERY
private static final byte[] SESSION_QUERY -
IS_MASTER_QUERY
private static final byte[] IS_MASTER_QUERY -
logger
-
lock
-
urlParser
-
options
-
username
-
password
-
traceCache
-
globalInfo
-
hasWarnings
public boolean hasWarnings -
activeStreamingResult
-
serverStatus
public short serverStatus -
autoIncrementIncrement
protected int autoIncrementIncrement -
socket
-
writer
-
readOnly
protected boolean readOnly -
reader
-
proxy
-
connected
protected volatile boolean connected -
explicitClosed
protected boolean explicitClosed -
database
-
serverThreadId
protected long serverThreadId -
serverPrepareStatementCache
-
eofDeprecated
protected boolean eofDeprecated -
serverCapabilities
protected long serverCapabilities -
currentHost
-
hostFailed
private boolean hostFailed -
serverVersion
-
serverMariaDb
private boolean serverMariaDb -
majorVersion
private int majorVersion -
minorVersion
private int minorVersion -
patchVersion
private int patchVersion -
timeZone
-
socketTimeout
protected int socketTimeout
-
-
Constructor Details
-
AbstractConnectProtocol
Get a protocol instance.- Parameters:
urlParser
- connection URL informationglobalInfo
- server global variables informationlock
- the lock for thread synchronisation
-
-
Method Details
-
closeSocket
private static void closeSocket(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, Socket socket) -
close
public void close()Closes socket and stream readers/writers Attempts graceful shutdown. -
abort
public void abort()Force closes socket and stream readers/writers. -
forceAbort
private void forceAbort() -
abortActiveStream
private void abortActiveStream() -
skip
Skip packets not read that are not needed. Packets are read according to needs. If some data have not been read before next execution, skip it. Lock must be set before using this method- Specified by:
skip
in interfaceProtocol
- Throws:
SQLException
- exception
-
cleanMemory
private void cleanMemory() -
setServerStatus
public void setServerStatus(short serverStatus) - Specified by:
setServerStatus
in interfaceProtocol
-
removeHasMoreResults
public void removeHasMoreResults()Remove flag has more results.- Specified by:
removeHasMoreResults
in interfaceProtocol
-
initializeSocketOption
private void initializeSocketOption()InitializeSocketOption. -
connect
Connect to currentHost.- Specified by:
connect
in interfaceProtocol
- Throws:
SQLException
- exception
-
connect
Connect the client and perform handshake.- Parameters:
host
- hostport
- port- Throws:
SQLException
- handshake error, e.g wrong user or passwordIOException
- connection error (host/port not available)
-
sendPipelineAdditionalData
Send all additional needed values. Command are send one after the other, assuming that command are less than 65k (minimum hosts TCP/IP buffer size)- Throws:
IOException
- if socket exception occur
-
sendSessionInfos
- Throws:
IOException
-
sendRequestSessionVariables
- Throws:
IOException
-
readRequestSessionVariables
- Throws:
SQLException
-
sendCreateDatabaseIfNotExist
- Throws:
IOException
-
sendUseDatabaseIfNotExist
- Throws:
IOException
-
readPipelineAdditionalData
- Throws:
SQLException
-
requestSessionDataWithShow
- Throws:
SQLException
-
additionalData
- Throws:
IOException
SQLException
-
ensureClosingSocketOnException
private void ensureClosingSocketOnException() -
isClosed
public boolean isClosed()Is the connection closed. -
handleConnectionPhases
- Throws:
SQLException
-
authentication
private void authentication(byte exchangeCharset, long clientCapabilities, byte packetSeq, ReadInitialHandShakePacket greetingPacket) throws SQLException, IOException - Throws:
SQLException
IOException
-
initializeClientCapabilities
private long initializeClientCapabilities(long serverCapabilities) -
loadCalendar
- Throws:
SQLException
-
checkIfMaster
Check that current connection is a master connection (not read-only).- Specified by:
checkIfMaster
in interfaceProtocol
- Returns:
- true if master
- Throws:
SQLException
- if requesting infos for server fail.
-
decideLanguage
private byte decideLanguage(int serverLanguage) Default collation used for string exchanges with server.- Parameters:
serverLanguage
- server default collation- Returns:
- collation byte
-
readEofPacket
Check that next read packet is a End-of-file packet.- Specified by:
readEofPacket
in interfaceProtocol
- Throws:
SQLException
- if not a End-of-file packetIOException
- if connection error occur
-
skipEofPacket
Check that next read packet is a End-of-file packet.- Specified by:
skipEofPacket
in interfaceProtocol
- Throws:
SQLException
- if not a End-of-file packetIOException
- if connection error occur
-
setHostFailedWithoutProxy
public void setHostFailedWithoutProxy()- Specified by:
setHostFailedWithoutProxy
in interfaceProtocol
-
getUrlParser
- Specified by:
getUrlParser
in interfaceProtocol
-
isMasterConnection
public boolean isMasterConnection()Indicate if current protocol is a master protocol.- Specified by:
isMasterConnection
in interfaceProtocol
- Returns:
- is master flag
-
sendPipelineCheckMaster
Send query to identify if server is master.- Throws:
IOException
- in case of socket error.
-
readPipelineCheckMaster
- Throws:
SQLException
-
mustBeMasterConnection
public boolean mustBeMasterConnection()- Specified by:
mustBeMasterConnection
in interfaceProtocol
-
noBackslashEscapes
public boolean noBackslashEscapes()- Specified by:
noBackslashEscapes
in interfaceProtocol
-
connectWithoutProxy
Connect without proxy. (use basic failover implementation)- Specified by:
connectWithoutProxy
in interfaceProtocol
- Throws:
SQLException
- exception
-
shouldReconnectWithoutProxy
public boolean shouldReconnectWithoutProxy()- Specified by:
shouldReconnectWithoutProxy
in interfaceProtocol
-
getServerVersion
- Specified by:
getServerVersion
in interfaceProtocol
-
getReadonly
public boolean getReadonly()- Specified by:
getReadonly
in interfaceProtocol
-
setReadonly
public void setReadonly(boolean readOnly) - Specified by:
setReadonly
in interfaceProtocol
-
getHostAddress
- Specified by:
getHostAddress
in interfaceProtocol
-
setHostAddress
- Specified by:
setHostAddress
in interfaceProtocol
-
getHost
-
getProxy
-
setProxy
-
getPort
public int getPort() -
getDatabase
- Specified by:
getDatabase
in interfaceProtocol
-
getUsername
- Specified by:
getUsername
in interfaceProtocol
-
parseVersion
private void parseVersion() -
getMajorServerVersion
public int getMajorServerVersion()- Specified by:
getMajorServerVersion
in interfaceProtocol
-
getMinorServerVersion
public int getMinorServerVersion()- Specified by:
getMinorServerVersion
in interfaceProtocol
-
enabledSslProtocolSuites
Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1". MariaDB versions ≥ 10.0.15 and ≥ 5.5.41 supports TLSv1.2 if compiled with openSSL (default). MySQL community versions ≥ 5.7.10 is compile with yaSSL, so max TLS is TLSv1.1.- Parameters:
sslSocket
- current sslSocket- Throws:
SQLException
- if protocol isn't a supported protocol
-
enabledSslCipherSuites
Set ssl socket cipher according to options.- Parameters:
sslSocket
- current ssl socket- Throws:
SQLException
- if a cipher isn't known
-
versionGreaterOrEqual
public boolean versionGreaterOrEqual(int major, int minor, int patch) Utility method to check if database version is greater than parameters.- Specified by:
versionGreaterOrEqual
in interfaceProtocol
- Parameters:
major
- major versionminor
- minor versionpatch
- patch version- Returns:
- true if version is greater than parameters
-
getPinGlobalTxToPhysicalConnection
public boolean getPinGlobalTxToPhysicalConnection()- Specified by:
getPinGlobalTxToPhysicalConnection
in interfaceProtocol
-
hasWarnings
public boolean hasWarnings()Has warnings.- Specified by:
hasWarnings
in interfaceProtocol
- Returns:
- true if as warnings.
-
isConnected
public boolean isConnected()Is connected.- Specified by:
isConnected
in interfaceProtocol
- Returns:
- true if connected
-
getServerThreadId
public long getServerThreadId()- Specified by:
getServerThreadId
in interfaceProtocol
-
getSocket
-
isExplicitClosed
public boolean isExplicitClosed()- Specified by:
isExplicitClosed
in interfaceProtocol
-
getTimeZone
- Specified by:
getTimeZone
in interfaceProtocol
-
getOptions
- Specified by:
getOptions
in interfaceProtocol
-
setHasWarnings
public void setHasWarnings(boolean hasWarnings) - Specified by:
setHasWarnings
in interfaceProtocol
-
getActiveStreamingResult
- Specified by:
getActiveStreamingResult
in interfaceProtocol
-
setActiveStreamingResult
- Specified by:
setActiveStreamingResult
in interfaceProtocol
-
removeActiveStreamingResult
public void removeActiveStreamingResult()Remove exception result and since totally fetched, set fetch size to 0.- Specified by:
removeActiveStreamingResult
in interfaceProtocol
-
getLock
-
hasMoreResults
public boolean hasMoreResults()- Specified by:
hasMoreResults
in interfaceProtocol
-
prepareStatementCache
- Specified by:
prepareStatementCache
in interfaceProtocol
-
executeQuery
- Specified by:
executeQuery
in interfaceProtocol
- Throws:
SQLException
-
changeSocketTcpNoDelay
public void changeSocketTcpNoDelay(boolean setTcpNoDelay) Change Socket TcpNoDelay option.- Specified by:
changeSocketTcpNoDelay
in interfaceProtocol
- Parameters:
setTcpNoDelay
- value to set.
-
changeSocketSoTimeout
- Specified by:
changeSocketSoTimeout
in interfaceProtocol
- Throws:
SocketException
-
isServerMariaDb
public boolean isServerMariaDb()- Specified by:
isServerMariaDb
in interfaceProtocol
-
getReader
-
getWriter
-
isEofDeprecated
public boolean isEofDeprecated()- Specified by:
isEofDeprecated
in interfaceProtocol
-
sessionStateAware
public boolean sessionStateAware()- Specified by:
sessionStateAware
in interfaceProtocol
-
getTraces
Get a String containing readable information about last 10 send/received packets.
-