public class XProtocol extends AbstractProtocol<XMessage> implements Protocol<XMessage>
Protocol.ProtocolEventHandler, Protocol.ProtocolEventListener| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
defaultSchemaName |
authProvider, exceptionInterceptor, log, messageBuilder, packetDebugRingBuffer, propertySet, queryTimingUnits, session, socketConnection, transactionManager, useNanosForElapsedTime| Constructor and Description |
|---|
XProtocol(HostInfo hostInfo,
PropertySet propertySet) |
| Modifier and Type | Method and Description |
|---|---|
void |
afterHandshake() |
void |
beforeHandshake() |
void |
changeDatabase(java.lang.String database) |
void |
changeUser(java.lang.String user,
java.lang.String password,
java.lang.String database)
Re-authenticates as the given user and password
|
XMessage |
checkErrorMessage()
Read one message from the MySQL server, checks for errors in it, and if none,
returns the message, ready for reading
|
void |
close() |
void |
configureTimeZone() |
void |
connect(java.lang.String user,
java.lang.String password,
java.lang.String database)
Create a new session.
|
void |
drainRows()
Used only in tests
|
boolean |
failedPreparingStatement(int preparedStatementId,
XProtocolError e)
Informs this protocol instance that preparing a statement on the connected server failed.
|
void |
freePreparedStatementId(int preparedStatementId)
Frees a prepared statement id so that it can be reused.
|
ExceptionInterceptor |
getExceptionInterceptor() |
java.io.InputStream |
getLocalInfileInputStream()
Returns the InputStream instance that will be used to send
data in response to a "LOAD DATA LOCAL INFILE" statement.
|
int |
getNewPreparedStatementId(PreparableStatement<?> preparableStatement)
Returns an id to be used as a client-managed prepared statement id.
|
java.lang.String |
getQueryComment()
Returns the comment that will be prepended to all statements
sent to the server.
|
ServerSession |
getServerSession() |
java.util.function.Supplier<ValueEncoder> |
getValueEncoderSupplier(java.lang.Object obj) |
boolean |
hasMoreResults() |
boolean |
hasResults()
Used only in tests
|
void |
init(Session sess,
SocketConnection socketConn,
PropertySet propSet,
TransactionEventHandler trManager)
Init method takes the place of constructor.
|
void |
initServerSession() |
boolean |
isOpen() |
boolean |
isSqlResultPending() |
void |
negotiateCompression()
Negotiates compression capabilities with the server.
|
void |
negotiateSSLConnection() |
protected void |
newCommand()
Signal the intent to start processing a new command.
|
<M extends Message,R extends QueryResult> |
query(M message,
ResultBuilder<R> resultBuilder) |
<M extends Message,R extends QueryResult> |
queryAsync(M message,
ResultBuilder<R> resultBuilder) |
<T extends ProtocolEntity> |
read(java.lang.Class<Resultset> requiredClass,
int maxRows,
boolean streamResults,
XMessage resultPacket,
boolean isBinaryEncoded,
ColumnDefinition metadata,
ProtocolEntityFactory<T,XMessage> protocolEntityFactory)
Read protocol entity.
|
<T extends ProtocolEntity> |
read(java.lang.Class<T> requiredClass,
ProtocolEntityFactory<T,XMessage> protocolEntityFactory) |
byte[] |
readAuthenticateContinue() |
void |
readAuthenticateOk() |
XMessage |
readMessage(XMessage reuse)
Read one message from the MySQL server into the reusable buffer if provided or into the new one.
|
ColumnDefinition |
readMetadata() |
ColumnDefinition |
readMetadata(java.util.function.Consumer<Notice> noticeConsumer) |
ColumnDefinition |
readMetadata(Field f,
java.util.function.Consumer<Notice> noticeConsumer) |
<T extends QueryResult> |
readQueryResult(ResultBuilder<T> resultBuilder)
Read messages from server and deliver them to resultBuilder.
|
XProtocolRow |
readRowOrNull(ColumnDefinition metadata,
java.util.function.Consumer<Notice> noticeConsumer) |
ServerCapabilities |
readServerCapabilities()
Get the capabilities from the server.
|
boolean |
readyForPreparingStatements()
Checks if enough statements have been executed in this MySQL server so that another prepare statement attempt should be done.
|
void |
reset()
Return Protocol to its initial state right after successful connect.
|
void |
send(Message message,
int packetLen) |
void |
sendCapabilities(java.util.Map<java.lang.String,java.lang.Object> keyValuePair)
Set client capabilities of current session.
|
XMessage |
sendCommand(Message queryPacket,
boolean skipCheck,
int timeoutMillis)
Send a command to the MySQL server.
|
void |
setLocalInfileInputStream(java.io.InputStream stream)
Sets an InputStream instance that will be used to send data
to the MySQL server for a "LOAD DATA LOCAL INFILE" statement
rather than a FileInputStream or URLInputStream that represents
the path given as an argument to the statement.
|
void |
setMaxAllowedPacket(int maxAllowedPacket) |
void |
setQueryComment(java.lang.String comment)
Sets the comment that will be prepended to all statements
sent to the server.
|
boolean |
supportsPreparedStatements()
Checks if the MySQL server currently connected supports prepared statements.
|
boolean |
versionMeetsMinimum(int major,
int minor,
int subminor) |
addListener, getAuthenticationProvider, getMessageBuilder, getPacketReceivedTimeHolder, getPacketSentTimeHolder, getPropertySet, getQueryTimingUnits, getSocketConnection, invokeListeners, removeListener, setPacketReceivedTimeHolder, setPacketSentTimeHolder, setPropertySetclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAuthenticationProvider, getMessageBuilder, getPacketReceivedTimeHolder, getPacketSentTimeHolder, getPropertySet, getQueryTimingUnits, getSocketConnection, setPacketReceivedTimeHolder, setPacketSentTimeHolder, setPropertySetpublic XProtocol(HostInfo hostInfo, PropertySet propertySet)
public void init(Session sess, SocketConnection socketConn, PropertySet propSet, TransactionEventHandler trManager)
Protocolinit in interface Protocol<XMessage>init in class AbstractProtocol<XMessage>sess - SessionsocketConn - SocketConnectionpropSet - PropertySettrManager - TransactionEventHandlerpublic ServerSession getServerSession()
getServerSession in interface Protocol<XMessage>public void sendCapabilities(java.util.Map<java.lang.String,java.lang.Object> keyValuePair)
changeUser(String, String, String)).keyValuePair - capabilities name/value mappublic void negotiateSSLConnection()
negotiateSSLConnection in interface Protocol<XMessage>public void negotiateCompression()
public void beforeHandshake()
beforeHandshake in interface Protocol<XMessage>public void connect(java.lang.String user,
java.lang.String password,
java.lang.String database)
Protocolpublic void changeUser(java.lang.String user,
java.lang.String password,
java.lang.String database)
ProtocolchangeUser in interface Protocol<XMessage>user - DB user namepassword - DB user passworddatabase - database namepublic void afterHandshake()
afterHandshake in interface Protocol<XMessage>public void configureTimeZone()
configureTimeZone in interface Protocol<XMessage>public void initServerSession()
initServerSession in interface Protocol<XMessage>public void readAuthenticateOk()
public byte[] readAuthenticateContinue()
public boolean hasMoreResults()
public <T extends QueryResult> T readQueryResult(ResultBuilder<T> resultBuilder)
ProtocolreadQueryResult in interface Protocol<XMessage>T - result typeresultBuilder - ResultBuilder instanceQueryResultpublic boolean hasResults()
public void drainRows()
public ColumnDefinition readMetadata()
readMetadata in interface Protocol<XMessage>public ColumnDefinition readMetadata(java.util.function.Consumer<Notice> noticeConsumer)
public ColumnDefinition readMetadata(Field f, java.util.function.Consumer<Notice> noticeConsumer)
public XProtocolRow readRowOrNull(ColumnDefinition metadata, java.util.function.Consumer<Notice> noticeConsumer)
public boolean supportsPreparedStatements()
true if the MySQL server currently connected supports prepared statements.public boolean readyForPreparingStatements()
true if enough executions have been done since last time a prepared statement failed to preparepublic int getNewPreparedStatementId(PreparableStatement<?> preparableStatement)
freePreparedStatementId(int) must be called when the prepared
statement is deallocated so that the same id can be re-used.preparableStatement - PreparableStatementpublic void freePreparedStatementId(int preparedStatementId)
preparedStatementId - the prepared statement id to releasepublic boolean failedPreparingStatement(int preparedStatementId,
XProtocolError e)
preparedStatementId - the id of the prepared statement that failed to preparee - XProtocolErrortrue if the exception was properly handledprotected void newCommand()
public <M extends Message,R extends QueryResult> R query(M message, ResultBuilder<R> resultBuilder)
public <M extends Message,R extends QueryResult> java.util.concurrent.CompletableFuture<R> queryAsync(M message, ResultBuilder<R> resultBuilder)
public boolean isOpen()
public void close()
throws java.io.IOException
public boolean isSqlResultPending()
public void setMaxAllowedPacket(int maxAllowedPacket)
public void send(Message message, int packetLen)
public ServerCapabilities readServerCapabilities()
NOTE: This must be called before authentication.
readServerCapabilities in interface Protocol<XMessage>public void reset()
Protocolpublic ExceptionInterceptor getExceptionInterceptor()
getExceptionInterceptor in interface Protocol<XMessage>getExceptionInterceptor in class AbstractProtocol<XMessage>public void changeDatabase(java.lang.String database)
changeDatabase in interface Protocol<XMessage>public boolean versionMeetsMinimum(int major,
int minor,
int subminor)
versionMeetsMinimum in interface Protocol<XMessage>public XMessage readMessage(XMessage reuse)
ProtocolreadMessage in interface Protocol<XMessage>reuse - Message instance to read into, may be nullpublic XMessage checkErrorMessage()
ProtocolcheckErrorMessage in interface Protocol<XMessage>public XMessage sendCommand(Message queryPacket, boolean skipCheck, int timeoutMillis)
ProtocolsendCommand in interface Protocol<XMessage>queryPacket - a packet pre-loaded with data for the protocol (eg.
from a client-side prepared statement). The first byte of
this packet is the MySQL protocol 'command' from MysqlDefsskipCheck - do not call checkErrorPacket() if truetimeoutMillis - timeoutpublic <T extends ProtocolEntity> T read(java.lang.Class<T> requiredClass, ProtocolEntityFactory<T,XMessage> protocolEntityFactory) throws java.io.IOException
public <T extends ProtocolEntity> T read(java.lang.Class<Resultset> requiredClass, int maxRows, boolean streamResults, XMessage resultPacket, boolean isBinaryEncoded, ColumnDefinition metadata, ProtocolEntityFactory<T,XMessage> protocolEntityFactory) throws java.io.IOException
Protocolread in interface Protocol<XMessage>T - object extending the ProtocolEntityrequiredClass - required Resultset classmaxRows - the maximum number of rows to read (-1 means all rows)streamResults - should the driver leave the results on the wire,
and read them only when needed?resultPacket - the first packet of information in the result setisBinaryEncoded - true if the binary protocol is used (for server prepared statements)metadata - use this metadata instead of the one provided on wireprotocolEntityFactory - ProtocolEntityFactory instanceProtocolEntity instancejava.io.IOException - if an error occurspublic void setLocalInfileInputStream(java.io.InputStream stream)
ProtocolsetLocalInfileInputStream in interface Protocol<XMessage>stream - input streampublic java.io.InputStream getLocalInfileInputStream()
ProtocolgetLocalInfileInputStream in interface Protocol<XMessage>public java.lang.String getQueryComment()
ProtocolgetQueryComment in interface Protocol<XMessage>public void setQueryComment(java.lang.String comment)
ProtocolsetQueryComment in interface Protocol<XMessage>comment - query comment stringpublic java.util.function.Supplier<ValueEncoder> getValueEncoderSupplier(java.lang.Object obj)
getValueEncoderSupplier in interface Protocol<XMessage>