org.mariadb.jdbc.internal.mysql

## Class MySQLProtocol

- java.lang.Object
- - org.mariadb.jdbc.internal.mysql.MySQLProtocol

All Implemented Interfaces:
  Protocol

Direct Known Subclasses:
  MastersSlavesProtocol

    public class MySQLProtocol
    extends Object
    implements Protocol

### Field Summary

Fields
`StreamingSelectResult` `activeResult`
`protected HostAddress` `currentHost`
`int` `datatypeMappingFlags`
`boolean` `hasWarnings`
`protected JDBCUrl` `jdbcUrl`
`protected ReentrantReadWriteLock` `lock`
`boolean` `moreResults`
`protected SyncPacketFetcher` `packetFetcher`
`protected FailoverProxy` `proxy`
`protected boolean` `readOnly`
`short` `serverStatus`
`protected Socket` `socket`
`protected PacketOutputStream` `writer`

### Constructor Summary

Constructors
Constructor and Description
`MySQLProtocol(JDBCUrl jdbcUrl, ReentrantReadWriteLock lock)` Get a protocol instance

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `cancelCurrentQuery()` cancels the current query - clones the current protocol and executes a query using the new connection
`boolean` `checkIfMaster()`
`void` `close()` Closes socket and stream readers/writers Attempts graceful shutdown.
`protected static void` `close(PacketFetcher fetcher, PacketOutputStream packetOutputStream, Socket socket)`
`void` `closeExplicit()`
`void` `closeIfActiveResult()`
`void` `closePreparedStatement(int statementId)`
`void` `connect()`
`void` `connectWithoutProxy()`
`QueryResult` `executeBatch(List<Query> dQueries, boolean streaming, boolean isRewritable, int rewriteOffset)`
`QueryResult` `executePreparedQuery(String sql, ParameterHolder[] parameters, PrepareResult prepareResult, MySQLType[] parameterTypeHeader, boolean isStreaming)`
`QueryResult` `executePreparedQueryAfterFailover(String sql, ParameterHolder[] parameters, PrepareResult oldPrepareResult, MySQLType[] parameterTypeHeader, boolean isStreaming)`
`QueryResult` `executeQuery(List<Query> dQueries, boolean streaming, boolean isRewritable, int rewriteOffset)`
`QueryResult` `executeQuery(Query dQuery)`
`QueryResult` `executeQuery(Query query, boolean streaming)`
`boolean` `getAutocommit()`
`Calendar` `getCalendar()`
`String` `getDatabase()`
`int` `getDatatypeMappingFlags()`
`String` `getHost()`
`HostAddress` `getHostAddress()`
`JDBCUrl` `getJdbcUrl()`
`int` `getMajorServerVersion()`
`int` `getMaxRows()`
`int` `getMinorServerVersion()`
`QueryResult` `getMoreResults(boolean streaming)`
`static MySQLProtocol` `getNewProtocol(FailoverProxy proxy, JDBCUrl jdbcUrl)`
`Options` `getOptions()`
`String` `getPassword()`
`boolean` `getPinGlobalTxToPhysicalConnection()`
`int` `getPort()`
`FailoverProxy` `getProxy()`
`boolean` `getReadonly()`
`QueryResult` `getResult(Object dQueries, boolean streaming, boolean binaryProtocol)`
`String` `getServerData(String code)`
`long` `getServerThreadId()`
`String` `getServerVersion()`
`int` `getTimeout()` Returns the connection timeout in milliseconds.
`int` `getTransactionIsolationLevel()`
`String` `getUsername()`
`boolean` `hasMoreResults()`
`boolean` `hasUnreadData()`
`boolean` `hasWarnings()`
`static String` `hexdump(byte[] buffer, int offset)`
`static String` `hexdump(ByteBuffer bb, int offset)`
`boolean` `inTransaction()`
`boolean` `isClosed()`
`boolean` `isConnected()`
`boolean` `isExplicitClosed()`
`boolean` `isMasterConnection()`
`static void` `loop(Listener listener, List<HostAddress> addresses, Map<HostAddress,Long> blacklist, SearchFilter searchFilter)` loop until found the failed connection.
`boolean` `mustBeMasterConnection()`
`boolean` `noBackslashEscapes()`
`boolean` `ping()`
`PrepareResult` `prepare(String sql)`
`PrepareStatementCache` `prepareStatementCache()`
`void` `releasePrepareStatement(String sql, int statementId)`
`void` `rollback()`
`void` `setCatalog(String database)`
`void` `setHostAddress(HostAddress host)`
`void` `setHostFailedWithoutProxy()`
`void` `setInternalMaxRows(int max)`
`void` `setLocalInfileInputStream(InputStream inputStream)`
`void` `setMaxRows(int max)`
`void` `setProxy(FailoverProxy proxy)`
`void` `setReadonly(boolean readOnly)`
`void` `setTimeout(int timeout)` Sets the connection timeout.
`void` `setTransactionIsolation(int level)`
`boolean` `shouldReconnectWithoutProxy()`
`boolean` `versionGreaterOrEqual(int major, int minor, int patch)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### lock

    protected final ReentrantReadWriteLock lock

#### jdbcUrl

    protected final JDBCUrl jdbcUrl

#### moreResults

    public boolean moreResults

#### hasWarnings

    public boolean hasWarnings

#### activeResult

    public StreamingSelectResult activeResult

#### datatypeMappingFlags

    public int datatypeMappingFlags

#### serverStatus

    public short serverStatus

#### socket

    protected Socket socket

#### writer

    protected PacketOutputStream writer

#### readOnly

    protected boolean readOnly

#### packetFetcher

    protected SyncPacketFetcher packetFetcher

#### currentHost

    protected HostAddress currentHost

#### proxy

    protected FailoverProxy proxy

### Constructor Detail

#### MySQLProtocol

    public MySQLProtocol(JDBCUrl jdbcUrl,
                         ReentrantReadWriteLock lock)

Get a protocol instance

Parameters:
  `jdbcUrl` - connection URL infos
  `lock` - the lock for thread synchronisation

### Method Detail

#### getNewProtocol

    public static MySQLProtocol getNewProtocol(FailoverProxy proxy,
                                               JDBCUrl jdbcUrl)

#### loop

    public static void loop(Listener listener,
                            List<HostAddress> addresses,
                            Map<HostAddress,Long> blacklist,
                            SearchFilter searchFilter)
                     throws QueryException

loop until found the failed connection.

Parameters:
  `listener` - current listener
  `addresses` - list of HostAddress to loop
  `blacklist` - current blacklist
  `searchFilter` - search parameter
Throws:
  `QueryException` - if not found

#### close

    protected static void close(PacketFetcher fetcher,
                                PacketOutputStream packetOutputStream,
                                Socket socket)
                         throws QueryException

Throws:
  `QueryException`

#### hexdump

    public static String hexdump(byte[] buffer,
                                 int offset)

#### hexdump

    public static String hexdump(ByteBuffer bb,
                                 int offset)

#### getServerData

    public String getServerData(String code)

Specified by:
  `getServerData` in interface `Protocol`

#### checkIfMaster

    public boolean checkIfMaster()
                          throws QueryException

Specified by:
  `checkIfMaster` in interface `Protocol`
Throws:
  `QueryException`

#### prepare

    public PrepareResult prepare(String sql)
                          throws QueryException

Specified by:
  `prepare` in interface `Protocol`
Throws:
  `QueryException`

#### closePreparedStatement

    public void closePreparedStatement(int statementId)
                                throws QueryException

Specified by:
  `closePreparedStatement` in interface `Protocol`
Throws:
  `QueryException`

#### setHostFailedWithoutProxy

    public void setHostFailedWithoutProxy()

Specified by:
  `setHostFailedWithoutProxy` in interface `Protocol`

#### getJdbcUrl

    public JDBCUrl getJdbcUrl()

Specified by:
  `getJdbcUrl` in interface `Protocol`

#### getAutocommit

    public boolean getAutocommit()

Specified by:
  `getAutocommit` in interface `Protocol`

#### isMasterConnection

    public boolean isMasterConnection()

Specified by:
  `isMasterConnection` in interface `Protocol`

#### mustBeMasterConnection

    public boolean mustBeMasterConnection()

Specified by:
  `mustBeMasterConnection` in interface `Protocol`

#### noBackslashEscapes

    public boolean noBackslashEscapes()

Specified by:
  `noBackslashEscapes` in interface `Protocol`

#### connect

    public void connect()
                 throws QueryException

Specified by:
  `connect` in interface `Protocol`
Throws:
  `QueryException`

#### connectWithoutProxy

    public void connectWithoutProxy()
                             throws QueryException

Specified by:
  `connectWithoutProxy` in interface `Protocol`
Throws:
  `QueryException`

#### shouldReconnectWithoutProxy

    public boolean shouldReconnectWithoutProxy()

Specified by:
  `shouldReconnectWithoutProxy` in interface `Protocol`

#### inTransaction

    public boolean inTransaction()

Specified by:
  `inTransaction` in interface `Protocol`

#### getOptions

    public Options getOptions()

Specified by:
  `getOptions` in interface `Protocol`

#### hasMoreResults

    public boolean hasMoreResults()

Specified by:
  `hasMoreResults` in interface `Protocol`

#### closeExplicit

    public void closeExplicit()

Specified by:
  `closeExplicit` in interface `Protocol`

#### close

    public void close()

Closes socket and stream readers/writers Attempts graceful shutdown.

Specified by:
  `close` in interface `Protocol`

#### rollback

    public void rollback()

Specified by:
  `rollback` in interface `Protocol`

#### isClosed

    public boolean isClosed()

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

#### setCatalog

    public void setCatalog(String database)
                    throws QueryException

Specified by:
  `setCatalog` in interface `Protocol`
Throws:
  `QueryException`

#### 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`

