org.mariadb.jdbc.internal.protocol
Class AbstractConnectProtocol

java.lang.Object
  extended by org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol
All Implemented Interfaces:
Protocol
Direct Known Subclasses:
AbstractQueryProtocol

public abstract class AbstractConnectProtocol
extends Object
implements Protocol


Field Summary
 Results activeStreamingResult
           
protected  int autoIncrementIncrement
           
protected  boolean connected
           
protected  HostAddress currentHost
           
protected  String database
           
 int dataTypeMappingFlags
           
protected  boolean eofDeprecated
           
protected  boolean explicitClosed
           
 boolean hasWarnings
           
static byte[] IS_MASTER_QUERY
           
protected  ReentrantLock lock
           
protected  Options options
           
protected  FailoverProxy proxy
           
protected  PacketInputStream reader
           
protected  boolean readOnly
           
protected  long serverCapabilities
           
protected  ServerPrepareStatementCache serverPrepareStatementCache
           
 short serverStatus
           
protected  long serverThreadId
           
static byte[] SESSION_QUERY
           
protected  Socket socket
           
protected  UrlParser urlParser
           
protected  PacketOutputStream writer
           
 
Constructor Summary
AbstractConnectProtocol(UrlParser urlParser, ReentrantLock lock)
          Get a protocol instance.
 
Method Summary
 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)
 void close()
          Closes socket and stream readers/writers Attempts graceful shutdown.
protected static void close(PacketInputStream packetInputStream, PacketOutputStream packetOutputStream, Socket socket)
           
 void connect()
          Connect to currentHost.
 void connectWithoutProxy()
          Connect without proxy.
protected  void enabledSslCipherSuites(SSLSocket sslSocket)
          Set ssl socket cipher according to options.
protected  void enabledSslProtocolSuites(SSLSocket sslSocket)
          Return possible protocols : values of option enabledSslProtocolSuites is set, or default to "TLSv1,TLSv1.1".
abstract  void executeQuery(String sql)
           
 Results getActiveStreamingResult()
           
 String getDatabase()
           
 int getDataTypeMappingFlags()
           
 String getHost()
           
 HostAddress getHostAddress()
           
 ReentrantLock getLock()
           
 int getMajorServerVersion()
           
 int getMinorServerVersion()
           
 Options getOptions()
           
 String getPassword()
           
 boolean getPinGlobalTxToPhysicalConnection()
           
 int getPort()
           
 FailoverProxy getProxy()
           
 PacketInputStream getReader()
           
 boolean getReadonly()
           
 String getServerData(String code)
           
 long getServerThreadId()
           
 String getServerVersion()
           
 TimeZone getTimeZone()
           
 String getTraces()
           
 UrlParser getUrlParser()
           
 String getUsername()
           
 PacketOutputStream getWriter()
           
 boolean hasMoreResults()
           
 boolean hasWarnings()
          Has warnings.
 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()
           
 boolean mustBeMasterConnection()
           
 boolean noBackslashEscapes()
           
 ServerPrepareStatementCache prepareStatementCache()
           
 void readEofPacket()
          Check that next read packet is a End-of-file packet.
 void readPipelineCheckMaster()
           
 void removeActiveStreamingResult()
          Remove exception result and since totally fetched, set fetch size to 0.
 void removeHasMoreResults()
           
 void sendPipelineCheckMaster()
          Send query to identify if server is master.
 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.
 
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, executeBatch, executeBatchMulti, executeBatchMultiple, executeBatchRewrite, executePreparedQuery, executeQuery, executeQuery, executeQuery, executeQuery, forceReleasePrepareStatement, forceReleaseWaitingPrepareStatement, getAutocommit, getAutoIncrementIncrement, getMaxRows, getResult, getTimeout, getTransactionIsolationLevel, handleIoException, inTransaction, isInterrupted, isValid, ping, prepare, prepareAndExecute, prepareAndExecutes, prolog, prologProxy, releasePrepareStatement, resetStateAfterFailover, rollback, setActiveFutureTask, setCatalog, setInternalMaxRows, setLocalInfileInputStream, setMaxRows, setTimeout, setTransactionIsolation, stopIfInterrupted
 

Field Detail

SESSION_QUERY

public static final byte[] SESSION_QUERY

IS_MASTER_QUERY

public static final byte[] IS_MASTER_QUERY

lock

protected final ReentrantLock lock

urlParser

protected final UrlParser urlParser

options

protected final Options options

hasWarnings

public boolean hasWarnings

activeStreamingResult

