public class MySQLProtocol extends Object implements Protocol
Modifier and Type | Class and Description |
---|---|
class |
MySQLProtocol.PrepareResult |
Modifier and Type | Field and Description |
---|---|
StreamingSelectResult |
activeResult |
protected HostAddress |
currentHost |
int |
datatypeMappingFlags |
boolean |
hasWarnings |
protected JDBCUrl |
jdbcUrl |
protected ReentrantReadWriteLock |
lock |
boolean |
moreResults |
protected SyncPacketFetcher |
packetFetcher |
protected FailoverProxy |
proxy |
protected boolean |
readOnly |
short |
serverStatus |
protected Socket |
socket |
protected PacketOutputStream |
writer |
Constructor and Description |
---|
MySQLProtocol(JDBCUrl jdbcUrl,
ReentrantReadWriteLock lock)
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
|
boolean |
checkIfMaster() |
void |
close()
Closes socket and stream readers/writers
Attempts graceful shutdown.
|
protected static void |
close(PacketFetcher fetcher,
PacketOutputStream packetOutputStream,
Socket socket) |
void |
closeExplicit() |
void |
closeIfActiveResult() |
void |
closePreparedStatement(int statementId) |
void |
connect() |
void |
connectWithoutProxy() |
QueryResult |
executeQuery(List<Query> dQueries,
boolean streaming,
boolean isRewritable,
int rewriteOffset) |
QueryResult |
executeQuery(Query dQuery) |
QueryResult |
executeQuery(Query query,
boolean streaming) |
boolean |
getAutocommit() |
String |
getDatabase() |
int |
getDatatypeMappingFlags() |
String |
getHost() |
HostAddress |
getHostAddress() |
JDBCUrl |
getJdbcUrl() |
int |
getMajorServerVersion() |
int |
getMaxAllowedPacket() |
int |
getMaxRows() |
int |
getMinorServerVersion() |
QueryResult |
getMoreResults(boolean streaming) |
static MySQLProtocol |
getNewProtocol(FailoverProxy proxy,
JDBCUrl jdbcUrl) |
Options |
getOptions() |
String |
getPassword() |
boolean |
getPinGlobalTxToPhysicalConnection() |
int |
getPort() |
FailoverProxy |
getProxy() |
boolean |
getReadonly() |
QueryResult |
getResult(List<Query> dQueries,
boolean streaming) |
long |
getServerThreadId() |
String |
getServerVersion() |
int |
getTimeout()
Returns the connection timeout in milliseconds.
|
int |
getTransactionIsolationLevel() |
String |
getUsername() |
boolean |
hasMoreResults() |
boolean |
hasUnreadData() |
boolean |
hasWarnings() |
static String |
hexdump(byte[] buffer,
int offset) |
static String |
hexdump(ByteBuffer bb,
int offset) |
boolean |
inTransaction() |
boolean |
isClosed() |
boolean |
isConnected() |
boolean |
isExplicitClosed() |
boolean |
isMasterConnection() |
static void |
loop(Listener listener,
List<HostAddress> addresses,
Map<HostAddress,Long> blacklist,
SearchFilter searchFilter)
loop until found the failed connection.
|
boolean |
mustBeMasterConnection() |
boolean |
noBackslashEscapes() |
boolean |
ping() |
MySQLProtocol.PrepareResult |
prepare(String sql) |
void |
rollback() |
void |
setCatalog(String database) |
void |
setHostAddress(HostAddress host) |
void |
setHostFailedWithoutProxy() |
void |
setInternalMaxRows(int max) |
void |
setLocalInfileInputStream(InputStream inputStream) |
void |
setMaxAllowedPacket(int maxAllowedPacket) |
void |
setMaxRows(int max) |
void |
setProxy(FailoverProxy proxy) |
void |
setReadonly(boolean readOnly) |
void |
setTimeout(int timeout)
Sets the connection timeout.
|
void |
setTransactionIsolation(int level) |
boolean |
shouldReconnectWithoutProxy() |
boolean |
versionGreaterOrEqual(int major,
int minor,
int patch) |
protected final ReentrantReadWriteLock lock
protected Socket socket
protected PacketOutputStream writer
protected boolean readOnly
protected SyncPacketFetcher packetFetcher
public boolean moreResults
public boolean hasWarnings
public StreamingSelectResult activeResult
public int datatypeMappingFlags
public short serverStatus
protected final JDBCUrl jdbcUrl
protected HostAddress currentHost
protected FailoverProxy proxy
public MySQLProtocol(JDBCUrl jdbcUrl, ReentrantReadWriteLock lock)
jdbcUrl
- connection URL infoslock
- the lock for thread synchronisationpublic boolean checkIfMaster() throws QueryException
checkIfMaster
in interface Protocol
QueryException
public MySQLProtocol.PrepareResult prepare(String sql) throws QueryException
prepare
in interface Protocol
QueryException
public void closePreparedStatement(int statementId) throws QueryException
closePreparedStatement
in interface Protocol
QueryException
public void setHostFailedWithoutProxy()
setHostFailedWithoutProxy
in interface Protocol
public JDBCUrl getJdbcUrl()
getJdbcUrl
in interface Protocol
public static MySQLProtocol getNewProtocol(FailoverProxy proxy, JDBCUrl jdbcUrl)
public boolean getAutocommit()
getAutocommit
in interface Protocol
public boolean isMasterConnection()
isMasterConnection
in interface Protocol
public boolean mustBeMasterConnection()
mustBeMasterConnection
in interface Protocol
public boolean noBackslashEscapes()
noBackslashEscapes
in interface Protocol
public void connect() throws QueryException
connect
in interface Protocol
QueryException
public void connectWithoutProxy() throws QueryException
connectWithoutProxy
in interface Protocol
QueryException
public boolean shouldReconnectWithoutProxy()
shouldReconnectWithoutProxy
in interface Protocol
public static void loop(Listener listener, List<HostAddress> addresses, Map<HostAddress,Long> blacklist, SearchFilter searchFilter) throws QueryException
listener
- current listeneraddresses
- list of HostAddress to loopblacklist
- current blacklistsearchFilter
- search parameterQueryException
- if not foundpublic boolean inTransaction()
inTransaction
in interface Protocol
public Options getOptions()
getOptions
in interface Protocol
public boolean hasMoreResults()
hasMoreResults
in interface Protocol
protected static void close(PacketFetcher fetcher, PacketOutputStream packetOutputStream, Socket socket) throws QueryException
QueryException
public void closeExplicit()
closeExplicit
in interface Protocol
public void close()
public boolean isClosed()
public void setCatalog(String database) throws QueryException
setCatalog
in interface Protocol
QueryException
public String getServerVersion()
getServerVersion
in interface Protocol
public void setReadonly(boolean readOnly)
setReadonly
in interface Protocol
public boolean getReadonly()
getReadonly
in interface Protocol
public HostAddress getHostAddress()
getHostAddress
in interface Protocol
public void setHostAddress(HostAddress host)
setHostAddress
in interface Protocol
public void setProxy(FailoverProxy proxy)
public FailoverProxy getProxy()
public String getDatabase()
getDatabase
in interface Protocol
public String getUsername()
getUsername
in interface Protocol
public String getPassword()
getPassword
in interface Protocol
public boolean ping() throws QueryException
ping
in interface Protocol
QueryException
public QueryResult executeQuery(Query dQuery) throws QueryException
executeQuery
in interface Protocol
QueryException
public QueryResult getResult(List<Query> dQueries, boolean streaming) throws QueryException
getResult
in interface Protocol
QueryException
public QueryResult executeQuery(Query query, boolean streaming) throws QueryException
executeQuery
in interface Protocol
QueryException
public QueryResult executeQuery(List<Query> dQueries, boolean streaming, boolean isRewritable, int rewriteOffset) throws QueryException
executeQuery
in interface Protocol
QueryException
public void cancelCurrentQuery() throws QueryException, IOException
cancelCurrentQuery
in interface Protocol
QueryException
- never thrownIOException
- if Host is not respondingpublic QueryResult getMoreResults(boolean streaming) throws QueryException
getMoreResults
in interface Protocol
QueryException
public static String hexdump(byte[] buffer, int offset)
public static String hexdump(ByteBuffer bb, int offset)
public boolean hasUnreadData()
hasUnreadData
in interface Protocol
public void setMaxRows(int max) throws QueryException
setMaxRows
in interface Protocol
QueryException
public void setInternalMaxRows(int max)
setInternalMaxRows
in interface Protocol
public int getMaxRows()
getMaxRows
in interface Protocol
public int getMajorServerVersion()
getMajorServerVersion
in interface Protocol
public int getMinorServerVersion()
getMinorServerVersion
in interface Protocol
public boolean versionGreaterOrEqual(int major, int minor, int patch)
versionGreaterOrEqual
in interface Protocol
public void setLocalInfileInputStream(InputStream inputStream)
setLocalInfileInputStream
in interface Protocol
public int getMaxAllowedPacket()
getMaxAllowedPacket
in interface Protocol
public void setMaxAllowedPacket(int maxAllowedPacket)
setMaxAllowedPacket
in interface Protocol
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 int getTimeout() throws SocketException
getTimeout
in interface Protocol
SocketException
- if there is an error in the underlying protocol, such as a TCP error.public boolean getPinGlobalTxToPhysicalConnection()
getPinGlobalTxToPhysicalConnection
in interface Protocol
public void setTransactionIsolation(int level) throws QueryException
setTransactionIsolation
in interface Protocol
QueryException
public int getTransactionIsolationLevel()
getTransactionIsolationLevel
in interface Protocol
public boolean hasWarnings()
hasWarnings
in interface Protocol
public boolean isConnected()
isConnected
in interface Protocol
public long getServerThreadId()
getServerThreadId
in interface Protocol
public int getDatatypeMappingFlags()
getDatatypeMappingFlags
in interface Protocol
public void closeIfActiveResult()
closeIfActiveResult
in interface Protocol
public boolean isExplicitClosed()
isExplicitClosed
in interface Protocol
Copyright © 2015. All rights reserved.