#### ping

    public boolean ping()
                 throws QueryException

Specified by:
  `ping` in interface `Protocol`
Throws:
  `QueryException`

#### executeQuery

    public QueryResult executeQuery(Query dQuery)
                             throws QueryException

Specified by:
  `executeQuery` in interface `Protocol`
Throws:
  `QueryException`

#### getResult

    public QueryResult getResult(Object dQueries,
                                 boolean streaming,
                                 boolean binaryProtocol)
                          throws QueryException

Specified by:
  `getResult` in interface `Protocol`
Throws:
  `QueryException`

#### executeQuery

    public QueryResult executeQuery(Query query,
                                    boolean streaming)
                             throws QueryException

Specified by:
  `executeQuery` in interface `Protocol`
Throws:
  `QueryException`

#### executeQuery

    public QueryResult executeQuery(List<Query> dQueries,
                                    boolean streaming,
                                    boolean isRewritable,
                                    int rewriteOffset)
                             throws QueryException

Specified by:
  `executeQuery` in interface `Protocol`
Throws:
  `QueryException`

#### executeBatch

    public QueryResult executeBatch(List<Query> dQueries,
                                    boolean streaming,
                                    boolean isRewritable,
                                    int rewriteOffset)
                             throws QueryException

Throws:
  `QueryException`

