Class AbstractConnectProtocol
java.lang.Object
org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol
- All Implemented Interfaces:
Protocol
- Direct Known Subclasses:
AbstractQueryProtocol
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected booleanprivate HostAddressprotected Stringprotected booleanprotected booleanprivate final GlobalStateInfobooleanprivate booleanprivate static final byte[]protected final ReentrantLockprivate static final Loggerprivate intprivate intprotected final Optionsprivate final Stringprivate intprotected FailoverProxyprotected PacketInputStreamprotected booleanprotected longprivate booleanprotected ServerPrepareStatementCacheshortprotected longprivate Stringprivate static final byte[]protected Socketprotected intprivate TimeZoneprivate final LruTraceCacheprotected final UrlParserprivate final Stringprotected PacketOutputStream -
Constructor Summary
ConstructorsConstructorDescriptionAbstractConnectProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, ReentrantLock lock) Get a protocol instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Force closes socket and stream readers/writers.private voidprivate voidadditionalData(Map<String, String> serverData) private voidauthentication(byte exchangeCharset, long clientCapabilities, byte packetSeq, ReadInitialHandShakePacket greetingPacket) voidchangeSocketSoTimeout(int setSoTimeout) voidchangeSocketTcpNoDelay(boolean setTcpNoDelay) Change Socket TcpNoDelay option.booleanCheck that current connection is a master connection (not read-only).private voidvoidclose()Closes socket and stream readers/writers Attempts graceful shutdown.private static voidcloseSocket(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, Socket socket) voidconnect()Connect to currentHost.private voidConnect the client and perform handshake.voidConnect without proxy.private bytedecideLanguage(int serverLanguage) Default collation used for string exchanges with server.private voidenabledSslCipherSuites(SSLSocket sslSocket) Set ssl socket cipher according to options.private voidenabledSslProtocolSuites(SSLSocket sslSocket) Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1".private voidabstract voidexecuteQuery(String sql) private voidgetHost()getLock()intintbooleanintgetPort()getProxy()booleanlongGet a String containing readable information about last 10 send/received packets.private voidhandleConnectionPhases(String host) booleanbooleanHas warnings.private longinitializeClientCapabilities(long serverCapabilities) private voidInitializeSocketOption.booleanisClosed()Is the connection closed.booleanIs connected.booleanbooleanbooleanIndicate if current protocol is a master protocol.booleanprivate voidloadCalendar(String srvTimeZone, String srvSystemTimeZone) booleanbooleanprivate voidvoidCheck that next read packet is a End-of-file packet.private voidreadPipelineAdditionalData(Map<String, String> serverData) voidprivate voidreadRequestSessionVariables(Map<String, String> serverData) voidRemove exception result and since totally fetched, set fetch size to 0.voidRemove flag has more results.private voidrequestSessionDataWithShow(Map<String, String> serverData) private voidsendCreateDatabaseIfNotExist(String quotedDb) private voidSend all additional needed values.private voidSend query to identify if server is master.private voidprivate voidprivate voidsendUseDatabaseIfNotExist(String quotedDb) booleanvoidsetActiveStreamingResult(Results activeStreamingResult) voidsetHasWarnings(boolean hasWarnings) voidsetHostAddress(HostAddress host) voidvoidsetProxy(FailoverProxy proxy) voidsetReadonly(boolean readOnly) voidsetServerStatus(short serverStatus) booleanvoidskip()Skip packets not read that are not needed.voidCheck that next read packet is a End-of-file packet.booleanversionGreaterOrEqual(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, waitMethods 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:
skipin interfaceProtocol- Throws:
SQLException- exception
-
cleanMemory
private void cleanMemory() -
setServerStatus
public void setServerStatus(short serverStatus) - Specified by:
setServerStatusin interfaceProtocol
-
removeHasMoreResults
public void removeHasMoreResults()Remove flag has more results.- Specified by:
removeHasMoreResultsin interfaceProtocol
-
initializeSocketOption
private void initializeSocketOption()InitializeSocketOption. -
connect
Connect to currentHost.- Specified by:
connectin 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:
IOExceptionSQLException
-
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:
SQLExceptionIOException
-
initializeClientCapabilities
private long initializeClientCapabilities(long serverCapabilities) -
loadCalendar
- Throws:
SQLException
-
checkIfMaster
Check that current connection is a master connection (not read-only).- Specified by:
checkIfMasterin 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:
readEofPacketin 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:
skipEofPacketin interfaceProtocol- Throws:
SQLException- if not a End-of-file packetIOException- if connection error occur
-
setHostFailedWithoutProxy
public void setHostFailedWithoutProxy()- Specified by:
setHostFailedWithoutProxyin interfaceProtocol
-
getUrlParser
- Specified by:
getUrlParserin interfaceProtocol
-
isMasterConnection
public boolean isMasterConnection()Indicate if current protocol is a master protocol.- Specified by:
isMasterConnectionin 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:
mustBeMasterConnectionin interfaceProtocol
-
noBackslashEscapes
public boolean noBackslashEscapes()- Specified by:
noBackslashEscapesin interfaceProtocol
-
connectWithoutProxy
Connect without proxy. (use basic failover implementation)- Specified by:
connectWithoutProxyin interfaceProtocol- Throws:
SQLException- exception
-
shouldReconnectWithoutProxy
public boolean shouldReconnectWithoutProxy()- Specified by:
shouldReconnectWithoutProxyin interfaceProtocol
-
getServerVersion
- Specified by:
getServerVersionin interfaceProtocol
-
getReadonly
public boolean getReadonly()- Specified by:
getReadonlyin interfaceProtocol
-
setReadonly
public void setReadonly(boolean readOnly) - Specified by:
setReadonlyin interfaceProtocol
-
getHostAddress
- Specified by:
getHostAddressin interfaceProtocol
-
setHostAddress
- Specified by:
setHostAddressin interfaceProtocol
-
getHost
-
getProxy
-
setProxy
-
getPort
public int getPort() -
getDatabase
- Specified by:
getDatabasein interfaceProtocol
-
getUsername
- Specified by:
getUsernamein interfaceProtocol
-
parseVersion
private void parseVersion() -
getMajorServerVersion
public int getMajorServerVersion()- Specified by:
getMajorServerVersionin interfaceProtocol
-
getMinorServerVersion
public int getMinorServerVersion()- Specified by:
getMinorServerVersionin 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:
versionGreaterOrEqualin interfaceProtocol- Parameters:
major- major versionminor- minor versionpatch- patch version- Returns:
- true if version is greater than parameters
-
getPinGlobalTxToPhysicalConnection
public boolean getPinGlobalTxToPhysicalConnection()- Specified by:
getPinGlobalTxToPhysicalConnectionin interfaceProtocol
-
hasWarnings
public boolean hasWarnings()Has warnings.- Specified by:
hasWarningsin interfaceProtocol- Returns:
- true if as warnings.
-
isConnected
public boolean isConnected()Is connected.- Specified by:
isConnectedin interfaceProtocol- Returns:
- true if connected
-
getServerThreadId
public long getServerThreadId()- Specified by:
getServerThreadIdin interfaceProtocol
-
getSocket
-
isExplicitClosed
public boolean isExplicitClosed()- Specified by:
isExplicitClosedin interfaceProtocol
-
getTimeZone
- Specified by:
getTimeZonein interfaceProtocol
-
getOptions
- Specified by:
getOptionsin interfaceProtocol
-
setHasWarnings
public void setHasWarnings(boolean hasWarnings) - Specified by:
setHasWarningsin interfaceProtocol
-
getActiveStreamingResult
- Specified by:
getActiveStreamingResultin interfaceProtocol
-
setActiveStreamingResult
- Specified by:
setActiveStreamingResultin interfaceProtocol
-
removeActiveStreamingResult
public void removeActiveStreamingResult()Remove exception result and since totally fetched, set fetch size to 0.- Specified by:
removeActiveStreamingResultin interfaceProtocol
-
getLock
-
hasMoreResults
public boolean hasMoreResults()- Specified by:
hasMoreResultsin interfaceProtocol
-
prepareStatementCache
- Specified by:
prepareStatementCachein interfaceProtocol
-
executeQuery
- Specified by:
executeQueryin interfaceProtocol- Throws:
SQLException
-
changeSocketTcpNoDelay
public void changeSocketTcpNoDelay(boolean setTcpNoDelay) Change Socket TcpNoDelay option.- Specified by:
changeSocketTcpNoDelayin interfaceProtocol- Parameters:
setTcpNoDelay- value to set.
-
changeSocketSoTimeout
- Specified by:
changeSocketSoTimeoutin interfaceProtocol- Throws:
SocketException
-
isServerMariaDb
public boolean isServerMariaDb()- Specified by:
isServerMariaDbin interfaceProtocol
-
getReader
-
getWriter
-
isEofDeprecated
public boolean isEofDeprecated()- Specified by:
isEofDeprecatedin interfaceProtocol
-
sessionStateAware
public boolean sessionStateAware()- Specified by:
sessionStateAwarein interfaceProtocol
-
getTraces
Get a String containing readable information about last 10 send/received packets.
-