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 java.util.Set<java.lang.Integer> |
LOCK_DEADLOCK_ERROR_CODES |
private static Logger |
logger |
private long |
maxRows |
private java.util.concurrent.ThreadPoolExecutor |
readScheduler |
private int |
statementIdToRelease |
private int |
transactionIsolationLevel |
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| Constructor and Description |
|---|
AbstractQueryProtocol(UrlParser urlParser,
GlobalStateInfo globalInfo,
java.util.concurrent.locks.ReentrantLock lock,
LruTraceCache traceCache)
Get a protocol instance.
|
| Modifier and Type | Method and Description |
|---|---|
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() |
private MariaDbSqlException |
exceptionWithQuery(ParameterHolder[] parameters,
PrepareResult serverPrepareResult,
java.sql.SQLException sqlException,
boolean explicitClosed) |
private MariaDbSqlException |
exceptionWithQuery(java.lang.String sql,
java.sql.SQLException sqlException,
boolean explicitClosed) |
private void |
executeBatch(Results results,
java.util.List<java.lang.String> queries)
Execute list of queries not rewritable.
|
private void |
executeBatchAggregateSemiColon(Results results,
java.util.List<java.lang.String> queries)
Execute list of queries.
|
boolean |
executeBatchClient(boolean mustExecuteOnMaster,
Results results,
ClientPrepareResult prepareResult,
java.util.List<ParameterHolder[]> parametersList)
Execute clientPrepareQuery batch.
|
private void |
executeBatchMulti(Results results,
ClientPrepareResult clientPrepareResult,
java.util.List<ParameterHolder[]> parametersList)
Execute clientPrepareQuery batch.
|
private void |
executeBatchRewrite(Results results,
ClientPrepareResult prepareResult,
java.util.List<ParameterHolder[]> parameterList,
boolean rewriteValues)
Specific execution for batch rewrite that has specific query for memory.
|
boolean |
executeBatchServer(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 |
executeBatchStmt(boolean mustExecuteOnMaster,
Results results,
java.util.List<java.lang.String> queries)
Execute batch from Statement.executeBatch().
|
private boolean |
executeBulkBatch(Results results,
java.lang.String sql,
ServerPrepareResult serverPrepareResult,
java.util.List<ParameterHolder[]> parametersList)
Execute clientPrepareQuery batch.
|
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.
|
java.lang.String |
getCatalog() |
long |
getMaxRows() |
void |
getResult(Results results) |
int |
getTimeout()
Returns the connection timeout in milliseconds.
|
int |
getTransactionIsolationLevel() |
java.sql.SQLException |
handleIoException(java.lang.Exception 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) |
private void |
initializeBatchReader() |
void |
interrupt() |
boolean |
inTransaction() |
boolean |
isInterrupted() |
boolean |
isValid(int timeout)
Check that connection is valid.
|
boolean |
ping() |
ServerPrepareResult |
prepare(java.lang.String sql,
boolean executeOnMaster)
Prepare query on server side.
|
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) |
ServerPrepareResult |
putInCache(java.lang.String key,
ServerPrepareResult serverPrepareResult) |
private java.sql.SQLException |
readErrorPacket(Buffer buffer,
Results results)
Read ERR_Packet.
|
private void |
readLocalInfilePacket(Buffer buffer,
Results results)
Read Local_infile Packet.
|
private void |
readOkPacket(Buffer buffer,
Results results)
Read OK_Packet.
|
private void |
readPacket(Results results)
Read server response packet.
|
private void |
readResultSet(Buffer buffer,
Results results)
Read ResultSet Packet.
|
void |
releasePrepareStatement(ServerPrepareResult serverPrepareResult)
Deallocate prepare statement if not used anymore.
|
void |
reset()
Reset connection state.
|
void |
resetDatabase() |
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 |
setLocalInfileInputStream(java.io.InputStream inputStream) |
void |
setMaxRows(long max) |
void |
setReadonly(boolean readOnly)
Puts this connection in read-only / read-write mode
|
void |
setTimeout(int timeout)
Sets the connection timeout.
|
void |
setTransactionIsolation(int level)
Set transaction isolation.
|
void |
stopIfInterrupted()
Throw TimeoutException if timeout has been reached.
|
abort, changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, connect, connectWithoutProxy, destroySocket, getActiveStreamingResult, getDatabase, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReader, getReadonly, getServerThreadId, getServerVersion, getSocket, 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, versionGreaterOrEqualclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitabort, changeSocketSoTimeout, changeSocketTcpNoDelay, checkIfMaster, close, connect, connectWithoutProxy, getActiveStreamingResult, getDatabase, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, 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, versionGreaterOrEqualprivate static final Logger logger
private static final java.util.Set<java.lang.Integer> LOCK_DEADLOCK_ERROR_CODES
private java.util.concurrent.ThreadPoolExecutor readScheduler
private int transactionIsolationLevel
private java.io.InputStream localInfileInputStream
private long maxRows
private volatile int statementIdToRelease
private java.util.concurrent.FutureTask activeFutureTask
private boolean interrupted
AbstractQueryProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, java.util.concurrent.locks.ReentrantLock lock, LruTraceCache traceCache)
urlParser - connection URL information'slock - the lock for thread synchronisationtraceCache - trace cachepublic void reset()
throws java.sql.SQLException
private MariaDbSqlException exceptionWithQuery(ParameterHolder[] parameters, PrepareResult serverPrepareResult, java.sql.SQLException sqlException, boolean explicitClosed)
private MariaDbSqlException exceptionWithQuery(java.lang.String sql, java.sql.SQLException sqlException, boolean explicitClosed)
public void executeQuery(java.lang.String sql)
throws java.sql.SQLException
!! will not support multi values queries !!
executeQuery in interface ProtocolexecuteQuery in class AbstractConnectProtocolsql - sqljava.sql.SQLException - in any exception occurpublic void executeQuery(boolean mustExecuteOnMaster,
Results results,
java.lang.String sql)
throws java.sql.SQLException
executeQuery in interface ProtocolmustExecuteOnMaster - 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 Protocoljava.sql.SQLExceptionpublic void executeQuery(boolean mustExecuteOnMaster,
Results results,
ClientPrepareResult clientPrepareResult,
ParameterHolder[] parameters)
throws java.sql.SQLException
executeQuery in interface ProtocolmustExecuteOnMaster - 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 ProtocolmustExecuteOnMaster - was intended to be launched on master connectionresults - resultsclientPrepareResult - clientPrepareResultparameters - parametersqueryTimeout - if timeout is set and must use max_statement_timejava.sql.SQLException - exceptionpublic boolean executeBatchClient(boolean mustExecuteOnMaster,
Results results,
ClientPrepareResult prepareResult,
java.util.List<ParameterHolder[]> parametersList)
throws java.sql.SQLException
executeBatchClient in interface ProtocolmustExecuteOnMaster - was intended to be launched on master connectionresults - resultsprepareResult - ClientPrepareResultparametersList - List of parametersjava.sql.SQLException - exceptionprivate boolean executeBulkBatch(Results results, java.lang.String sql, ServerPrepareResult serverPrepareResult, java.util.List<ParameterHolder[]> parametersList) throws java.sql.SQLException
results - resultssql - sql commandserverPrepareResult - prepare result if existparametersList - List of parametersjava.sql.SQLException - exceptionprivate void initializeBatchReader()
private void executeBatchMulti(Results results, ClientPrepareResult clientPrepareResult, java.util.List<ParameterHolder[]> parametersList) throws java.sql.SQLException
results - resultsclientPrepareResult - ClientPrepareResultparametersList - List of parametersjava.sql.SQLException - exceptionpublic void executeBatchStmt(boolean mustExecuteOnMaster,
Results results,
java.util.List<java.lang.String> queries)
throws java.sql.SQLException
executeBatchStmt in interface ProtocolmustExecuteOnMaster - was intended to be launched on master connectionresults - resultsqueries - queriesjava.sql.SQLException - if any exception occurprivate void executeBatch(Results results, java.util.List<java.lang.String> queries) throws java.sql.SQLException
results - 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 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)
private void executeBatchAggregateSemiColon(Results results, java.util.List<java.lang.String> queries) throws java.sql.SQLException
results - result objectqueries - list of queriesjava.sql.SQLException - exceptionprivate void executeBatchRewrite(Results results, ClientPrepareResult prepareResult, java.util.List<ParameterHolder[]> parameterList, boolean rewriteValues) throws java.sql.SQLException
results - resultprepareResult - prepareResultparameterList - parametersrewriteValues - is rewritable flagjava.sql.SQLException - exceptionpublic boolean executeBatchServer(boolean mustExecuteOnMaster,
ServerPrepareResult serverPrepareResult,
Results results,
java.lang.String sql,
java.util.List<ParameterHolder[]> parametersList)
throws java.sql.SQLException
executeBatchServer in interface ProtocolmustExecuteOnMaster - 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 void executePreparedQuery(boolean mustExecuteOnMaster,
ServerPrepareResult serverPrepareResult,
Results results,
ParameterHolder[] parameters)
throws java.sql.SQLException
executePreparedQuery in interface ProtocolmustExecuteOnMaster - 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 ProtocolstatementId - prepared statement Id to remove.java.sql.SQLException - if connection exception.public void forceReleaseWaitingPrepareStatement()
throws java.sql.SQLException
forceReleaseWaitingPrepareStatement in interface Protocoljava.sql.SQLException - if connection occurpublic boolean ping()
throws java.sql.SQLException
public boolean isValid(int timeout)
throws java.sql.SQLException
public java.lang.String getCatalog()
throws java.sql.SQLException
getCatalog in interface Protocoljava.sql.SQLExceptionpublic void setCatalog(java.lang.String database)
throws java.sql.SQLException
setCatalog in interface Protocoljava.sql.SQLExceptionpublic void resetDatabase()
throws java.sql.SQLException
resetDatabase in interface Protocoljava.sql.SQLExceptionpublic void cancelCurrentQuery()
throws java.sql.SQLException
cancelCurrentQuery in interface Protocoljava.sql.SQLException - never thrownpublic boolean getAutocommit()
getAutocommit in interface Protocolpublic boolean inTransaction()
inTransaction in interface Protocolpublic void closeExplicit()
closeExplicit in interface Protocolpublic void releasePrepareStatement(ServerPrepareResult serverPrepareResult) throws java.sql.SQLException
releasePrepareStatement in interface ProtocolserverPrepareResult - allocation resultjava.sql.SQLException - if de-allocation failed.public long getMaxRows()
getMaxRows in interface Protocolpublic void setMaxRows(long max)
throws java.sql.SQLException
setMaxRows in interface Protocoljava.sql.SQLExceptionpublic void setLocalInfileInputStream(java.io.InputStream inputStream)
setLocalInfileInputStream in interface Protocolpublic int getTimeout()
getTimeout in interface Protocolpublic void setTimeout(int timeout)
throws java.net.SocketException
setTimeout in interface Protocoltimeout - the timeout, in millisecondsjava.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.public void setReadonly(boolean readOnly)
throws java.sql.SQLException
setReadonly in interface ProtocolreadOnly - true enables read-only mode; false disables itjava.sql.SQLException - If socket error.public void setTransactionIsolation(int level)
throws java.sql.SQLException
setTransactionIsolation in interface Protocollevel - transaction level.java.sql.SQLException - if transaction level is unknownpublic int getTransactionIsolationLevel()
getTransactionIsolationLevel in interface Protocolprivate void checkClose()
throws java.sql.SQLException
java.sql.SQLExceptionpublic void getResult(Results results) throws java.sql.SQLException
private void readPacket(Results results) throws java.sql.SQLException
results - result objectjava.sql.SQLException - if sub-result connection failprivate void readOkPacket(Buffer buffer, Results results)
buffer - current bufferresults - result objectpublic int getAutoIncrementIncrement()
throws java.sql.SQLException
getAutoIncrementIncrement in interface Protocoljava.sql.SQLException - if cannot retrieve auto increment valueprivate java.sql.SQLException readErrorPacket(Buffer buffer, Results results)
buffer - current bufferresults - result objectprivate void readLocalInfilePacket(Buffer buffer, Results results) throws java.sql.SQLException
buffer - current bufferresults - result objectjava.sql.SQLException - if sub-result connection failprivate 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 Protocoljava.sql.SQLExceptionpublic void prolog(long maxRows,
boolean hasProxy,
MariaDbConnection connection,
MariaDbStatement statement)
throws java.sql.SQLException
public ServerPrepareResult putInCache(java.lang.String key, ServerPrepareResult serverPrepareResult)
putInCache in interface Protocolprivate void cmdPrologue()
throws java.sql.SQLException
java.sql.SQLExceptionpublic void resetStateAfterFailover(long maxRows,
int transactionIsolationLevel,
java.lang.String database,
boolean autocommit)
throws java.sql.SQLException
resetStateAfterFailover in interface ProtocolmaxRows - current Max rowstransactionIsolationLevel - current transactionIsolationLeveldatabase - current databaseautocommit - current autocommit statejava.sql.SQLException - if any error occur.public java.sql.SQLException handleIoException(java.lang.Exception initialException)
There is 3 kind of IOException :
handleIoException in interface ProtocolinitialException - initial Io errorpublic void setActiveFutureTask(java.util.concurrent.FutureTask activeFutureTask)
setActiveFutureTask in interface Protocolpublic boolean isInterrupted()
isInterrupted in interface Protocolpublic void stopIfInterrupted()
throws java.sql.SQLTimeoutException
stopIfInterrupted in interface Protocoljava.sql.SQLTimeoutException - to indicate timeout exception.