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, checkCallableResultSet, connected, currentHost, database, dataTypeMappingFlags, explicitClosed, hasWarnings, lock, moreResults, moreResultsTypeBinary, options, packetFetcher, proxy, readOnly, serverPrepareStatementCache, serverStatus, serverThreadId, socket, urlParser, writer`

### Constructor Summary

Constructors
Constructor and Description
`AbstractQueryProtocol(UrlParser urlParser, ReentrantLock lock)` Get a protocol instance.

### Method Summary

All Methods Instance Methods Concrete Methods
`ServerPrepareResult` `addPrepareInCache(String key, ServerPrepareResult serverPrepareResult)`
`void` `cancelCurrentQuery()` Cancels the current query - clones the current protocol and executes a query using the new connection.
`void` `closeExplicit()`
`void` `executeBatch(boolean mustExecuteOnMaster, ExecutionResult executionResult, List<String> queries, int resultSetScrollType)` Execute list of queries not rewritable.
`void` `executeBatchMulti(boolean mustExecuteOnMaster, ExecutionResult executionResult, ClientPrepareResult clientPrepareResult, List<ParameterHolder[]> parametersList, int resultSetScrollType)` Execute clientPrepareQuery batch.
`void` `executeBatchMultiple(boolean mustExecuteOnMaster, ExecutionResult executionResult, List<String> queries, int resultSetScrollType)` Execute list of queries.
`void` `executeBatchRewrite(boolean mustExecuteOnMaster, ExecutionResult executionResult, ClientPrepareResult prepareResult, List<ParameterHolder[]> parameterList, int resultSetScrollType, boolean rewriteValues)` Specific execution for batch rewrite that has specific query for memory.
`void` `executePreparedQuery(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, ParameterHolder[] parameters, int resultSetScrollType)` Execute a query that is already prepared.
`void` `executeQuery(boolean mustExecuteOnMaster, ExecutionResult executionResult, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters, int resultSetScrollType)` Execute a unique clientPrepareQuery.
`void` `executeQuery(boolean mustExecuteOnMaster, ExecutionResult executionResult, String sql, int resultSetScrollType)` Execute query directly to outputStream.
`void` `executeQuery(String sql)`
`void` `fetchActiveStreamingResult()` Close active result.
`boolean` `forceReleasePrepareStatement(int statementId)` Force release of prepare statement that are not used.
`void` `forceReleaseWaitingPrepareStatement()` Force release of prepare statement that are not used.
`boolean` `getAutocommit()`
`int` `getMaxRows()`
`void` `getMoreResults(ExecutionResult executionResult)`
`ServerPrepareResult` `getPrepareStatementFromCache(String key)` Retrieve prepare result from cache.
`ExecutionResult` `getResult(ExecutionResult executionResult, int resultSetScrollType, boolean binaryProtocol, boolean loadAllResults)`
`int` `getTimeout()` Returns the connection timeout in milliseconds.
`int` `getTransactionIsolationLevel()`
`boolean` `hasMoreResults()`
`boolean` `inTransaction()`
`boolean` `ping()`
`ServerPrepareResult` `prepare(String sql, boolean executeOnMaster)` Prepare query on server side.
`ServerPrepareResult` `prepareAndExecute(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, String sql, ParameterHolder[] parameters, int resultSetScrollType)` Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.
`ServerPrepareResult` `prepareAndExecutes(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, String sql, List<ParameterHolder[]> parametersList, int resultSetScrollType)` Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.
`void` `prolog(ExecutionResult executionResult, int maxRows, boolean hasProxy, MariaDbConnection connection, Statement statement)` Preparation before command.
`void` `prologProxy(ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, int maxRows, boolean hasProxy, MariaDbConnection connection, Statement statement)`
`void` `releasePrepareStatement(ServerPrepareResult serverPrepareResult)` 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

`changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, close, connect, connectWithoutProxy, enabledSslCipherSuites, enabledSslProtocolSuites, getActiveStreamingResult, getCalendar, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPacketFetcher, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReadonly, getServerData, getServerThreadId, getServerVersion, getUrlParser, getUsername, getWriter, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, releaseWriterBuffer, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setMoreResults, setProxy, setReadonly, shouldReconnectWithoutProxy, skip, skipEofPacket, 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

`changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, connect, connectWithoutProxy, getActiveStreamingResult, getCalendar, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPacketFetcher, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReadonly, getServerData, getServerThreadId, getServerVersion, getUrlParser, getUsername, getWriter, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, releaseWriterBuffer, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setMoreResults, setProxy, setReadonly, shouldReconnectWithoutProxy, skip, skipEofPacket, 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

#### 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(boolean mustExecuteOnMaster,
                             ExecutionResult executionResult,
                             String sql,
                             int resultSetScrollType)
                      throws QueryException

Execute query directly to outputStream.

Specified by:
  `executeQuery` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - was intended to be launched on master connection
  `executionResult` - result
  `sql` - the query to executeInternal
  `resultSetScrollType` - resultSetScrollType
Throws:
  `QueryException` - exception

#### executeQuery

    public void executeQuery(boolean mustExecuteOnMaster,
                             ExecutionResult executionResult,
                             ClientPrepareResult clientPrepareResult,
                             ParameterHolder[] parameters,
                             int resultSetScrollType)
                      throws QueryException

Execute a unique clientPrepareQuery.

Specified by:
  `executeQuery` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - was intended to be launched on master connection
  `executionResult` - result
  `clientPrepareResult` - clientPrepareResult
  `parameters` - parameters
  `resultSetScrollType` - resultsetScroll type
Throws:
  `QueryException` - exception

#### executeBatchMulti

    public void executeBatchMulti(boolean mustExecuteOnMaster,
                                  ExecutionResult executionResult,
                                  ClientPrepareResult clientPrepareResult,
                                  List<ParameterHolder[]> parametersList,
                                  int resultSetScrollType)
                           throws QueryException

Execute clientPrepareQuery batch.

Specified by:
  `executeBatchMulti` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - was intended to be launched on master connection
  `executionResult` - result
  `clientPrepareResult` - ClientPrepareResult
  `parametersList` - List of parameters
  `resultSetScrollType` - resultsetScroll type
Throws:
  `QueryException` - exception

#### executeBatch

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

Execute list of queries not rewritable.

Specified by:
  `executeBatch` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - was intended to be launched on master connection
  `queries` - list of queries
  `resultSetScrollType` - resultSetScrollType
Throws:
  `QueryException` - exception

#### prepare

    public ServerPrepareResult prepare(String sql,
                                       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
  `executeOnMaster` - state of current connection when creating this prepareStatement
Returns:
  a ServerPrepareResult object that contain prepare result information.
Throws:
  `QueryException` - if any error occur on connection.

#### executeBatchMultiple

    public void executeBatchMultiple(boolean mustExecuteOnMaster,
                                     ExecutionResult executionResult,
                                     List<String> queries,
                                     int resultSetScrollType)
                              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:
  `executeBatchMultiple` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - was intended to be launched on master connection
  `queries` - list of queryes
  `resultSetScrollType` - resultSetScrollType
Throws:
  `QueryException` - exception

#### executeBatchRewrite

    public void executeBatchRewrite(boolean mustExecuteOnMaster,
                                    ExecutionResult executionResult,
                                    ClientPrepareResult prepareResult,
                                    List<ParameterHolder[]> parameterList,
                                    int resultSetScrollType,
                                    boolean rewriteValues)
                             throws QueryException

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

Specified by:
  `executeBatchRewrite` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - was intended to be launched on master connection
  `executionResult` - result
  `prepareResult` - prepareResult
  `parameterList` - parameters
  `resultSetScrollType` - resultsetScroll type
  `rewriteValues` - is rewritable flag
Throws:
  `QueryException` - exception

#### prepareAndExecutes

    public ServerPrepareResult prepareAndExecutes(boolean mustExecuteOnMaster,
                                                  ServerPrepareResult serverPrepareResult,
                                                  ExecutionResult executionResult,
                                                  String sql,
                                                  List<ParameterHolder[]> parametersList,
                                                  int resultSetScrollType)
                                           throws QueryException

Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.

Specified by:
  `prepareAndExecutes` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - must normally be executed on master connection
  `serverPrepareResult` - prepare result. can be null if not prepared.
  `executionResult` - execution results
  `sql` - sql query if needed to be prepared
  `parametersList` - parameter list
  `resultSetScrollType` - result scroll type
Returns:
  Prepare result
Throws:
  `QueryException` - if parameter error or connection error occur.

#### prepareAndExecute

    public ServerPrepareResult prepareAndExecute(boolean mustExecuteOnMaster,
                                                 ServerPrepareResult serverPrepareResult,
                                                 ExecutionResult executionResult,
                                                 String sql,
                                                 ParameterHolder[] parameters,
                                                 int resultSetScrollType)
                                          throws QueryException

Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.

Specified by:
  `prepareAndExecute` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - must normally be executed on master connection
  `serverPrepareResult` - prepare result. can be null if not prepared.
  `executionResult` - execution results
  `sql` - sql query if needed to be prepared
  `parameters` - parameters
  `resultSetScrollType` - result scroll type
Returns:
  Prepare result
Throws:
  `QueryException` - if parameter error or connection error occur.

#### executePreparedQuery

    public void executePreparedQuery(boolean mustExecuteOnMaster,
                                     ServerPrepareResult serverPrepareResult,
                                     ExecutionResult executionResult,
                                     ParameterHolder[] parameters,
                                     int resultSetScrollType)
                              throws QueryException

Execute a query that is already prepared.

Specified by:
  `executePreparedQuery` in interface `Protocol`
Parameters:
  `mustExecuteOnMaster` - must execute on master
  `serverPrepareResult` - prepare result
  `executionResult` - execution result
  `parameters` - parameters
  `resultSetScrollType` - scroll type.
Throws:
  `QueryException` - exception

#### rollback

    public void rollback()
                  throws QueryException

Rollback transaction.

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

#### forceReleasePrepareStatement

    public boolean 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.
Returns:
  true if successfully released
Throws:
  `QueryException` - if connection exception.

#### forceReleaseWaitingPrepareStatement

    public void forceReleaseWaitingPrepareStatement()
                                             throws QueryException

Force release of prepare statement that are not used. This permit to deallocate a statement that cannot be release due to multi-thread use.

Specified by:
  `forceReleaseWaitingPrepareStatement` in interface `Protocol`
Throws:
  `QueryException` - if connection occur

#### ping

    public boolean ping()
                 throws QueryException

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

#### setCatalog

    public void setCatalog(String database)
                    throws QueryException

Specified by:
  `setCatalog` 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

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

#### releasePrepareStatement

    public void releasePrepareStatement(ServerPrepareResult serverPrepareResult)
                                 throws QueryException

Deallocate prepare statement if not used anymore.

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

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

#### getResult

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

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

#### prologProxy

    public void prologProxy(ServerPrepareResult serverPrepareResult,
                            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.

#### addPrepareInCache

    public ServerPrepareResult addPrepareInCache(String key,
                                                 ServerPrepareResult serverPrepareResult)

Specified by:
  `addPrepareInCache` in interface `Protocol`

#### getPrepareStatementFromCache

    public ServerPrepareResult getPrepareStatementFromCache(String key)

Retrieve prepare result from cache.

Specified by:
  `getPrepareStatementFromCache` in interface `Protocol`
Parameters:
  `key` - cache key.
Returns:
  serverPrepareResult if found, null otherwise.