public class AbstractQueryProtocol extends AbstractConnectProtocol implements Protocol
activeStreamingResult, checkCallableResultSet, connected, currentHost, database, dataTypeMappingFlags, explicitClosed, hasWarnings, lock, moreResults, moreResultsTypeBinary, options, packetFetcher, proxy, readOnly, serverComMultiCapability, serverPrepareStatementCache, serverStatus, serverThreadId, socket, urlParser, writer
Constructor and Description |
---|
AbstractQueryProtocol(UrlParser urlParser,
ReentrantLock lock)
Get a protocol instance.
|
Modifier and Type | Method and Description |
---|---|
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) |
ExecutionResult |
getResult(ExecutionResult executionResult,
int resultSetScrollType,
boolean binaryProtocol,
boolean loadAllResults) |
int |
getTimeout()
Returns the connection timeout in milliseconds.
|
int |
getTransactionIsolationLevel() |
boolean |
hasMoreResults() |
static String |
hexdump(byte[] buffer,
int offset)
Hexdump.
|
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.
|
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, hasServerComMultiCapability, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, releaseWriterBuffer, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setMoreResults, setProxy, setReadonly, shouldReconnectWithoutProxy, skip, skipEofPacket, versionGreaterOrEqual
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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, hasServerComMultiCapability, hasWarnings, isClosed, isConnected, isExplicitClosed, isMasterConnection, mustBeMasterConnection, noBackslashEscapes, prepareStatementCache, readEofPacket, releaseWriterBuffer, setActiveStreamingResult, setHasWarnings, setHostAddress, setHostFailedWithoutProxy, setMoreResults, setProxy, setReadonly, shouldReconnectWithoutProxy, skip, skipEofPacket, versionGreaterOrEqual
public AbstractQueryProtocol(UrlParser urlParser, ReentrantLock lock)
urlParser
- connection URL infoslock
- the lock for thread synchronisationpublic void executeQuery(String sql) throws QueryException
executeQuery
in interface Protocol
executeQuery
in class AbstractConnectProtocol
QueryException
public void executeQuery(boolean mustExecuteOnMaster, ExecutionResult executionResult, String sql, int resultSetScrollType) throws QueryException
executeQuery
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionexecutionResult
- resultsql
- the query to executeInternalresultSetScrollType
- resultSetScrollTypeQueryException
- exceptionpublic void executeQuery(boolean mustExecuteOnMaster, ExecutionResult executionResult, ClientPrepareResult clientPrepareResult, ParameterHolder[] parameters, int resultSetScrollType) throws QueryException
executeQuery
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionexecutionResult
- resultclientPrepareResult
- clientPrepareResultparameters
- parametersresultSetScrollType
- resultsetScroll typeQueryException
- exceptionpublic void executeBatchMulti(boolean mustExecuteOnMaster, ExecutionResult executionResult, ClientPrepareResult clientPrepareResult, List<ParameterHolder[]> parametersList, int resultSetScrollType) throws QueryException
executeBatchMulti
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionexecutionResult
- resultclientPrepareResult
- ClientPrepareResultparametersList
- List of parametersresultSetScrollType
- resultsetScroll typeQueryException
- exceptionpublic void executeBatch(boolean mustExecuteOnMaster, ExecutionResult executionResult, List<String> queries, int resultSetScrollType) throws QueryException
executeBatch
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionqueries
- list of queriesresultSetScrollType
- resultSetScrollTypeQueryException
- exceptionpublic ServerPrepareResult prepare(String sql, boolean executeOnMaster) throws QueryException
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)
prepare
in interface Protocol
sql
- the queryexecuteOnMaster
- state of current connection when creating this prepareStatementQueryException
- if any error occur on connection.public void executeBatchMultiple(boolean mustExecuteOnMaster, ExecutionResult executionResult, List<String> queries, int resultSetScrollType) throws QueryException
executeBatchMultiple
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionqueries
- list of queryesresultSetScrollType
- resultSetScrollTypeQueryException
- exceptionpublic void executeBatchRewrite(boolean mustExecuteOnMaster, ExecutionResult executionResult, ClientPrepareResult prepareResult, List<ParameterHolder[]> parameterList, int resultSetScrollType, boolean rewriteValues) throws QueryException
executeBatchRewrite
in interface Protocol
mustExecuteOnMaster
- was intended to be launched on master connectionexecutionResult
- resultprepareResult
- prepareResultparameterList
- parametersresultSetScrollType
- resultsetScroll typerewriteValues
- is rewritable flagQueryException
- exceptionpublic ServerPrepareResult prepareAndExecutes(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, String sql, List<ParameterHolder[]> parametersList, int resultSetScrollType) throws QueryException
prepareAndExecutes
in interface Protocol
mustExecuteOnMaster
- must normally be executed on master connectionserverPrepareResult
- prepare result. can be null if not prepared.executionResult
- execution resultssql
- sql query if needed to be preparedparametersList
- parameter listresultSetScrollType
- result scroll typeQueryException
- if parameter error or connection error occur.public ServerPrepareResult prepareAndExecute(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, String sql, ParameterHolder[] parameters, int resultSetScrollType) throws QueryException
prepareAndExecute
in interface Protocol
mustExecuteOnMaster
- must normally be executed on master connectionserverPrepareResult
- prepare result. can be null if not prepared.executionResult
- execution resultssql
- sql query if needed to be preparedparameters
- parametersresultSetScrollType
- result scroll typeQueryException
- if parameter error or connection error occur.public void executePreparedQuery(boolean mustExecuteOnMaster, ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, ParameterHolder[] parameters, int resultSetScrollType) throws QueryException
executePreparedQuery
in interface Protocol
mustExecuteOnMaster
- must execute on masterserverPrepareResult
- prepare resultexecutionResult
- execution resultparameters
- parametersresultSetScrollType
- scroll type.QueryException
- exceptionpublic void rollback() throws QueryException
rollback
in interface Protocol
QueryException
public boolean forceReleasePrepareStatement(int statementId) throws QueryException
forceReleasePrepareStatement
in interface Protocol
statementId
- prepared statement Id to remove.QueryException
- if connection exception.public void forceReleaseWaitingPrepareStatement() throws QueryException
forceReleaseWaitingPrepareStatement
in interface Protocol
QueryException
- if connection occurpublic boolean ping() throws QueryException
ping
in interface Protocol
QueryException
public void setCatalog(String database) throws QueryException
setCatalog
in interface Protocol
QueryException
public void cancelCurrentQuery() throws QueryException, IOException
cancelCurrentQuery
in interface Protocol
QueryException
- never thrownIOException
- if Host is not respondingpublic boolean getAutocommit()
getAutocommit
in interface Protocol
public boolean inTransaction()
inTransaction
in interface Protocol
public boolean hasMoreResults()
hasMoreResults
in interface Protocol
hasMoreResults
in class AbstractConnectProtocol
public void closeExplicit()
closeExplicit
in interface Protocol
public void releasePrepareStatement(ServerPrepareResult serverPrepareResult) throws QueryException
releasePrepareStatement
in interface Protocol
serverPrepareResult
- allocation resultQueryException
- if deallocation failed.public void getMoreResults(ExecutionResult executionResult) throws QueryException
getMoreResults
in interface Protocol
getMoreResults
in class AbstractConnectProtocol
QueryException
public void setInternalMaxRows(int max)
setInternalMaxRows
in interface Protocol
max
- row number max valuepublic int getMaxRows()
getMaxRows
in interface Protocol
public void setMaxRows(int max) throws QueryException
setMaxRows
in interface Protocol
QueryException
public void setLocalInfileInputStream(InputStream inputStream)
setLocalInfileInputStream
in interface Protocol
public int getTimeout() throws SocketException
getTimeout
in interface Protocol
SocketException
- if there is an error in the underlying protocol, such as a TCP error.public void setTimeout(int timeout) throws SocketException
setTimeout
in interface Protocol
timeout
- the timeout, in millisecondsSocketException
- if there is an error in the underlying protocol, such as a TCP error.public void setTransactionIsolation(int level) throws QueryException
setTransactionIsolation
in interface Protocol
level
- transaction level.QueryException
- if transaction level is unknownpublic int getTransactionIsolationLevel()
getTransactionIsolationLevel
in interface Protocol
public void fetchActiveStreamingResult() throws SQLException
SQLException
- if socket error.public ExecutionResult getResult(ExecutionResult executionResult, int resultSetScrollType, boolean binaryProtocol, boolean loadAllResults) throws QueryException
getResult
in interface Protocol
QueryException
public void prologProxy(ServerPrepareResult serverPrepareResult, ExecutionResult executionResult, int maxRows, boolean hasProxy, MariaDbConnection connection, Statement statement) throws SQLException
prologProxy
in interface Protocol
SQLException
public void prolog(ExecutionResult executionResult, int maxRows, boolean hasProxy, MariaDbConnection connection, Statement statement) throws SQLException
prolog
in interface Protocol
executionResult
- resultmaxRows
- query max rowshasProxy
- has proxyconnection
- current connectionstatement
- current statementSQLException
- if any error occur.public ServerPrepareResult addPrepareInCache(String key, ServerPrepareResult serverPrepareResult)
addPrepareInCache
in interface Protocol
public static String hexdump(byte[] buffer, int offset)
buffer
- byte arrayoffset
- offsetCopyright © 2016. All rights reserved.