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

`activeStreamingResult, connected, currentHost, database, dataTypeMappingFlags, explicitClosed, hasWarnings, lock, moreResults, moreResultsTypeBinary, options, 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` `executePreparedQuery(PrepareResult prepareResult, ExecutionResult executionResult, String sql, ParameterHolder[] parameters, MariaDbType[] parameterTypeHeader, int resultSetScrollType)`
`void` `executePreparedQueryAfterFailover(PrepareResult oldPrepareResult, ExecutionResult executionResult, String sql, ParameterHolder[] parameters, MariaDbType[] parameterTypeHeader, int resultSetScrollType)`
`void` `executeQueries(ExecutionResult executionResult, List<String> queries, int resultSetScrollType)` Execute list of queries not rewritable.
`void` `executeQueries(ExecutionResult executionResult, List<String> queryParts, List<ParameterHolder[]> parameterList, int resultSetScrollType, boolean isRewritable)` Specific execution for batch rewrite that has specific query for memory.
`void` `executeQueriesRewrite(ExecutionResult executionResult, List<String> queries, int resultSetScrollType, boolean isRewritable, int rewriteOffset)` Execute list of queries.
`void` `executeQuery(ExecutionResult executionResult, String sql, int resultSetScrollType)` Execute query.
`void` `executeQuery(String sql)`
`void` `fetchActiveStreamingResult()` Close active result.
`void` `forceReleasePrepareStatement(int statementId)` Force release of prepare statement that are not used.
`boolean` `getAutocommit()`
`int` `getMaxRows()`
`void` `getMoreResults(ExecutionResult executionResult)`
`void` `getResult(ExecutionResult executionResult, int resultSetScrollType, boolean binaryProtocol)`
`int` `getTimeout()` Returns the connection timeout in milliseconds.
`int` `getTransactionIsolationLevel()`
`boolean` `hasMoreResults()`
`static String` `hexdump(byte[] buffer, int offset)` Hexdump.
`boolean` `inTransaction()`
`boolean` `ping()`
`PrepareResult` `prepare(String sql)` Prepare query on server side.
`PrepareResult` `prepare(String sql, boolean forceNew, boolean executeOnMaster)` Prepare query on server side.
`PrepareStatementCache` `prepareStatementCache()`
`void` `prolog(ExecutionResult executionResult, int maxRows, boolean hasProxy, MariaDbConnection connection, Statement statement)` Preparation before command.
`void` `prologProxy(PrepareResult prepareResult, ExecutionResult executionResult, 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, getActiveStreamingResult, getCalendar, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getPrepareStatementCache, getProxy, getReadonly, getServerData, getServerThreadId, getServerVersion, getUrlParser, getUsername, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, readEofPacket, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setMoreResults, setProxy, setReadonly, shouldReconnectWithoutProxy, skip, 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, getActiveStreamingResult, getCalendar, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReadonly, getServerData, getServerThreadId, getServerVersion, getUrlParser, getUsername, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setMoreResults, setProxy, setReadonly, shouldReconnectWithoutProxy, skip, 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

#### prepare

    public PrepareResult prepare(String sql)
                          throws QueryException

Prepare query on server side. Will permit to know the parameter number of the query, and permit to send only the data on next results.

Specified by:
  `prepare` in interface `Protocol`
Parameters:
  `sql` - the query
Returns:
  state of current connection when creating this prepareStatement
Throws:
  `QueryException` - if any error occur on connection.

#### prepare

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

Prepare query on server side. Will permit to know the parameter number of the query, and permit to send only the data on next results. For failover, two additional information are in the resultset object : - current connection : Since server maintain a state of this prepare statement, all query will be executed on this particular connection. - executeOnMaster : state of current connection when creating this prepareStatement (if was on master, will only be executed on master. If was on a slave, can be execute temporary on master, but we keep this flag, so when a slave is connected back to relaunch this query on slave)

Specified by:
  `prepare` in interface `Protocol`
Parameters:
  `sql` - the query
  `forceNew` - do not use prepared in cache in present.
  `executeOnMaster` - state of current connection when creating this prepareStatement
Returns:
  a PrepareResult object that contain prepare result information.
Throws:
  `QueryException` - if any error occur on connection.

#### 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`
Overrides:
  `hasMoreResults` in class `AbstractConnectProtocol`

#### 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 void executePreparedQueryAfterFailover(PrepareResult oldPrepareResult,
                                                  ExecutionResult executionResult,
                                                  String sql,
                                                  ParameterHolder[] parameters,
                                                  MariaDbType[] parameterTypeHeader,
                                                  int resultSetScrollType)
                                           throws QueryException

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

#### executePreparedQuery

    public void executePreparedQuery(PrepareResult prepareResult,
                                     ExecutionResult executionResult,
                                     String sql,
                                     ParameterHolder[] parameters,
                                     MariaDbType[] parameterTypeHeader,
                                     int resultSetScrollType)
                              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 void getMoreResults(ExecutionResult executionResult)
                        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`

#### fetchActiveStreamingResult

    public void fetchActiveStreamingResult()
                                    throws SQLException

Close active result.

Throws:
  `SQLException` - if socket error.

#### prepareStatementCache

    public PrepareStatementCache prepareStatementCache()

Specified by:
  `prepareStatementCache` in interface `Protocol`

#### executeQuery

    public void executeQuery(String sql)
                      throws QueryException

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

#### executeQuery

    public void executeQuery(ExecutionResult executionResult,
                             String sql,
                             int resultSetScrollType)
                      throws QueryException

Execute query.

Specified by:
  `executeQuery` in interface `Protocol`
Parameters:
  `sql` - the query to executeInternal
  `resultSetScrollType` - resultSetScrollType
Throws:
  `QueryException` - exception

#### executeQueries

    public void executeQueries(ExecutionResult executionResult,
                               List<String> queries,
                               int resultSetScrollType)
                        throws QueryException

Execute list of queries not rewritable.

Specified by:
  `executeQueries` in interface `Protocol`
Parameters:
  `queries` - list of queryes
  `resultSetScrollType` - resultSetScrollType
Throws:
  `QueryException` - exception

#### executeQueries

    public void executeQueries(ExecutionResult executionResult,
                               List<String> queryParts,
                               List<ParameterHolder[]> parameterList,
                               int resultSetScrollType,
                               boolean isRewritable)
                        throws QueryException

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

Specified by:
  `executeQueries` in interface `Protocol`
Parameters:
  `executionResult` - result
  `queryParts` - query part
  `parameterList` - parameters
  `resultSetScrollType` - resultsetScroll type
  `isRewritable` - is rewritable flag
Throws:
  `QueryException` - exception

#### executeQueriesRewrite

    public void executeQueriesRewrite(ExecutionResult executionResult,
                                      List<String> queries,
                                      int resultSetScrollType,
                                      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:
  `executeQueriesRewrite` in interface `Protocol`
Parameters:
  `queries` - list of queryes
  `resultSetScrollType` - resultSetScrollType
  `isRewritable` - is rewritable flag
  `rewriteOffset` - rewrite offset
Throws:
  `QueryException` - exception

#### getResult

    public void getResult(ExecutionResult executionResult,
                          int resultSetScrollType,
                          boolean binaryProtocol)
                   throws QueryException

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

#### prologProxy

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

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

#### prolog

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

Preparation before command.

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