public Results activeStreamingResult

dataTypeMappingFlags

public int dataTypeMappingFlags

serverStatus

public short serverStatus

autoIncrementIncrement

protected int autoIncrementIncrement

socket

protected Socket socket

writer

protected PacketOutputStream writer

readOnly

protected boolean readOnly

reader

protected PacketInputStream reader

currentHost

protected HostAddress currentHost

proxy

protected FailoverProxy proxy

connected

protected volatile boolean connected

explicitClosed

protected boolean explicitClosed

database

protected String database

serverThreadId

protected long serverThreadId

serverPrepareStatementCache

protected ServerPrepareStatementCache serverPrepareStatementCache

eofDeprecated

protected boolean eofDeprecated

serverCapabilities

protected long serverCapabilities
Constructor Detail

AbstractConnectProtocol

public AbstractConnectProtocol(UrlParser urlParser,
                               ReentrantLock lock)
Get a protocol instance.

Parameters:
urlParser - connection URL infos
lock - the lock for thread synchronisation
Method Detail

close

protected static void close(PacketInputStream packetInputStream,
                            PacketOutputStream packetOutputStream,
                            Socket socket)
                     throws SQLException
Throws:
SQLException

close

public void close()
Closes socket and stream readers/writers Attempts graceful shutdown.

Specified by:
close in interface Protocol

skip

public void skip()
          throws 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

Specified by:
skip in interface Protocol
Throws:
SQLException - exception

setServerStatus

public void setServerStatus(short serverStatus)
Specified by:
setServerStatus in interface Protocol

removeHasMoreResults

public void removeHasMoreResults()
Specified by:
removeHasMoreResults in interface Protocol

connect

public void connect()
             throws SQLException
Connect to currentHost.

Specified by:
connect in interface Protocol
Throws:
SQLException - exception

isClosed

public boolean isClosed()
Is the connection closed.

Specified by:
isClosed in interface Protocol
Returns:
true if the connection is closed

getServerData

public String getServerData(String code)

checkIfMaster

public boolean checkIfMaster()
                      throws SQLException
Check that current connection is a master connection (not read-only)

Specified by:
checkIfMaster in interface Protocol
Returns:
true if master
Throws:
SQLException - if requesting infos for server fail.

readEofPacket

public void readEofPacket()
                   throws SQLException,
                          IOException
Check that next read packet is a End-of-file packet.

Specified by:
readEofPacket in interface Protocol
Throws:
SQLException - if not a End-of-file packet
IOException - if connection error occur

skipEofPacket

public void skipEofPacket()
                   throws SQLException,
                          IOException
Check that next read packet is a End-of-file packet.

Specified by:
skipEofPacket in interface Protocol
Throws:
SQLException - if not a End-of-file packet
IOException - if connection error occur

setHostFailedWithoutProxy

public void setHostFailedWithoutProxy()
Specified by:
setHostFailedWithoutProxy in interface Protocol

getUrlParser

public UrlParser getUrlParser()
Specified by:
getUrlParser in interface Protocol

isMasterConnection

public boolean isMasterConnection()
Indicate if current protocol is a master protocol.

Specified by:
isMasterConnection in interface Protocol
Returns:
is master flag

sendPipelineCheckMaster

public void sendPipelineCheckMaster()
                             throws IOException
Send query to identify if server is master.

Throws:
IOException - in case of socket error.

readPipelineCheckMaster

public void readPipelineCheckMaster()
                             throws IOException,
                                    SQLException
Throws:
IOException
SQLException

mustBeMasterConnection

public boolean mustBeMasterConnection()
Specified by:
mustBeMasterConnection in interface Protocol

noBackslashEscapes

public boolean noBackslashEscapes()
Specified by:
noBackslashEscapes in interface Protocol

connectWithoutProxy

public void connectWithoutProxy()
                         throws SQLException
Connect without proxy. (use basic failover implementation)

Specified by:
connectWithoutProxy in interface Protocol
Throws:
SQLException - exception

shouldReconnectWithoutProxy

public boolean shouldReconnectWithoutProxy()
Specified by:
shouldReconnectWithoutProxy in interface Protocol

getServerVersion

public String getServerVersion()
Specified by:
getServerVersion in interface Protocol

getReadonly

public boolean getReadonly()
Specified by:
getReadonly in interface Protocol

setReadonly

public void setReadonly(boolean readOnly)
Specified by:
setReadonly in interface Protocol

getHostAddress

public HostAddress getHostAddress()
Specified by:
getHostAddress in interface Protocol

