public class AbstractQueryProtocol extends AbstractConnectProtocol implements Protocol
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.FutureTask |
activeFutureTask |
private boolean |
interrupted |
private java.io.InputStream |
localInfileInputStream |
private static Logger |
logger |
private LogQueryTool |
logQuery |
private long |
maxRows |
static java.util.concurrent.ThreadPoolExecutor |
readScheduler |
private int |
statementIdToRelease |
private int |
transactionIsolationLevel |
activeStreamingResult, autoIncrementIncrement, connected, currentHost, database, dataTypeMappingFlags, eofDeprecated, explicitClosed, hasWarnings, IS_MASTER_QUERY, lock, options, proxy, reader, readOnly, serverCapabilities, serverPrepareStatementCache, serverStatus, serverThreadId, SESSION_QUERY, socket, urlParser, writer
Constructor and Description |
---|
AbstractQueryProtocol(UrlParser urlParser,
java.util.concurrent.locks.ReentrantLock lock)
Get a protocol instance.
|
Modifier and Type | Method and Description |
---|---|
ServerPrepareResult |
addPrepareInCache(java.lang.String key,
ServerPrepareResult serverPrepareResult) |
void |
cancelCurrentQuery()
Cancels the current query - clones the current protocol and executes a query using the new connection.
|
private void |
checkClose() |
void |
closeExplicit() |
private void |
cmdPrologue() |
void |
executeBatch(boolean mustExecuteOnMaster,
Results results,
java.util.List<java.lang.String> queries)
Execute list of queries not rewritable.
|
void |
executeBatchMulti(boolean mustExecuteOnMaster,
Results results,
ClientPrepareResult clientPrepareResult,
java.util.List<ParameterHolder[]> parametersList)
Execute clientPrepareQuery batch.
|
void |
executeBatchMultiple(boolean mustExecuteOnMaster,
Results results,
java.util.List<java.lang.String> queries)
Execute list of queries.
|
void |
executeBatchRewrite(boolean mustExecuteOnMaster,
Results results,
ClientPrepareResult prepareResult,
java.util.List<ParameterHolder[]> parameterList,
boolean rewriteValues)
Specific execution for batch rewrite that has specific query for memory.
|
void |
executePreparedQuery(boolean mustExecuteOnMaster,
ServerPrepareResult serverPrepareResult,
Results results,
ParameterHolder[] parameters)
Execute a query that is already prepared.
|
void |
executeQuery(boolean mustExecuteOnMaster,
Results results,
ClientPrepareResult clientPrepareResult,
ParameterHolder[] parameters)
Execute a unique clientPrepareQuery.
|
void |
executeQuery(boolean mustExecuteOnMaster,
Results results,
ClientPrepareResult clientPrepareResult,
ParameterHolder[] parameters,
int queryTimeout)
Execute a unique clientPrepareQuery.
|
void |
executeQuery(boolean mustExecuteOnMaster,
Results results,
java.lang.String sql)
Execute query directly to outputStream.
|
void |
executeQuery(boolean mustExecuteOnMaster,
Results results,
java.lang.String sql,
java.nio.charset.Charset charset) |
void |
executeQuery(java.lang.String sql)
Execute internal query.
|
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()
Get current autocommit status.
|
int |
getAutoIncrementIncrement()
Get current auto increment increment.
|
long |
getMaxRows() |
void |
getResult(Results results) |
int |
getTimeout()
Returns the connection timeout in milliseconds.
|
int |
getTransactionIsolationLevel() |
java.sql.SQLException |
handleIoException(java.io.IOException initialException)
Handle IoException (reconnect if Exception is due to having send too much data,
making server close the connection.
|
private void |
handleStateChange(Buffer buf,
Results results) |
boolean |
inTransaction() |
boolean |
isInterrupted() |
boolean |
ping() |
ServerPrepareResult |
prepare(java.lang.String sql,
boolean executeOnMaster)
Prepare query on server side.
|
ServerPrepareResult |
prepareAndExecute(boolean mustExecuteOnMaster,
ServerPrepareResult serverPrepareResult,
Results results,
java.lang.String sql,
ParameterHolder[] parameters)
Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.
|
ServerPrepareResult |
prepareAndExecutes(boolean mustExecuteOnMaster,
ServerPrepareResult serverPrepareResult,
Results results,
java.lang.String sql,
java.util.List<ParameterHolder[]> parametersList)
Execute Prepare if needed, and execute COM_STMT_EXECUTE queries in batch.
|
void |
prolog(long maxRows,
boolean hasProxy,
MariaDbConnection connection,
MariaDbStatement statement)
Preparation before command.
|
void |
prologProxy(ServerPrepareResult serverPrepareResult,
long maxRows,
boolean hasProxy,
MariaDbConnection connection,
MariaDbStatement statement) |
java.sql.SQLException |
readErrorPacket(Buffer buffer,
Results results)
Read ERR_Packet.
|
void |
readLocalInfilePacket(Buffer buffer,
Results results)
Read Local_infile Packet.
|
void |
readOkPacket(Buffer buffer,
Results results)
Read OK_Packet.
|
void |
readPacket(Results results)
Read server response packet.
|
void |
readResultSet(Buffer buffer,
Results results)
Read ResultSet Packet.
|
void |
releasePrepareStatement(ServerPrepareResult serverPrepareResult)
Deallocate prepare statement if not used anymore.
|
void |
resetStateAfterFailover(long maxRows,
int transactionIsolationLevel,
java.lang.String database,
boolean autocommit)
Set current state after a failover.
|
void |
rollback()
Rollback transaction.
|
void |
setActiveFutureTask(java.util.concurrent.FutureTask activeFutureTask) |
void |
setCatalog(java.lang.String database) |
void |
setInternalMaxRows(long max)
Set max row retuen by a statement.
|
void |
setLocalInfileInputStream(java.io.InputStream inputStream) |
void |
setMaxRows(long max) |
void |
setTimeout(int timeout)
Sets the connection timeout.
|
void |
setTransactionIsolation(int level)
Set transaction isolation.
|
void |
stopIfInterrupted()
Throw TimeoutException if timeout has been reached.
|
changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, close, connect, connectWithoutProxy, enabledSslCipherSuites, enabledSslProtocolSuites, getActiveStreamingResult, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReader, getReadonly, getServerData, getServerThreadId, getServerVersion, getTimeZone, getTraces, getUrlParser, getUsername, getWriter, hasMoreResults, hasWarnings, isClosed, isConnected, isEofDeprecated, isExplicitClosed, isMasterConnection, isServerMariaDb, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, readPipelineCheckMaster, removeActiveStreamingResult, removeHasMoreResults, sendPipelineCheckMaster, sessionStateAware, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setProxy, setReadonly, setServerStatus, shouldReconnectWithoutProxy, skip, skipEofPacket, versionGreaterOrEqual
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, connect, connectWithoutProxy, getActiveStreamingResult, getDatabase, getDataTypeMappingFlags, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPassword, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReader, getReadonly, getServerThreadId, getServerVersion, getTimeZone, getTraces, getUrlParser, getUsername, getWriter, hasMoreResults, hasWarnings, isClosed, isConnected, isEofDeprecated, isExplicitClosed, isMasterConnection, isServerMariaDb, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, removeActiveStreamingResult, removeHasMoreResults, sessionStateAware, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setProxy, setReadonly, setServerStatus, shouldReconnectWithoutProxy, skip, skipEofPacket, versionGreaterOrEqual
public static java.util.concurrent.ThreadPoolExecutor readScheduler
private static Logger logger
private int transactionIsolationLevel
private java.io.InputStream localInfileInputStream
private long maxRows
private volatile int statementIdToRelease
private java.util.concurrent.FutureTask activeFutureTask
private LogQueryTool logQuery
private boolean interrupted
public AbstractQueryProtocol(UrlParser urlParser, java.util.concurrent.locks.ReentrantLock lock)
urlParser
- connection URL infoslock
- the lock for thread synchronisationpublic void executeQuery(java.lang.String sql) throws java.sql.SQLException
!! will not support multi values queries !!
executeQuery
in interface Protocol
executeQuery
in class AbstractConnectProtocol
sql
- sqljava.sql.SQLException
- in any exception occurpublic void executeQuery(boolean mustExecuteOnMaster, Results results, java.lang.String sql) throws java.sql.SQLException
executeQuery
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- resultsql
- the query to executeInternaljava.sql.SQLException
- exceptionpublic void executeQuery(boolean mustExecuteOnMaster, Results results, java.lang.String sql, java.nio.charset.Charset charset) throws java.sql.SQLException
executeQuery
in interface Protocol
java.sql.SQLException
public void executeQuery(boolean mustExecuteOnMaster, Results results, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters) throws java.sql.SQLException
executeQuery
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- resultsclientPrepareResult
- clientPrepareResultparameters
- parametersjava.sql.SQLException
- exceptionpublic void executeQuery(boolean mustExecuteOnMaster, Results results, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters, int queryTimeout) throws java.sql.SQLException
executeQuery
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- resultsclientPrepareResult
- clientPrepareResultparameters
- parametersqueryTimeout
- if timeout is set and must use max_statement_timejava.sql.SQLException
- exceptionpublic void executeBatchMulti(boolean mustExecuteOnMaster, Results results, ClientPrepareResult clientPrepareResult, java.util.List<ParameterHolder[]> parametersList) throws java.sql.SQLException
executeBatchMulti
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- resultsclientPrepareResult
- ClientPrepareResultparametersList
- List of parametersjava.sql.SQLException
- exceptionpublic void executeBatch(boolean mustExecuteOnMaster, Results results, java.util.List<java.lang.String> queries) throws java.sql.SQLException
executeBatch
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- result objectqueries
- list of queriesjava.sql.SQLException
- exceptionpublic ServerPrepareResult prepare(java.lang.String sql, boolean executeOnMaster) throws java.sql.SQLException
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)
public void executeBatchMultiple(boolean mustExecuteOnMaster, Results results, java.util.List<java.lang.String> queries) throws java.sql.SQLException
executeBatchMultiple
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- result objectqueries
- list of queriesjava.sql.SQLException
- exceptionpublic void executeBatchRewrite(boolean mustExecuteOnMaster, Results results, ClientPrepareResult prepareResult, java.util.List<ParameterHolder[]> parameterList, boolean rewriteValues) throws java.sql.SQLException
executeBatchRewrite
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- resultprepareResult
- prepareResultparameterList
- parametersrewriteValues
- is rewritable flagjava.sql.SQLException
- exceptionpublic ServerPrepareResult prepareAndExecutes(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, Results results, java.lang.String sql, java.util.List<ParameterHolder[]> parametersList) throws java.sql.SQLException
prepareAndExecutes
in interface Protocol
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 listjava.sql.SQLException
- if parameter error or connection error occur.public ServerPrepareResult prepareAndExecute(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, Results results, java.lang.String sql, ParameterHolder[] parameters) throws java.sql.SQLException
prepareAndExecute
in interface Protocol
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 preparedparameters
- parametersjava.sql.SQLException
- if parameter error or connection error occur.public void executePreparedQuery(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, Results results, ParameterHolder[] parameters) throws java.sql.SQLException
executePreparedQuery
in interface Protocol
mustExecuteOnMaster
- must execute on masterserverPrepareResult
- prepare resultresults
- execution resultparameters
- parametersjava.sql.SQLException
- exceptionpublic void rollback() throws java.sql.SQLException
public boolean forceReleasePrepareStatement(int statementId) throws java.sql.SQLException
forceReleasePrepareStatement
in interface Protocol
statementId
- prepared statement Id to remove.java.sql.SQLException
- if connection exception.public void forceReleaseWaitingPrepareStatement() throws java.sql.SQLException
forceReleaseWaitingPrepareStatement
in interface Protocol
java.sql.SQLException
- if connection occurpublic boolean ping() throws java.sql.SQLException
public void setCatalog(java.lang.String database) throws java.sql.SQLException
setCatalog
in interface Protocol
java.sql.SQLException
public void cancelCurrentQuery() throws java.sql.SQLException, java.io.IOException
cancelCurrentQuery
in interface Protocol
java.sql.SQLException
- never thrownjava.io.IOException
- if Host is not respondingpublic boolean getAutocommit()
getAutocommit
in interface Protocol
public boolean inTransaction()
inTransaction
in interface Protocol
public void closeExplicit()
closeExplicit
in interface Protocol
public void releasePrepareStatement(ServerPrepareResult serverPrepareResult) throws java.sql.SQLException
releasePrepareStatement
in interface Protocol
serverPrepareResult
- allocation resultjava.sql.SQLException
- if deallocation failed.public void setInternalMaxRows(long max)
setInternalMaxRows
in interface Protocol
max
- row number max valuepublic long getMaxRows()
getMaxRows
in interface Protocol
public void setMaxRows(long max) throws java.sql.SQLException
setMaxRows
in interface Protocol
java.sql.SQLException
public void setLocalInfileInputStream(java.io.InputStream inputStream)
setLocalInfileInputStream
in interface Protocol
public int getTimeout() throws java.net.SocketException
getTimeout
in interface Protocol
java.net.SocketException
- if there is an error in the underlying protocol, such as a TCP error.public void setTimeout(int timeout) throws java.net.SocketException
setTimeout
in interface Protocol
timeout
- the timeout, in millisecondsjava.net.SocketException
- if there is an error in the underlying protocol, such as a TCP error.public void setTransactionIsolation(int level) throws java.sql.SQLException
setTransactionIsolation
in interface Protocol
level
- transaction level.java.sql.SQLException
- if transaction level is unknownpublic int getTransactionIsolationLevel()
getTransactionIsolationLevel
in interface Protocol
private void checkClose() throws java.sql.SQLException
java.sql.SQLException
public void getResult(Results results) throws java.sql.SQLException
public void readPacket(Results results) throws java.sql.SQLException
results
- result objectjava.sql.SQLException
- if sub-result connection failpublic void readOkPacket(Buffer buffer, Results results) throws java.sql.SQLException
buffer
- current bufferresults
- result objectjava.sql.SQLException
- if sub-result connection failprivate void handleStateChange(Buffer buf, Results results) throws java.sql.SQLException
java.sql.SQLException
public int getAutoIncrementIncrement()
getAutoIncrementIncrement
in interface Protocol
public java.sql.SQLException readErrorPacket(Buffer buffer, Results results)
buffer
- current bufferresults
- result objectpublic void readLocalInfilePacket(Buffer buffer, Results results) throws java.sql.SQLException
buffer
- current bufferresults
- result objectjava.sql.SQLException
- if sub-result connection failpublic void readResultSet(Buffer buffer, Results results) throws java.sql.SQLException
buffer
- current bufferresults
- result objectjava.sql.SQLException
- if sub-result connection failpublic void prologProxy(ServerPrepareResult serverPrepareResult, long maxRows, boolean hasProxy, MariaDbConnection connection, MariaDbStatement statement) throws java.sql.SQLException
prologProxy
in interface Protocol
java.sql.SQLException
public void prolog(long maxRows, boolean hasProxy, MariaDbConnection connection, MariaDbStatement statement) throws java.sql.SQLException
public ServerPrepareResult addPrepareInCache(java.lang.String key, ServerPrepareResult serverPrepareResult)
addPrepareInCache
in interface Protocol
private void cmdPrologue() throws java.sql.SQLException
java.sql.SQLException
public void resetStateAfterFailover(long maxRows, int transactionIsolationLevel, java.lang.String database, boolean autocommit) throws java.sql.SQLException
resetStateAfterFailover
in interface Protocol
maxRows
- current Max rowstransactionIsolationLevel
- current transactionIsolationLeveldatabase
- current databaseautocommit
- current autocommit statejava.sql.SQLException
- if any error occur.public java.sql.SQLException handleIoException(java.io.IOException initialException)
There is 3 kind of IOException :
handleIoException
in interface Protocol
initialException
- initial Io errorpublic void setActiveFutureTask(java.util.concurrent.FutureTask activeFutureTask)
setActiveFutureTask
in interface Protocol
public boolean isInterrupted()
isInterrupted
in interface Protocol
public void stopIfInterrupted() throws java.sql.SQLTimeoutException
stopIfInterrupted
in interface Protocol
java.sql.SQLTimeoutException
- to indicate timeout exception.