Class AbstractConnectProtocol
- java.lang.Object
-
- org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol
-
- All Implemented Interfaces:
Protocol
- Direct Known Subclasses:
AbstractQueryProtocol
public abstract class AbstractConnectProtocol extends java.lang.Object implements Protocol
-
-
Field Summary
Fields Modifier and Type Field Description ResultsactiveStreamingResultprotected intautoIncrementIncrementprotected booleanconnectedprivate HostAddresscurrentHostprotected java.lang.Stringdatabaseprotected booleaneofDeprecatedprotected booleanexplicitClosedprivate GlobalStateInfoglobalInfobooleanhasWarningsprivate booleanhostFailedprivate static byte[]IS_MASTER_QUERYprotected java.util.concurrent.locks.ReentrantLocklockprivate static Loggerloggerprivate intmajorVersionprivate intminorVersionprotected Optionsoptionsprivate java.lang.Stringpasswordprivate intpatchVersionprotected FailoverProxyproxyprotected PacketInputStreamreaderprotected booleanreadOnlyprotected longserverCapabilitiesprivate booleanserverMariaDbprotected ServerPrepareStatementCacheserverPrepareStatementCacheshortserverStatusprotected longserverThreadIdprivate java.lang.StringserverVersionprivate static byte[]SESSION_QUERYprotected java.net.Socketsocketprotected intsocketTimeoutprivate java.util.TimeZonetimeZoneprivate LruTraceCachetraceCacheprotected UrlParserurlParserprivate java.lang.Stringusernameprotected PacketOutputStreamwriter
-
Constructor Summary
Constructors Constructor Description AbstractConnectProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, java.util.concurrent.locks.ReentrantLock lock)Get a protocol instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidabort()Force closes socket and stream readers/writers.private voidabortActiveStream()private voidadditionalData(java.util.Map<java.lang.String,java.lang.String> serverData)private voidauthentication(byte exchangeCharset, long clientCapabilities, byte packetSeq, ReadInitialHandShakePacket greetingPacket)voidchangeSocketSoTimeout(int setSoTimeout)voidchangeSocketTcpNoDelay(boolean setTcpNoDelay)Change Socket TcpNoDelay option.booleancheckIfMaster()Check that current connection is a master connection (not read-only).private voidcleanMemory()voidclose()Closes socket and stream readers/writers Attempts graceful shutdown.private static voidcloseSocket(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, java.net.Socket socket)voidconnect()Connect to currentHost.private voidconnect(java.lang.String host, int port)Connect the client and perform handshake.voidconnectWithoutProxy()Connect without proxy.private bytedecideLanguage(int serverLanguage)Default collation used for string exchanges with server.private voidenabledSslCipherSuites(javax.net.ssl.SSLSocket sslSocket)Set ssl socket cipher according to options.private voidenabledSslProtocolSuites(javax.net.ssl.SSLSocket sslSocket)Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1".private voidensureClosingSocketOnException()abstract voidexecuteQuery(java.lang.String sql)private voidforceAbort()ResultsgetActiveStreamingResult()java.lang.StringgetDatabase()java.lang.StringgetHost()HostAddressgetHostAddress()java.util.concurrent.locks.ReentrantLockgetLock()intgetMajorServerVersion()intgetMinorServerVersion()OptionsgetOptions()booleangetPinGlobalTxToPhysicalConnection()intgetPort()FailoverProxygetProxy()PacketInputStreamgetReader()booleangetReadonly()longgetServerThreadId()java.lang.StringgetServerVersion()java.net.SocketgetSocket()java.util.TimeZonegetTimeZone()java.lang.StringgetTraces()Get a String containing readable information about last 10 send/received packets.UrlParsergetUrlParser()java.lang.StringgetUsername()PacketOutputStreamgetWriter()private voidhandleConnectionPhases(java.lang.String host)booleanhasMoreResults()booleanhasWarnings()Has warnings.private longinitializeClientCapabilities(long serverCapabilities)private voidinitializeSocketOption()InitializeSocketOption.booleanisClosed()Is the connection closed.booleanisConnected()Is connected.booleanisEofDeprecated()booleanisExplicitClosed()booleanisMasterConnection()Indicate if current protocol is a master protocol.booleanisServerMariaDb()private voidloadCalendar(java.lang.String srvTimeZone, java.lang.String srvSystemTimeZone)booleanmustBeMasterConnection()booleannoBackslashEscapes()private voidparseVersion()ServerPrepareStatementCacheprepareStatementCache()voidreadEofPacket()Check that next read packet is a End-of-file packet.private voidreadPipelineAdditionalData(java.util.Map<java.lang.String,java.lang.String> serverData)voidreadPipelineCheckMaster()private voidreadRequestSessionVariables(java.util.Map<java.lang.String,java.lang.String> serverData)voidremoveActiveStreamingResult()Remove exception result and since totally fetched, set fetch size to 0.voidremoveHasMoreResults()Remove flag has more results.private voidrequestSessionDataWithShow(java.util.Map<java.lang.String,java.lang.String> serverData)private voidsendCreateDatabaseIfNotExist(java.lang.String quotedDb)private voidsendPipelineAdditionalData()Send all additional needed values.private voidsendPipelineCheckMaster()Send query to identify if server is master.private voidsendRequestSessionVariables()private voidsendSessionInfos()private voidsendUseDatabaseIfNotExist(java.lang.String quotedDb)booleansessionStateAware()voidsetActiveStreamingResult(Results activeStreamingResult)voidsetHasWarnings(boolean hasWarnings)voidsetHostAddress(HostAddress host)voidsetHostFailedWithoutProxy()voidsetProxy(FailoverProxy proxy)voidsetReadonly(boolean readOnly)voidsetServerStatus(short serverStatus)booleanshouldReconnectWithoutProxy()voidskip()Skip packets not read that are not needed.voidskipEofPacket()Check 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, 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 Detail
-
SESSION_QUERY
private static final byte[] SESSION_QUERY
-
IS_MASTER_QUERY
private static final byte[] IS_MASTER_QUERY
-
logger
private static final Logger logger
-
lock
protected final java.util.concurrent.locks.ReentrantLock lock
-
urlParser
protected final UrlParser urlParser
-
options
protected final Options options
-
username
private final java.lang.String username
-
password
private final java.lang.String password
-
traceCache
private final LruTraceCache traceCache
-
globalInfo
private final GlobalStateInfo globalInfo
-
hasWarnings
public boolean hasWarnings
-
activeStreamingResult
public Results activeStreamingResult
-
serverStatus
public short serverStatus
-
autoIncrementIncrement
protected int autoIncrementIncrement
-
socket
protected java.net.Socket socket
-
writer
protected PacketOutputStream writer
-
readOnly
protected boolean readOnly
-
reader
protected PacketInputStream reader
-
proxy
protected FailoverProxy proxy
-
connected
protected volatile boolean connected
-
explicitClosed
protected boolean explicitClosed
-
database
protected java.lang.String database
-
serverThreadId
protected long serverThreadId
-
serverPrepareStatementCache
protected ServerPrepareStatementCache serverPrepareStatementCache
-
eofDeprecated
protected boolean eofDeprecated
-
serverCapabilities
protected long serverCapabilities
-
currentHost
private HostAddress currentHost
-
hostFailed
private boolean hostFailed
-
serverVersion
private java.lang.String serverVersion
-
serverMariaDb
private boolean serverMariaDb
-
majorVersion
private int majorVersion
-
minorVersion
private int minorVersion
-
patchVersion
private int patchVersion
-
timeZone
private java.util.TimeZone timeZone
-
socketTimeout
protected int socketTimeout
-
-
Constructor Detail
-
AbstractConnectProtocol
public AbstractConnectProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, java.util.concurrent.locks.ReentrantLock lock)
Get a protocol instance.- Parameters:
urlParser- connection URL informationglobalInfo- server global variables informationlock- the lock for thread synchronisation
-
-
Method Detail
-
closeSocket
private static void closeSocket(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, java.net.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
public void skip() throws java.sql.SQLExceptionSkip 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
-
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
public void connect() throws java.sql.SQLExceptionConnect to currentHost.
-
connect
private void connect(java.lang.String host, int port) throws java.sql.SQLException, java.io.IOExceptionConnect the client and perform handshake.- Parameters:
host- hostport- port- Throws:
java.sql.SQLException- handshake error, e.g wrong user or passwordjava.io.IOException- connection error (host/port not available)
-
sendPipelineAdditionalData
private void sendPipelineAdditionalData() throws java.io.IOExceptionSend 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:
java.io.IOException- if socket exception occur
-
sendSessionInfos
private void sendSessionInfos() throws java.io.IOException- Throws:
java.io.IOException
-
sendRequestSessionVariables
private void sendRequestSessionVariables() throws java.io.IOException- Throws:
java.io.IOException
-
readRequestSessionVariables
private void readRequestSessionVariables(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
sendCreateDatabaseIfNotExist
private void sendCreateDatabaseIfNotExist(java.lang.String quotedDb) throws java.io.IOException- Throws:
java.io.IOException
-
sendUseDatabaseIfNotExist
private void sendUseDatabaseIfNotExist(java.lang.String quotedDb) throws java.io.IOException- Throws:
java.io.IOException
-
readPipelineAdditionalData
private void readPipelineAdditionalData(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
requestSessionDataWithShow
private void requestSessionDataWithShow(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
additionalData
private void additionalData(java.util.Map<java.lang.String,java.lang.String> serverData) throws java.io.IOException, java.sql.SQLException- Throws:
java.io.IOExceptionjava.sql.SQLException
-
ensureClosingSocketOnException
private void ensureClosingSocketOnException()
-
isClosed
public boolean isClosed()
Is the connection closed.
-
handleConnectionPhases
private void handleConnectionPhases(java.lang.String host) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
authentication
private void authentication(byte exchangeCharset, long clientCapabilities, byte packetSeq, ReadInitialHandShakePacket greetingPacket) throws java.sql.SQLException, java.io.IOException- Throws:
java.sql.SQLExceptionjava.io.IOException
-
initializeClientCapabilities
private long initializeClientCapabilities(long serverCapabilities)
-
loadCalendar
private void loadCalendar(java.lang.String srvTimeZone, java.lang.String srvSystemTimeZone) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
checkIfMaster
public boolean checkIfMaster() throws java.sql.SQLExceptionCheck that current connection is a master connection (not read-only).- Specified by:
checkIfMasterin interfaceProtocol- Returns:
- true if master
- Throws:
java.sql.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
public void readEofPacket() throws java.sql.SQLException, java.io.IOExceptionCheck that next read packet is a End-of-file packet.- Specified by:
readEofPacketin interfaceProtocol- Throws:
java.sql.SQLException- if not a End-of-file packetjava.io.IOException- if connection error occur
-
skipEofPacket
public void skipEofPacket() throws java.sql.SQLException, java.io.IOExceptionCheck that next read packet is a End-of-file packet.- Specified by:
skipEofPacketin interfaceProtocol- Throws:
java.sql.SQLException- if not a End-of-file packetjava.io.IOException- if connection error occur
-
setHostFailedWithoutProxy
public void setHostFailedWithoutProxy()
- Specified by:
setHostFailedWithoutProxyin interfaceProtocol
-
getUrlParser
public UrlParser 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
private void sendPipelineCheckMaster() throws java.io.IOExceptionSend query to identify if server is master.- Throws:
java.io.IOException- in case of socket error.
-
readPipelineCheckMaster
public void readPipelineCheckMaster() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
mustBeMasterConnection
public boolean mustBeMasterConnection()
- Specified by:
mustBeMasterConnectionin interfaceProtocol
-
noBackslashEscapes
public boolean noBackslashEscapes()
- Specified by:
noBackslashEscapesin interfaceProtocol
-
connectWithoutProxy
public void connectWithoutProxy() throws java.sql.SQLExceptionConnect without proxy. (use basic failover implementation)- Specified by:
connectWithoutProxyin interfaceProtocol- Throws:
java.sql.SQLException- exception
-
shouldReconnectWithoutProxy
public boolean shouldReconnectWithoutProxy()
- Specified by:
shouldReconnectWithoutProxyin interfaceProtocol
-
getServerVersion
public java.lang.String getServerVersion()
- Specified by:
getServerVersionin interfaceProtocol
-
getReadonly
public boolean getReadonly()
- Specified by:
getReadonlyin interfaceProtocol
-
setReadonly
public void setReadonly(boolean readOnly)
- Specified by:
setReadonlyin interfaceProtocol
-
getHostAddress
public HostAddress getHostAddress()
- Specified by:
getHostAddressin interfaceProtocol
-
setHostAddress
public void setHostAddress(HostAddress host)
- Specified by:
setHostAddressin interfaceProtocol
-
getProxy
public FailoverProxy getProxy()
-
setProxy
public void setProxy(FailoverProxy proxy)
-
getDatabase
public java.lang.String getDatabase()
- Specified by:
getDatabasein interfaceProtocol
-
getUsername
public java.lang.String 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
private void enabledSslProtocolSuites(javax.net.ssl.SSLSocket sslSocket) throws java.sql.SQLExceptionReturn 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:
java.sql.SQLException- if protocol isn't a supported protocol
-
enabledSslCipherSuites
private void enabledSslCipherSuites(javax.net.ssl.SSLSocket sslSocket) throws java.sql.SQLExceptionSet ssl socket cipher according to options.- Parameters:
sslSocket- current ssl socket- Throws:
java.sql.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
-
isExplicitClosed
public boolean isExplicitClosed()
- Specified by:
isExplicitClosedin interfaceProtocol
-
getTimeZone
public java.util.TimeZone getTimeZone()
- Specified by:
getTimeZonein interfaceProtocol
-
getOptions
public Options getOptions()
- Specified by:
getOptionsin interfaceProtocol
-
setHasWarnings
public void setHasWarnings(boolean hasWarnings)
- Specified by:
setHasWarningsin interfaceProtocol
-
getActiveStreamingResult
public Results getActiveStreamingResult()
- Specified by:
getActiveStreamingResultin interfaceProtocol
-
setActiveStreamingResult
public void setActiveStreamingResult(Results activeStreamingResult)
- 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
public java.util.concurrent.locks.ReentrantLock getLock()
-
hasMoreResults
public boolean hasMoreResults()
- Specified by:
hasMoreResultsin interfaceProtocol
-
prepareStatementCache
public ServerPrepareStatementCache prepareStatementCache()
- Specified by:
prepareStatementCachein interfaceProtocol
-
executeQuery
public abstract void executeQuery(java.lang.String sql) throws java.sql.SQLException- Specified by:
executeQueryin interfaceProtocol- Throws:
java.sql.SQLException
-
changeSocketTcpNoDelay
public void changeSocketTcpNoDelay(boolean setTcpNoDelay)
Change Socket TcpNoDelay option.- Specified by:
changeSocketTcpNoDelayin interfaceProtocol- Parameters:
setTcpNoDelay- value to set.
-
changeSocketSoTimeout
public void changeSocketSoTimeout(int setSoTimeout) throws java.net.SocketException- Specified by:
changeSocketSoTimeoutin interfaceProtocol- Throws:
java.net.SocketException
-
isServerMariaDb
public boolean isServerMariaDb()
- Specified by:
isServerMariaDbin interfaceProtocol
-
getReader
public PacketInputStream getReader()
-
getWriter
public PacketOutputStream getWriter()
-
isEofDeprecated
public boolean isEofDeprecated()
- Specified by:
isEofDeprecatedin interfaceProtocol
-
sessionStateAware
public boolean sessionStateAware()
- Specified by:
sessionStateAwarein interfaceProtocol
-
-