setHostAddress

public void setHostAddress(HostAddress host)
Specified by:
setHostAddress in interface Protocol

getHost

public String getHost()
Specified by:
getHost in interface Protocol

getProxy

public FailoverProxy getProxy()
Specified by:
getProxy in interface Protocol

setProxy

public void setProxy(FailoverProxy proxy)
Specified by:
setProxy in interface Protocol

getPort

public int getPort()
Specified by:
getPort in interface Protocol

getDatabase

public String getDatabase()
Specified by:
getDatabase in interface Protocol

getUsername

public String getUsername()
Specified by:
getUsername in interface Protocol

getPassword

public String getPassword()
Specified by:
getPassword in interface Protocol

getMajorServerVersion

public int getMajorServerVersion()
Specified by:
getMajorServerVersion in interface Protocol

getMinorServerVersion

public int getMinorServerVersion()
Specified by:
getMinorServerVersion in interface Protocol

enabledSslProtocolSuites

protected void enabledSslProtocolSuites(SSLSocket sslSocket)
                                 throws 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:
SQLException - if protocol isn't a supported protocol

enabledSslCipherSuites

protected void enabledSslCipherSuites(SSLSocket sslSocket)
                               throws SQLException
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 interface Protocol
Parameters:
major - major version
minor - minor version
patch - patch version
Returns:
true if version is greater than parameters

getPinGlobalTxToPhysicalConnection

public boolean getPinGlobalTxToPhysicalConnection()
Specified by:
getPinGlobalTxToPhysicalConnection in interface Protocol

hasWarnings

public boolean hasWarnings()
Has warnings.

Specified by:
hasWarnings in interface Protocol
Returns:
true if as warnings.

isConnected

public boolean isConnected()
Is connected.

Specified by:
isConnected in interface Protocol
Returns:
true if connected

getServerThreadId

public long getServerThreadId()
Specified by:
getServerThreadId in interface Protocol

getDataTypeMappingFlags

public int getDataTypeMappingFlags()
Specified by:
getDataTypeMappingFlags in interface Protocol

isExplicitClosed

public boolean isExplicitClosed()
Specified by:
isExplicitClosed in interface Protocol

getTimeZone

public TimeZone getTimeZone()
Specified by:
getTimeZone in interface Protocol

getOptions

public Options getOptions()
Specified by:
getOptions in interface Protocol

setHasWarnings

public void setHasWarnings(boolean hasWarnings)
Specified by:
setHasWarnings in interface Protocol

getActiveStreamingResult

public Results getActiveStreamingResult()
Specified by:
getActiveStreamingResult in interface Protocol

setActiveStreamingResult

public void setActiveStreamingResult(Results activeStreamingResult)
Specified by:
setActiveStreamingResult in interface Protocol

removeActiveStreamingResult

public void removeActiveStreamingResult()
Remove exception result and since totally fetched, set fetch size to 0.

Specified by:
removeActiveStreamingResult in interface Protocol

getLock

public ReentrantLock getLock()
Specified by:
getLock in interface Protocol

hasMoreResults

public boolean hasMoreResults()
Specified by:
hasMoreResults in interface Protocol

prepareStatementCache

public ServerPrepareStatementCache prepareStatementCache()
Specified by:
prepareStatementCache in interface Protocol

executeQuery

public abstract void executeQuery(String sql)
                           throws SQLException
Specified by:
executeQuery in interface Protocol
Throws:
SQLException

changeSocketTcpNoDelay

public void changeSocketTcpNoDelay(boolean setTcpNoDelay)
Change Socket TcpNoDelay option.

Specified by:
changeSocketTcpNoDelay in interface Protocol
Parameters:
setTcpNoDelay - value to set.

changeSocketSoTimeout

public void changeSocketSoTimeout(int setSoTimeout)
                           throws SocketException
Specified by:
changeSocketSoTimeout in interface Protocol
Throws:
SocketException

isServerMariaDb

public boolean isServerMariaDb()
Specified by:
isServerMariaDb in interface Protocol

getReader

public PacketInputStream getReader()
Specified by:
getReader in interface Protocol

getWriter

public PacketOutputStream getWriter()
Specified by:
getWriter in interface Protocol

isEofDeprecated

public boolean isEofDeprecated()
Specified by:
isEofDeprecated in interface Protocol

sessionStateAware

public boolean sessionStateAware()
Specified by:
sessionStateAware in interface Protocol

getTraces

public String getTraces()
Specified by:
getTraces in interface Protocol


Copyright © 2017. All rights reserved.