org.mariadb.jdbc.internal.protocol

## Class AbstractQueryProtocol

- java.lang.Object
- - org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol
  - - org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol

All Implemented Interfaces:
  Protocol

Direct Known Subclasses:
  MasterProtocol

    public class AbstractQueryProtocol
    extends AbstractConnectProtocol
    implements Protocol

### Field Summary

### Fields inherited from class org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol

`activeResult, connected, currentHost, database, dataTypeMappingFlags, explicitClosed, hasWarnings, lock, moreResults, packetFetcher, prepareStatementCache, proxy, readOnly, serverStatus, serverThreadId, socket, urlParser, writer`

### Constructor Summary

Constructors
Constructor and Description
`AbstractQueryProtocol(UrlParser urlParser, ReentrantLock 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.
`void` `closeExplicit()`
`void` `closeIfActiveResult()` Close active result.
`AbstractQueryResult` `executePreparedQuery(PrepareResult prepareResult, String sql, ParameterHolder[] parameters, MariaDbType[] parameterTypeHeader, boolean isStreaming)`
`AbstractQueryResult` `executePreparedQueryAfterFailover(PrepareResult oldPrepareResult, String sql, ParameterHolder[] parameters, MariaDbType[] parameterTypeHeader, boolean isStreaming)`
`AbstractQueryResult` `executeQueries(List<String> queryParts, List<ParameterHolder[]> parameterList, boolean streaming, boolean isRewritable)` Specific execution for batch rewrite that has specific query for memory.
`AbstractQueryResult` `executeQuery(List<String> queries, boolean streaming, boolean isRewritable, int rewriteOffset)` Execute list of queries.
`AbstractQueryResult` `executeQuery(String sql, boolean streaming)` Execute query.
`void` `forceReleasePrepareStatement(int statementId)` Force release of prepare statement that are not used.
`boolean` `getAutocommit()`
`int` `getMaxRows()`
`AbstractQueryResult` `getMoreResults(boolean streaming)`
`AbstractQueryResult` `getResult(boolean streaming, boolean binaryProtocol)`
`int` `getTimeout()` Returns the connection timeout in milliseconds.
`int` `getTransactionIsolationLevel()`
`boolean` `hasMoreResults()`
`static String` `hexdump(byte[] buffer, int offset)` Hexdump.
`static String` `hexdump(ByteBuffer bb, int offset)` Hexdump.
`boolean` `inTransaction()`
`boolean` `ping()`
`PrepareResult` `prepare(String sql, boolean forceNew)`
`PrepareStatementCache` `prepareStatementCache()`
`void` `prolog(boolean isStreaming, int maxRows, boolean hasProxy, MariaDbConnection connection, Statement statement)` Preparation before command.
`void` `prologProxy(PrepareResult prepareResult, boolean isStreaming, int maxRows, boolean hasProxy, MariaDbConnection connection, Statement statement)`
`void` `releasePrepareStatement(PrepareResult prepareResult, String sql)` Deallocate prepare statement if not used anymore.
`void` `rollback()` Rollback transaction.
`void` `setCatalog(String database)`
`void` `setInternalMaxRows(int max)` Set max row retuen by a statement.
`void` `setLocalInfileInputStream(InputStream inputStream)`
`void` `setMaxRows(int max)`
`void` `setTimeout(int timeout)` Sets the connection timeout.
`void` `setTransactionIsolation(int level)` Set transaction isolation.

### Methods inherited from class org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol

`checkIfMaster, close, close, connect, connectWithoutProxy, getCalendar, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getMajorServerVersion, getMinorServerVersion, getOptions, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReadonly, getServerData, getServerThreadId, getServerVersion, getUrlParser, getUsername, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, readEofPacket, setHostAddress, setHostFailedWithoutProxy, setProxy, setReadonly, shouldReconnectWithoutProxy, versionGreaterOrEqual`

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

`checkIfMaster, close, connect, connectWithoutProxy, getCalendar, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getMajorServerVersion, getMinorServerVersion, getOptions, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReadonly, getServerData, getServerThreadId, getServerVersion, getUrlParser, getUsername, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, setHostAddress, setHostFailedWithoutProxy, setProxy, setReadonly, shouldReconnectWithoutProxy, versionGreaterOrEqual`

### Constructor Detail

#### AbstractQueryProtocol

    public AbstractQueryProtocol(UrlParser urlParser,
                                 ReentrantLock lock)

Get a protocol instance.

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

### Method Detail

#### hexdump

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

Hexdump.

Parameters:
  `buffer` - byte array
  `offset` - offset
Returns:
  String

#### hexdump

    public static String hexdump(ByteBuffer bb,
                                 int offset)

Hexdump.

Parameters:
  `bb` - bytebuffer
  `offset` - offset
Returns:
  String

#### prepare

    public PrepareResult prepare(String sql,
                                 boolean forceNew)
                          throws QueryException

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

#### getAutocommit

    public boolean getAutocommit()

Specified by:
  `getAutocommit` in interface `Protocol`

#### inTransaction

    public boolean inTransaction()

Specified by:
  `inTransaction` in interface `Protocol`

#### hasMoreResults

    public boolean hasMoreResults()

Specified by:
  `hasMoreResults` in interface `Protocol`

#### closeExplicit

    public void closeExplicit()

Specified by:
  `closeExplicit` in interface `Protocol`

#### rollback

    public void rollback()

Rollback transaction.

Specified by:
  `rollback` in interface `Protocol`

#### setCatalog

    public void setCatalog(String database)
                    throws QueryException

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

#### ping

    public boolean ping()
                 throws QueryException

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

#### executePreparedQueryAfterFailover

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

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

#### executePreparedQuery

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

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

#### releasePrepareStatement

    public void releasePrepareStatement(PrepareResult prepareResult,
                                        String sql)
                                 throws QueryException

Deallocate prepare statement if not used anymore.

Specified by:
  `releasePrepareStatement` in interface `Protocol`
Parameters:
  `prepareResult` - allocation result
  `sql` - sql query
Throws:
  `QueryException` - if deallocation failed.

#### forceReleasePrepareStatement

    public void forceReleasePrepareStatement(int statementId)
                                      throws QueryException

Force release of prepare statement that are not used. This method will be call when adding a new preparestatement in cache, so the packet can be send to server without problem.

Specified by:
  `forceReleasePrepareStatement` in interface `Protocol`
Parameters:
  `statementId` - prepared statement Id to remove.
Throws:
  `QueryException` - if connection exception.

#### 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 AbstractQueryResult getMoreResults(boolean streaming)
                                       throws QueryException

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

#### setInternalMaxRows

    public void setInternalMaxRows(int max)

Set max row retuen by a statement.

Specified by:
  `setInternalMaxRows` in interface `Protocol`
Parameters:
  `max` - row number max value

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

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

#### setTransactionIsolation

    public void setTransactionIsolation(int level)
                                 throws QueryException

Set transaction isolation.

Specified by:
  `setTransactionIsolation` in interface `Protocol`
Parameters:
  `level` - transaction level.
Throws:
  `QueryException` - if transaction level is unknown

#### getTransactionIsolationLevel

    public int getTransactionIsolationLevel()

Specified by:
  `getTransactionIsolationLevel` in interface `Protocol`

#### closeIfActiveResult

    public void closeIfActiveResult()

Close active result.

Specified by:
  `closeIfActiveResult` in interface `Protocol`

#### prepareStatementCache

    public PrepareStatementCache prepareStatementCache()

Specified by:
  `prepareStatementCache` in interface `Protocol`

#### executeQuery

    public AbstractQueryResult executeQuery(String sql,
                                            boolean streaming)
                                     throws QueryException

Execute query.

Specified by:
  `executeQuery` in interface `Protocol`
Parameters:
  `sql` - the query to executeInternal
  `streaming` - is streaming flag
Returns:
  queryResult
Throws:
  `QueryException` - exception

#### executeQuery

    public AbstractQueryResult executeQuery(List<String> queries,
                                            boolean streaming,
                                            boolean isRewritable,
                                            int rewriteOffset)
                                     throws QueryException

Execute list of queries. This method is used when using text batch statement and using rewriting (allowMultiQueries || rewriteBatchedStatements). queries will be send to server according to max_allowed_packet size.

Specified by:
  `executeQuery` in interface `Protocol`
Parameters:
  `queries` - list of queryes
  `streaming` - is streaming flag
  `isRewritable` - is rewritable flag
  `rewriteOffset` - rewrite offset
Returns:
  queryresult
Throws:
  `QueryException` - exception

#### executeQueries

    public AbstractQueryResult executeQueries(List<String> queryParts,
                                              List<ParameterHolder[]> parameterList,
                                              boolean streaming,
                                              boolean isRewritable)
                                       throws QueryException

Specific execution for batch rewrite that has specific query for memory.

Specified by:
  `executeQueries` in interface `Protocol`
Parameters:
  `queryParts` - query part
  `parameterList` - parameters
  `streaming` - is streaming flag
  `isRewritable` - is rewritable flag
Returns:
  queryresult
Throws:
  `QueryException` - exception

#### getResult

    public AbstractQueryResult getResult(boolean streaming,
                                         boolean binaryProtocol)
                                  throws QueryException

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

#### prologProxy

    public void prologProxy(PrepareResult prepareResult,
                            boolean isStreaming,
                            int maxRows,
                            boolean hasProxy,
                            MariaDbConnection connection,
                            Statement statement)
                     throws SQLException

Specified by:
  `prologProxy` in interface `Protocol`
Throws:
  `SQLException`

#### prolog

    public void prolog(boolean isStreaming,
                       int maxRows,
                       boolean hasProxy,
                       MariaDbConnection connection,
                       Statement statement)
                throws SQLException

Preparation before command.

Specified by:
  `prolog` in interface `Protocol`
Parameters:
  `isStreaming` - is streaming
  `maxRows` - query max rows
  `hasProxy` - has proxy
  `connection` - current connection
  `statement` - current statement
Throws:
  `SQLException` - if any error occur.