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
-
Field Summary
Fields inherited from class AbstractConnectProtocol
activeStreamingResult, autoIncrementIncrement, CHECK_GALERA_STATE_QUERY, connected, database, eofDeprecated, exceptionFactory, explicitClosed, galeraAllowedStates, hasWarnings, lock, options, proxy, reader, readOnly, serverCapabilities, serverPrepareStatementCache, serverStatus, serverThreadId, socket, socketTimeout, traceCache, urlParser, writer -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels the current query - clones the current protocol and executes a query using the new connection.voidbooleanexecuteBatchClient(boolean mustExecuteOnMaster, Results results, ClientPrepareResult prepareResult, List<ParameterHolder[]> parametersList) Execute clientPrepareQuery batch.booleanexecuteBatchServer(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, Results results, String sql, List<ParameterHolder[]> parametersList) Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.voidexecuteBatchStmt(boolean mustExecuteOnMaster, Results results, List<String> queries) Execute batch from Statement.executeBatch().voidexecutePreparedQuery(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, Results results, ParameterHolder[] parameters) Execute a query that is already prepared.voidexecuteQuery(boolean mustExecuteOnMaster, Results results, String sql) Execute query directly to outputStream.voidexecuteQuery(boolean mustExecuteOnMaster, Results results, String sql, Charset charset) voidexecuteQuery(boolean mustExecuteOnMaster, Results results, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters) Execute a unique clientPrepareQuery.voidexecuteQuery(boolean mustExecuteOnMaster, Results results, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters, int queryTimeout) Execute a unique clientPrepareQuery.voidexecuteQuery(String sql) Execute internal query.booleanforceReleasePrepareStatement(int statementId) Force release of prepare statement that are not used.voidForce release of prepare statement that are not used.booleanGet current autocommit status.intGet current auto increment increment.longvoidintReturns the connection timeout in milliseconds.inthandleIoException(Exception initialException) Handle IoException (reconnect if Exception is due to having send too much data, making server close the connection.voidbooleanbooleanbooleanisValid(int timeout) Check that connection is valid.booleanping()Prepare query on server side.voidprolog(long maxRows, boolean hasProxy, MariaDbConnection connection, MariaDbStatement statement) Preparation before command.voidprologProxy(ServerPrepareResult serverPrepareResult, long maxRows, boolean hasProxy, MariaDbConnection connection, MariaDbStatement statement) putInCache(String key, ServerPrepareResult serverPrepareResult) voidreleasePrepareStatement(ServerPrepareResult serverPrepareResult) Deallocate prepare statement if not used anymore.voidreset()Reset connection state.voidvoidresetStateAfterFailover(long maxRows, int transactionIsolationLevel, String database, boolean autocommit) Set current state after a failover.voidrollback()Rollback transaction.voidsetActiveFutureTask(FutureTask activeFutureTask) voidsetCatalog(String database) voidsetLocalInfileInputStream(InputStream inputStream) voidsetMaxRows(long max) voidsetReadonly(boolean readOnly) Puts this connection in read-only / read-write modevoidsetTimeout(int timeout) Sets the connection timeout.voidsetTransactionIsolation(int level) Set transaction isolation.voidThrow TimeoutException if timeout has been reached.Methods inherited from class AbstractConnectProtocol
abort, changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, connect, connectWithoutProxy, destroySocket, getActiveStreamingResult, getDatabase, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPatchServerVersion, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReader, getReadonly, getServerThreadId, getServerVersion, getSocket, getSocketIp, getTimeZone, getTraces, getUrlParser, getUsername, hasMoreResults, hasWarnings, isClosed, isConnected, isEofDeprecated, isExplicitClosed, isMasterConnection, isServerMariaDb, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, readPipelineCheckMaster, removeActiveStreamingResult, removeHasMoreResults, sessionStateAware, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setProxy, setServerStatus, shouldReconnectWithoutProxy, skip, skipEofPacket, versionGreaterOrEqualMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Protocol
abort, changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, connect, connectWithoutProxy, getActiveStreamingResult, getDatabase, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPatchServerVersion, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReader, getReadonly, getServerThreadId, getServerVersion, getSocket, getTimeZone, getTraces, getUrlParser, getUsername, hasMoreResults, hasWarnings, isClosed, isConnected, isEofDeprecated, isExplicitClosed, isMasterConnection, isServerMariaDb, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, removeActiveStreamingResult, removeHasMoreResults, sessionStateAware, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setProxy, setServerStatus, shouldReconnectWithoutProxy, skip, skipEofPacket, versionGreaterOrEqual
-
Method Details
-
reset
Reset connection state.- Transaction will be rollback
- transaction isolation will be reset
- user variables will be removed
- sessions variables will be reset to global values
- Specified by:
resetin interfaceProtocol- Throws:
SQLException- if command failed
-
executeQuery
Execute internal query.!! will not support multi values queries !!
- Specified by:
executeQueryin interfaceProtocol- Specified by:
executeQueryin classAbstractConnectProtocol- Parameters:
sql- sql- Throws:
SQLException- in any exception occur
-
executeQuery
public void executeQuery(boolean mustExecuteOnMaster, Results results, String sql) throws SQLException Execute query directly to outputStream.- Specified by:
executeQueryin interfaceProtocol- Parameters:
mustExecuteOnMaster- was intended to be launched on master connectionresults- resultsql- the query to executeInternal- Throws:
SQLException- exception
-
executeQuery
public void executeQuery(boolean mustExecuteOnMaster, Results results, String sql, Charset charset) throws SQLException - Specified by:
executeQueryin interfaceProtocol- Throws:
SQLException
-
executeQuery
public void executeQuery(boolean mustExecuteOnMaster, Results results, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters) throws SQLException Execute a unique clientPrepareQuery.- Specified by:
executeQueryin interfaceProtocol- Parameters:
mustExecuteOnMaster- was intended to be launched on master connectionresults- resultsclientPrepareResult- clientPrepareResultparameters- parameters- Throws:
SQLException- exception
-
executeQuery
public void executeQuery(boolean mustExecuteOnMaster, Results results, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters, int queryTimeout) throws SQLException Execute a unique clientPrepareQuery.- Specified by:
executeQueryin interfaceProtocol- Parameters:
mustExecuteOnMaster- was intended to be launched on master connectionresults- resultsclientPrepareResult- clientPrepareResultparameters- parametersqueryTimeout- if timeout is set and must use max_statement_time- Throws:
SQLException- exception
-
executeBatchClient
public boolean executeBatchClient(boolean mustExecuteOnMaster, Results results, ClientPrepareResult prepareResult, List<ParameterHolder[]> parametersList) throws SQLException Execute clientPrepareQuery batch.- Specified by:
executeBatchClientin interfaceProtocol- Parameters:
mustExecuteOnMaster- was intended to be launched on master connectionresults- resultsprepareResult- ClientPrepareResultparametersList- List of parameters- Throws:
SQLException- exception
-
executeBatchStmt
public void executeBatchStmt(boolean mustExecuteOnMaster, Results results, List<String> queries) throws SQLException Execute batch from Statement.executeBatch().- Specified by:
executeBatchStmtin interfaceProtocol- Parameters:
mustExecuteOnMaster- was intended to be launched on master connectionresults- resultsqueries- queries- Throws:
SQLException- if any exception occur
-
prepare
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 result-set 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 replica, can be execute temporary on master, but we keep this flag, so when a replica is connected back to relaunch this query on replica)
- Specified by:
preparein interfaceProtocol- Parameters:
sql- the queryexecuteOnMaster- state of current connection when creating this prepareStatement- Returns:
- a ServerPrepareResult object that contain prepare result information.
- Throws:
SQLException- if any error occur on connection.
-
executeBatchServer
public boolean executeBatchServer(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, Results results, String sql, List<ParameterHolder[]> parametersList) throws SQLException Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.- Specified by:
executeBatchServerin interfaceProtocol- Parameters:
mustExecuteOnMaster- must normally be executed on master connectionserverPrepareResult- prepare result. can be null if not prepared.results- execution resultssql- sql query if needed to be preparedparametersList- parameter list- Returns:
- executed
- Throws:
SQLException- if parameter error or connection error occur.
-
executePreparedQuery
public void executePreparedQuery(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, Results results, ParameterHolder[] parameters) throws SQLException Execute a query that is already prepared.- Specified by:
executePreparedQueryin interfaceProtocol- Parameters:
mustExecuteOnMaster- must execute on masterserverPrepareResult- prepare resultresults- execution resultparameters- parameters- Throws:
SQLException- exception
-
rollback
Rollback transaction.- Specified by:
rollbackin interfaceProtocol- Throws:
SQLException
-
forceReleasePrepareStatement
Force release of prepare statement that are not used. This method will be call when adding a new prepare statement in cache, so the packet can be send to server without problem.- Specified by:
forceReleasePrepareStatementin interfaceProtocol- Parameters:
statementId- prepared statement Id to remove.- Returns:
- true if successfully released
- Throws:
SQLException- if connection exception.
-
forceReleaseWaitingPrepareStatement
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:
forceReleaseWaitingPrepareStatementin interfaceProtocol- Throws:
SQLException- if connection occur
-
ping
- Specified by:
pingin interfaceProtocol- Throws:
SQLException
-
isValid
Check that connection is valid. !! careful, timeout is in milliseconds, connection.isValid(timeout) is in seconds !!- Specified by:
isValidin interfaceProtocol- Parameters:
timeout- timeout in milliseconds- Returns:
- true is valid
- Throws:
SQLException- if any error occur
-
getCatalog
- Specified by:
getCatalogin interfaceProtocol- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalogin interfaceProtocol- Throws:
SQLException
-
resetDatabase
- Specified by:
resetDatabasein interfaceProtocol- Throws:
SQLException
-
cancelCurrentQuery
Cancels the current query - clones the current protocol and executes a query using the new connection.- Specified by:
cancelCurrentQueryin interfaceProtocol- Throws:
SQLException- never thrown
-
getAutocommit
public boolean getAutocommit()Get current autocommit status.- Specified by:
getAutocommitin interfaceProtocol- Returns:
- autocommit status
-
inTransaction
public boolean inTransaction()- Specified by:
inTransactionin interfaceProtocol
-
closeExplicit
public void closeExplicit()- Specified by:
closeExplicitin interfaceProtocol
-
releasePrepareStatement
Deallocate prepare statement if not used anymore.- Specified by:
releasePrepareStatementin interfaceProtocol- Parameters:
serverPrepareResult- allocation result- Throws:
SQLException- if de-allocation failed.
-
getMaxRows
public long getMaxRows()- Specified by:
getMaxRowsin interfaceProtocol
-
setMaxRows
- Specified by:
setMaxRowsin interfaceProtocol- Throws:
SQLException
-
setLocalInfileInputStream
- Specified by:
setLocalInfileInputStreamin interfaceProtocol
-
getTimeout
public int getTimeout()Returns the connection timeout in milliseconds.- Specified by:
getTimeoutin interfaceProtocol- Returns:
- the connection timeout in milliseconds.
-
setTimeout
Sets the connection timeout.- Specified by:
setTimeoutin interfaceProtocol- Parameters:
timeout- the timeout, in milliseconds- Throws:
SocketException- if there is an error in the underlying protocol, such as a TCP error.
-
setReadonly
Puts this connection in read-only / read-write mode- Specified by:
setReadonlyin interfaceProtocol- Parameters:
readOnly- true enables read-only mode; false disables it- Throws:
SQLException- If socket error.
-
setTransactionIsolation
Set transaction isolation.- Specified by:
setTransactionIsolationin interfaceProtocol- Parameters:
level- transaction level.- Throws:
SQLException- if transaction level is unknown
-
getTransactionIsolationLevel
public int getTransactionIsolationLevel()- Specified by:
getTransactionIsolationLevelin interfaceProtocol
-
getResult
- Specified by:
getResultin interfaceProtocol- Throws:
SQLException
-
getAutoIncrementIncrement
Get current auto increment increment. *** no lock needed ****- Specified by:
getAutoIncrementIncrementin interfaceProtocol- Returns:
- auto increment increment.
- Throws:
SQLException- if cannot retrieve auto increment value
-
prologProxy
public void prologProxy(ServerPrepareResult serverPrepareResult, long maxRows, boolean hasProxy, MariaDbConnection connection, MariaDbStatement statement) throws SQLException - Specified by:
prologProxyin interfaceProtocol- Throws:
SQLException
-
prolog
public void prolog(long maxRows, boolean hasProxy, MariaDbConnection connection, MariaDbStatement statement) throws SQLException Preparation before command.- Specified by:
prologin interfaceProtocol- Parameters:
maxRows- query max rowshasProxy- has proxyconnection- current connectionstatement- current statement- Throws:
SQLException- if any error occur.
-
putInCache
- Specified by:
putInCachein interfaceProtocol
-
resetStateAfterFailover
public void resetStateAfterFailover(long maxRows, int transactionIsolationLevel, String database, boolean autocommit) throws SQLException Set current state after a failover.- Specified by:
resetStateAfterFailoverin interfaceProtocol- Parameters:
maxRows- current Max rowstransactionIsolationLevel- current transactionIsolationLeveldatabase- current databaseautocommit- current autocommit state- Throws:
SQLException- if any error occur.
-
handleIoException
Handle IoException (reconnect if Exception is due to having send too much data, making server close the connection.There is 3 kind of IOException :
- MaxAllowedPacketException : without need of reconnect : thrown when driver don't send packet that would have been too big then error is not a CONNECTION_EXCEPTION
- packets size is greater than max_allowed_packet (can be checked with writer.isAllowedCmdLength()). Need to reconnect
- unknown IO error throw a CONNECTION_EXCEPTION
- Specified by:
handleIoExceptionin interfaceProtocol- Parameters:
initialException- initial Io error- Returns:
- the resulting error to return to client.
-
setActiveFutureTask
- Specified by:
setActiveFutureTaskin interfaceProtocol
-
interrupt
-
isInterrupted
public boolean isInterrupted()- Specified by:
isInterruptedin interfaceProtocol
-
stopIfInterrupted
Throw TimeoutException if timeout has been reached.- Specified by:
stopIfInterruptedin interfaceProtocol- Throws:
SQLTimeoutException- to indicate timeout exception.
-