public class AbstractQueryProtocol extends AbstractConnectProtocol implements Protocol
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.FutureTask |
activeFutureTask |
private static java.lang.String |
CHECK_GALERA_STATE_QUERY |
private java.util.List<java.lang.String> |
galeraAllowedStates |
private boolean |
interrupted |
private java.io.InputStream |
localInfileInputStream |
private static Logger |
logger |
private LogQueryTool |
logQuery |
private long |
maxRows |
protected static java.util.concurrent.ThreadPoolExecutor |
readScheduler |
private int |
statementIdToRelease |
private int |
transactionIsolationLevel |
activeStreamingResult, autoIncrementIncrement, connected, database, eofDeprecated, explicitClosed, hasWarnings, lock, options, proxy, reader, readOnly, serverCapabilities, serverPrepareStatementCache, serverStatus, serverThreadId, socket, urlParser, writer
Constructor and Description |
---|
AbstractQueryProtocol(UrlParser urlParser,
GlobalStateInfo globalInfo,
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() |
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,
boolean hasLongData)
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,
boolean hasLongData)
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) |
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 |
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, getActiveStreamingResult, getDatabase, getHost, getHostAddress, getLock, getMajorServerVersion, getMinorServerVersion, getOptions, getPinGlobalTxToPhysicalConnection, getPort, getProxy, getReader, getReadonly, getServerThreadId, getServerVersion, getSocket, getTimeZone, getTraces, getUrlParser, getUsername, getWriter, hasMoreResults, hasWarnings, isClosed, isConnected, isEofDeprecated, isExplicitClosed, isMasterConnection, isServerMariaDb, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, readPipelineCheckMaster, removeActiveStreamingResult, removeHasMoreResults, sessionStateAware, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setProxy, setReadonly, setServerStatus, shouldReconnectWithoutProxy, skip, skipEofPacket, versionGreaterOrEqual
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
abort, 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, 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
private static final Logger logger
private static final java.lang.String CHECK_GALERA_STATE_QUERY
protected static java.util.concurrent.ThreadPoolExecutor readScheduler
private final LogQueryTool logQuery
private int transactionIsolationLevel
private java.io.InputStream localInfileInputStream
private long maxRows
private volatile int statementIdToRelease
private java.util.concurrent.FutureTask activeFutureTask
private boolean interrupted
private final java.util.List<java.lang.String> galeraAllowedStates
AbstractQueryProtocol(UrlParser urlParser, GlobalStateInfo globalInfo, java.util.concurrent.locks.ReentrantLock lock)
urlParser
- connection URL information'slock
- the lock for thread synchronisationpublic void reset() throws java.sql.SQLException
public 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 boolean executeBatchClient(boolean mustExecuteOnMaster, Results results, ClientPrepareResult prepareResult, java.util.List<ParameterHolder[]> parametersList, boolean hasLongData) throws java.sql.SQLException
executeBatchClient
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionresults
- resultsprepareResult
- ClientPrepareResultparametersList
- List of parametershasLongData
- has parameter with long data (stream)java.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 Protocol
mustExecuteOnMaster
- 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 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)
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, boolean hasLongData) throws java.sql.SQLException
executeBatchServer
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 listhasLongData
- has long data (stream)java.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 boolean isValid(int timeout) throws java.sql.SQLException
public java.lang.String getCatalog() throws java.sql.SQLException
getCatalog
in interface Protocol
java.sql.SQLException
public void setCatalog(java.lang.String database) throws java.sql.SQLException
setCatalog
in interface Protocol
java.sql.SQLException
public void resetDatabase() throws java.sql.SQLException
resetDatabase
in interface Protocol
java.sql.SQLException
public void cancelCurrentQuery() throws java.sql.SQLException
cancelCurrentQuery
in interface Protocol
java.sql.SQLException
- never thrownpublic 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 de-allocation failed.public 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
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 Protocol
java.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 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.lang.Exception 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.