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 Results
activeStreamingResult
protected int
autoIncrementIncrement
protected static java.lang.String
CHECK_GALERA_STATE_QUERY
protected boolean
connected
private HostAddress
currentHost
protected java.lang.String
database
protected boolean
eofDeprecated
protected ExceptionFactory
exceptionFactory
protected boolean
explicitClosed
protected java.util.List<java.lang.String>
galeraAllowedStates
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 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
protected int
socketTimeout
private java.util.TimeZone
timeZone
protected LruTraceCache
traceCache
protected UrlParser
urlParser
private java.lang.String
username
protected PacketOutputStream
writer
-
Constructor Summary
Constructors Constructor Description AbstractConnectProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, java.util.concurrent.locks.ReentrantLock lock, LruTraceCache traceCache)
Get a protocol instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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
assignStream(java.net.Socket socket, Options options)
private void
authenticationHandler(byte exchangeCharset, long clientCapabilities, java.lang.String authenticationPluginType, byte[] seed, Options options, java.lang.String database, Credential credential, java.lang.String host)
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)
private void
compressionHandler(Options options)
void
connect()
Connect to currentHost.void
connectWithoutProxy()
Connect without proxy.private void
createConnection(HostAddress hostAddress, java.lang.String username)
private static java.net.Socket
createSocket(java.lang.String host, int port, Options options)
private byte
decideLanguage(int serverLanguage)
Default collation used for string exchanges with server.void
destroySocket()
Closing socket in case of Connection error after socket creation.private static void
enabledSslCipherSuites(javax.net.ssl.SSLSocket sslSocket, Options options)
Set ssl socket cipher according to options.private static void
enabledSslProtocolSuites(javax.net.ssl.SSLSocket sslSocket, Options options)
Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1".abstract void
executeQuery(java.lang.String sql)
private void
forceAbort()
private void
galeraStateValidation()
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()
boolean
hasMoreResults()
boolean
hasWarnings()
Has warnings.private static long
initializeClientCapabilities(Options options, long serverCapabilities, java.lang.String database)
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(java.lang.String serverVersion)
private void
postConnectionQueries()
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
setServerStatus(short serverStatus)
boolean
shouldReconnectWithoutProxy()
Indicate for Old reconnection if can reconnect without throwing exception.void
skip()
Skip packets not read that are not needed.void
skipEofPacket()
Check that next read packet is a End-of-file packet.private void
sslWrapper(java.lang.String host, java.net.Socket socket, Options options, long serverCapabilities, long clientCapabilities, byte exchangeCharset, long serverThreadId)
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
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, putInCache, releasePrepareStatement, reset, resetDatabase, resetStateAfterFailover, rollback, setActiveFutureTask, setCatalog, setLocalInfileInputStream, setMaxRows, setReadonly, setTimeout, setTransactionIsolation, stopIfInterrupted
-
-
-
-
Field Detail
-
SESSION_QUERY
private static final byte[] SESSION_QUERY
-
IS_MASTER_QUERY
private static final byte[] IS_MASTER_QUERY
-
CHECK_GALERA_STATE_QUERY
protected static final java.lang.String CHECK_GALERA_STATE_QUERY
- See Also:
- Constant Field Values
-
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
-
traceCache
protected final LruTraceCache traceCache
-
username
private final java.lang.String username
-
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
-
socketTimeout
protected int socketTimeout
-
exceptionFactory
protected ExceptionFactory exceptionFactory
-
galeraAllowedStates
protected final java.util.List<java.lang.String> galeraAllowedStates
-
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
-
-
Constructor Detail
-
AbstractConnectProtocol
public AbstractConnectProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, java.util.concurrent.locks.ReentrantLock lock, LruTraceCache traceCache)
Get a protocol instance.- Parameters:
urlParser
- connection URL informationglobalInfo
- server global variables informationlock
- the lock for thread synchronisationtraceCache
- trace cache
-
-
Method Detail
-
closeSocket
private static void closeSocket(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, java.net.Socket socket)
-
createSocket
private static java.net.Socket createSocket(java.lang.String host, int port, Options options) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
initializeClientCapabilities
private static long initializeClientCapabilities(Options options, long serverCapabilities, java.lang.String database)
-
enabledSslProtocolSuites
private static void enabledSslProtocolSuites(javax.net.ssl.SSLSocket sslSocket, Options options) throws java.sql.SQLException
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:
java.sql.SQLException
- if protocol isn't a supported protocol
-
enabledSslCipherSuites
private static void enabledSslCipherSuites(javax.net.ssl.SSLSocket sslSocket, Options options) throws java.sql.SQLException
Set ssl socket cipher according to options.- Parameters:
sslSocket
- current ssl socket- Throws:
java.sql.SQLException
- if a cipher isn't known
-
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.SQLException
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
-
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
-
connect
public void connect() throws java.sql.SQLException
Connect to currentHost.
-
createConnection
private void createConnection(HostAddress hostAddress, java.lang.String username) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
destroySocket
public void destroySocket()
Closing socket in case of Connection error after socket creation.
-
sslWrapper
private void sslWrapper(java.lang.String host, java.net.Socket socket, Options options, long serverCapabilities, long clientCapabilities, byte exchangeCharset, long serverThreadId) throws java.sql.SQLException, java.io.IOException
- Throws:
java.sql.SQLException
java.io.IOException
-
authenticationHandler
private void authenticationHandler(byte exchangeCharset, long clientCapabilities, java.lang.String authenticationPluginType, byte[] seed, Options options, java.lang.String database, Credential credential, java.lang.String host) throws java.sql.SQLException, java.io.IOException
- Throws:
java.sql.SQLException
java.io.IOException
-
compressionHandler
private void compressionHandler(Options options)
-
assignStream
private void assignStream(java.net.Socket socket, Options options) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
galeraStateValidation
private void galeraStateValidation() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
postConnectionQueries
private void postConnectionQueries() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
sendPipelineAdditionalData
private void sendPipelineAdditionalData() throws java.io.IOException
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:
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.IOException
java.sql.SQLException
-
isClosed
public boolean isClosed()
Is the connection closed.
-
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.SQLException
Check that current connection is a master connection (not read-only).- Specified by:
checkIfMaster
in 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.IOException
Check that next read packet is a End-of-file packet.- Specified by:
readEofPacket
in 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.IOException
Check that next read packet is a End-of-file packet.- Specified by:
skipEofPacket
in interfaceProtocol
- Throws:
java.sql.SQLException
- if not a End-of-file packetjava.io.IOException
- if connection error occur
-
setHostFailedWithoutProxy
public void setHostFailedWithoutProxy()
- Specified by:
setHostFailedWithoutProxy
in interfaceProtocol
-
getUrlParser
public UrlParser 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
private void sendPipelineCheckMaster() throws java.io.IOException
Send 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:
mustBeMasterConnection
in interfaceProtocol
-
noBackslashEscapes
public boolean noBackslashEscapes()
- Specified by:
noBackslashEscapes
in interfaceProtocol
-
connectWithoutProxy
public void connectWithoutProxy() throws java.sql.SQLException
Connect without proxy. (use basic failover implementation)- Specified by:
connectWithoutProxy
in interfaceProtocol
- Throws:
java.sql.SQLException
- exception
-
shouldReconnectWithoutProxy
public boolean shouldReconnectWithoutProxy()
Indicate for Old reconnection if can reconnect without throwing exception.- Specified by:
shouldReconnectWithoutProxy
in interfaceProtocol
- Returns:
- true if can reconnect without issue
-
getServerVersion
public java.lang.String getServerVersion()
- Specified by:
getServerVersion
in interfaceProtocol
-
getReadonly
public boolean getReadonly()
- Specified by:
getReadonly
in interfaceProtocol
-
getHostAddress
public HostAddress getHostAddress()
- Specified by:
getHostAddress
in interfaceProtocol
-
setHostAddress
public void setHostAddress(HostAddress host)
- Specified by:
setHostAddress
in interfaceProtocol
-
getProxy
public FailoverProxy getProxy()
-
setProxy
public void setProxy(FailoverProxy proxy)
-
getDatabase
public java.lang.String getDatabase()
- Specified by:
getDatabase
in interfaceProtocol
-
getUsername
public java.lang.String getUsername()
- Specified by:
getUsername
in interfaceProtocol
-
parseVersion
private void parseVersion(java.lang.String serverVersion)
-
getMajorServerVersion
public int getMajorServerVersion()
- Specified by:
getMajorServerVersion
in interfaceProtocol
-
getMinorServerVersion
public int getMinorServerVersion()
- Specified by:
getMinorServerVersion
in interfaceProtocol
-
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
-
isExplicitClosed
public boolean isExplicitClosed()
- Specified by:
isExplicitClosed
in interfaceProtocol
-
getTimeZone
public java.util.TimeZone getTimeZone()
- Specified by:
getTimeZone
in interfaceProtocol
-
getOptions
public Options getOptions()
- Specified by:
getOptions
in interfaceProtocol
-
setHasWarnings
public void setHasWarnings(boolean hasWarnings)
- Specified by:
setHasWarnings
in interfaceProtocol
-
getActiveStreamingResult
public Results getActiveStreamingResult()
- Specified by:
getActiveStreamingResult
in interfaceProtocol
-
setActiveStreamingResult
public void setActiveStreamingResult(Results activeStreamingResult)
- 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
public java.util.concurrent.locks.ReentrantLock getLock()
-
hasMoreResults
public boolean hasMoreResults()
- Specified by:
hasMoreResults
in interfaceProtocol
-
prepareStatementCache
public ServerPrepareStatementCache prepareStatementCache()
- Specified by:
prepareStatementCache
in interfaceProtocol
-
executeQuery
public abstract void executeQuery(java.lang.String sql) throws java.sql.SQLException
- Specified by:
executeQuery
in interfaceProtocol
- Throws:
java.sql.SQLException
-
changeSocketTcpNoDelay
public void changeSocketTcpNoDelay(boolean setTcpNoDelay)
Change Socket TcpNoDelay option.- Specified by:
changeSocketTcpNoDelay
in interfaceProtocol
- Parameters:
setTcpNoDelay
- value to set.
-
changeSocketSoTimeout
public void changeSocketSoTimeout(int setSoTimeout) throws java.net.SocketException
- Specified by:
changeSocketSoTimeout
in interfaceProtocol
- Throws:
java.net.SocketException
-
isServerMariaDb
public boolean isServerMariaDb()
- Specified by:
isServerMariaDb
in interfaceProtocol
-
getReader
public PacketInputStream getReader()
-
isEofDeprecated
public boolean isEofDeprecated()
- Specified by:
isEofDeprecated
in interfaceProtocol
-
sessionStateAware
public boolean sessionStateAware()
- Specified by:
sessionStateAware
in interfaceProtocol
-
-