#### executePreparedQueryAfterFailover

    public QueryResult executePreparedQueryAfterFailover(String sql,
                                                         ParameterHolder[] parameters,
                                                         PrepareResult oldPrepareResult,
                                                         MySQLType[] parameterTypeHeader,
                                                         boolean isStreaming)
                                                  throws QueryException

Specified by:
  `executePreparedQueryAfterFailover` in interface `Protocol`
Throws:
  `QueryException`

#### executePreparedQuery

    public QueryResult executePreparedQuery(String sql,
                                            ParameterHolder[] parameters,
                                            PrepareResult prepareResult,
                                            MySQLType[] parameterTypeHeader,
                                            boolean isStreaming)
                                     throws QueryException

Specified by:
  `executePreparedQuery` in interface `Protocol`
Throws:
  `QueryException`

#### releasePrepareStatement

    public void releasePrepareStatement(String sql,
                                        int statementId)
                                 throws QueryException

Specified by:
  `releasePrepareStatement` in interface `Protocol`
Throws:
  `QueryException`

#### cancelCurrentQuery

    public void cancelCurrentQuery()
                            throws QueryException,
                                   IOException

cancels the current query - clones the current protocol and executes a query using the new connection

Specified by:
  `cancelCurrentQuery` in interface `Protocol`
Throws:
  `QueryException` - never thrown
  `IOException` - if Host is not responding

#### getMoreResults

    public QueryResult getMoreResults(boolean streaming)
                               throws QueryException

Specified by:
  `getMoreResults` in interface `Protocol`
Throws:
  `QueryException`

#### hasUnreadData

    public boolean hasUnreadData()

Specified by:
  `hasUnreadData` in interface `Protocol`

#### setInternalMaxRows

    public void setInternalMaxRows(int max)

Specified by:
  `setInternalMaxRows` in interface `Protocol`

#### getMaxRows

    public int getMaxRows()

Specified by:
  `getMaxRows` in interface `Protocol`

#### setMaxRows

    public void setMaxRows(int max)
                    throws QueryException

Specified by:
  `setMaxRows` in interface `Protocol`
Throws:
  `QueryException`

#### getMajorServerVersion

    public int getMajorServerVersion()

Specified by:
  `getMajorServerVersion` in interface `Protocol`

#### getMinorServerVersion

    public int getMinorServerVersion()

Specified by:
  `getMinorServerVersion` in interface `Protocol`

#### versionGreaterOrEqual

    public boolean versionGreaterOrEqual(int major,
                                         int minor,
                                         int patch)

Specified by:
  `versionGreaterOrEqual` in interface `Protocol`

#### setLocalInfileInputStream

    public void setLocalInfileInputStream(InputStream inputStream)

Specified by:
  `setLocalInfileInputStream` in interface `Protocol`

#### getTimeout

    public int getTimeout()
                   throws SocketException

Returns the connection timeout in milliseconds.

Specified by:
  `getTimeout` in interface `Protocol`
Returns:
  the connection timeout in milliseconds.
Throws:
  `SocketException` - if there is an error in the underlying protocol, such as a TCP error.

#### setTimeout

    public void setTimeout(int timeout)
                    throws SocketException

Sets the connection timeout.

Specified by:
  `setTimeout` in interface `Protocol`
Parameters:
  `timeout` - the timeout, in milliseconds
Throws:
  `SocketException` - if there is an error in the underlying protocol, such as a TCP error.

#### getPinGlobalTxToPhysicalConnection

    public boolean getPinGlobalTxToPhysicalConnection()

Specified by:
  `getPinGlobalTxToPhysicalConnection` in interface `Protocol`

#### setTransactionIsolation

    public void setTransactionIsolation(int level)
                                 throws QueryException

Specified by:
  `setTransactionIsolation` in interface `Protocol`
Throws:
  `QueryException`

#### getTransactionIsolationLevel

    public int getTransactionIsolationLevel()

Specified by:
  `getTransactionIsolationLevel` in interface `Protocol`

#### hasWarnings

    public boolean hasWarnings()

Specified by:
  `hasWarnings` in interface `Protocol`

#### isConnected

    public boolean isConnected()

Specified by:
  `isConnected` in interface `Protocol`

#### getServerThreadId

    public long getServerThreadId()

Specified by:
  `getServerThreadId` in interface `Protocol`

#### getDatatypeMappingFlags

    public int getDatatypeMappingFlags()

Specified by:
  `getDatatypeMappingFlags` in interface `Protocol`

#### closeIfActiveResult

    public void closeIfActiveResult()

Specified by:
  `closeIfActiveResult` in interface `Protocol`

#### isExplicitClosed

    public boolean isExplicitClosed()

Specified by:
  `isExplicitClosed` in interface `Protocol`

#### prepareStatementCache

    public PrepareStatementCache prepareStatementCache()

Specified by:
  `prepareStatementCache` in interface `Protocol`

#### getCalendar

    public Calendar getCalendar()

Specified by:
  `getCalendar` in interface `Protocol`