类 XProtocol
- java.lang.Object
-
- com.mysql.cj.protocol.AbstractProtocol<XMessage>
-
- com.mysql.cj.protocol.x.XProtocol
-
- 所有已实现的接口:
Protocol<XMessage>,Protocol.ProtocolEventHandler
- 直接已知子类:
ClientImpl.PooledXProtocol
public class XProtocol extends AbstractProtocol<XMessage> implements Protocol<XMessage>
Low-level interface to communications with X Plugin.
-
-
嵌套类概要
-
从接口继承的嵌套类/接口 com.mysql.cj.protocol.Protocol
Protocol.ProtocolEventHandler, Protocol.ProtocolEventListener
-
-
字段概要
字段 修饰符和类型 字段 说明 StringdefaultSchemaName-
从类继承的字段 com.mysql.cj.protocol.AbstractProtocol
authProvider, exceptionInterceptor, log, messageBuilder, packetDebugRingBuffer, propertySet, queryTimingUnits, session, socketConnection, transactionManager, useNanosForElapsedTime
-
-
构造器概要
构造器 构造器 说明 XProtocol(HostInfo hostInfo, PropertySet propertySet)
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterHandshake()voidbeforeHandshake()voidchangeDatabase(String database)voidchangeUser(String user, String password, String database)Re-authenticates as the given user and passwordXMessagecheckErrorMessage()Read one message from the MySQL server, checks for errors in it, and if none, returns the message, ready for readingvoidclose()voidconfigureTimeZone()voidconnect(String user, String password, String database)Create a new session.voiddrainRows()Used only in testsbooleanfailedPreparingStatement(int preparedStatementId, XProtocolError e)Informs this protocol instance that preparing a statement on the connected server failed.voidfreePreparedStatementId(int preparedStatementId)Frees a prepared statement id so that it can be reused.ExceptionInterceptorgetExceptionInterceptor()InputStreamgetLocalInfileInputStream()Returns the InputStream instance that will be used to send data in response to a "LOAD DATA LOCAL INFILE" statement.intgetNewPreparedStatementId(PreparableStatement<?> preparableStatement)Returns an id to be used as a client-managed prepared statement id.StringgetQueryComment()Returns the comment that will be prepended to all statements sent to the server.ServerSessiongetServerSession()java.util.function.Supplier<ValueEncoder>getValueEncoderSupplier(Object obj)booleanhasMoreResults()booleanhasResults()Used only in testsvoidinit(Session sess, SocketConnection socketConn, PropertySet propSet, TransactionEventHandler trManager)Init method takes the place of constructor.voidinitServerSession()booleanisOpen()booleanisSqlResultPending()voidnegotiateCompression()Negotiates compression capabilities with the server.voidnegotiateSSLConnection()protected voidnewCommand()Signal the intent to start processing a new command.<M extends Message,R extends QueryResult>
Rquery(M message, ResultBuilder<R> resultBuilder)<M extends Message,R extends QueryResult>
CompletableFuture<R>queryAsync(M message, ResultBuilder<R> resultBuilder)<T extends ProtocolEntity>
Tread(Class<Resultset> requiredClass, int maxRows, boolean streamResults, XMessage resultPacket, boolean isBinaryEncoded, ColumnDefinition metadata, ProtocolEntityFactory<T,XMessage> protocolEntityFactory)Read protocol entity.<T extends ProtocolEntity>
Tread(Class<T> requiredClass, ProtocolEntityFactory<T,XMessage> protocolEntityFactory)byte[]readAuthenticateContinue()voidreadAuthenticateOk()XMessagereadMessage(XMessage reuse)Read one message from the MySQL server into the reusable buffer if provided or into the new one.ColumnDefinitionreadMetadata()ColumnDefinitionreadMetadata(Field f, java.util.function.Consumer<Notice> noticeConsumer)ColumnDefinitionreadMetadata(java.util.function.Consumer<Notice> noticeConsumer)<T extends QueryResult>
TreadQueryResult(ResultBuilder<T> resultBuilder)Read messages from server and deliver them to resultBuilder.XProtocolRowreadRowOrNull(ColumnDefinition metadata, java.util.function.Consumer<Notice> noticeConsumer)ServerCapabilitiesreadServerCapabilities()Get the capabilities from the server.booleanreadyForPreparingStatements()Checks if enough statements have been executed in this MySQL server so that another prepare statement attempt should be done.voidreset()Return Protocol to its initial state right after successful connect.voidsend(Message message, int packetLen)voidsendCapabilities(Map<String,Object> keyValuePair)Set client capabilities of current session.XMessagesendCommand(Message queryPacket, boolean skipCheck, int timeoutMillis)Send a command to the MySQL server.voidsetLocalInfileInputStream(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.voidsetMaxAllowedPacket(int maxAllowedPacket)voidsetQueryComment(String comment)Sets the comment that will be prepended to all statements sent to the server.booleansupportsPreparedStatements()Checks if the MySQL server currently connected supports prepared statements.booleanversionMeetsMinimum(int major, int minor, int subminor)-
从类继承的方法 com.mysql.cj.protocol.AbstractProtocol
addListener, getAuthenticationProvider, getMessageBuilder, getPacketReceivedTimeHolder, getPacketSentTimeHolder, getPropertySet, getQueryTimingUnits, getSocketConnection, invokeListeners, removeListener, setPacketReceivedTimeHolder, setPacketSentTimeHolder, setPropertySet
-
-
-
-
字段详细资料
-
defaultSchemaName
public String defaultSchemaName
-
-
构造器详细资料
-
XProtocol
public XProtocol(HostInfo hostInfo, PropertySet propertySet)
-
-
方法详细资料
-
init
public void init(Session sess, SocketConnection socketConn, PropertySet propSet, TransactionEventHandler trManager)
从接口复制的说明:ProtocolInit method takes the place of constructor. A constructor should be used unless the encapsulation of ProtocolFactory is necessary.- 指定者:
init在接口中Protocol<XMessage>- 覆盖:
init在类中AbstractProtocol<XMessage>- 参数:
sess-SessionsocketConn-SocketConnectionpropSet-PropertySettrManager-TransactionEventHandler
-
getServerSession
public ServerSession getServerSession()
- 指定者:
getServerSession在接口中Protocol<XMessage>
-
sendCapabilities
public void sendCapabilities(Map<String,Object> keyValuePair)
Set client capabilities of current session. Must be done before authentication (changeUser(String, String, String)).- 参数:
keyValuePair- capabilities name/value map
-
negotiateSSLConnection
public void negotiateSSLConnection()
- 指定者:
negotiateSSLConnection在接口中Protocol<XMessage>
-
negotiateCompression
public void negotiateCompression()
Negotiates compression capabilities with the server.
-
beforeHandshake
public void beforeHandshake()
- 指定者:
beforeHandshake在接口中Protocol<XMessage>
-
connect
public void connect(String user, String password, String database)
从接口复制的说明:ProtocolCreate a new session. This generally happens once at the beginning of a connection.
-
changeUser
public void changeUser(String user, String password, String database)
从接口复制的说明:ProtocolRe-authenticates as the given user and password- 指定者:
changeUser在接口中Protocol<XMessage>- 参数:
user- DB user namepassword- DB user passworddatabase- database name
-
afterHandshake
public void afterHandshake()
- 指定者:
afterHandshake在接口中Protocol<XMessage>
-
configureTimeZone
public void configureTimeZone()
- 指定者:
configureTimeZone在接口中Protocol<XMessage>
-
initServerSession
public void initServerSession()
- 指定者:
initServerSession在接口中Protocol<XMessage>
-
readAuthenticateOk
public void readAuthenticateOk()
-
readAuthenticateContinue
public byte[] readAuthenticateContinue()
-
hasMoreResults
public boolean hasMoreResults()
-
readQueryResult
public <T extends QueryResult> T readQueryResult(ResultBuilder<T> resultBuilder)
从接口复制的说明:ProtocolRead messages from server and deliver them to resultBuilder.- 指定者:
readQueryResult在接口中Protocol<XMessage>- 类型参数:
T- result type- 参数:
resultBuilder-ResultBuilderinstance- 返回:
QueryResult
-
hasResults
public boolean hasResults()
Used only in tests- 返回:
- true if there are result rows
-
drainRows
public void drainRows()
Used only in tests
-
readMetadata
public ColumnDefinition readMetadata()
- 指定者:
readMetadata在接口中Protocol<XMessage>
-
readMetadata
public ColumnDefinition readMetadata(java.util.function.Consumer<Notice> noticeConsumer)
-
readMetadata
public ColumnDefinition readMetadata(Field f, java.util.function.Consumer<Notice> noticeConsumer)
-
readRowOrNull
public XProtocolRow readRowOrNull(ColumnDefinition metadata, java.util.function.Consumer<Notice> noticeConsumer)
-
supportsPreparedStatements
public boolean supportsPreparedStatements()
Checks if the MySQL server currently connected supports prepared statements.- 返回:
trueif the MySQL server currently connected supports prepared statements.
-
readyForPreparingStatements
public boolean readyForPreparingStatements()
Checks if enough statements have been executed in this MySQL server so that another prepare statement attempt should be done.- 返回:
trueif enough executions have been done since last time a prepared statement failed to prepare
-
getNewPreparedStatementId
public int getNewPreparedStatementId(PreparableStatement<?> preparableStatement)
Returns an id to be used as a client-managed prepared statement id. The methodfreePreparedStatementId(int)must be called when the prepared statement is deallocated so that the same id can be re-used.- 参数:
preparableStatement-PreparableStatement- 返回:
- a new identifier to be used as prepared statement id
-
freePreparedStatementId
public void freePreparedStatementId(int preparedStatementId)
Frees a prepared statement id so that it can be reused. Note that freeing an id from an active prepared statement will result in a statement prepare conflict next time one gets prepared with the same released id.- 参数:
preparedStatementId- the prepared statement id to release
-
failedPreparingStatement
public boolean failedPreparingStatement(int preparedStatementId, XProtocolError e)Informs this protocol instance that preparing a statement on the connected server failed.- 参数:
preparedStatementId- the id of the prepared statement that failed to preparee-XProtocolError- 返回:
trueif the exception was properly handled
-
newCommand
protected void newCommand()
Signal the intent to start processing a new command. A session supports processing a single command at a time. Results are read lazily from the wire. It is necessary to flush any pending result before starting a new command. This method performs the flush if necessary.
-
query
public <M extends Message,R extends QueryResult> R query(M message, ResultBuilder<R> resultBuilder)
-
queryAsync
public <M extends Message,R extends QueryResult> CompletableFuture<R> queryAsync(M message, ResultBuilder<R> resultBuilder)
-
isOpen
public boolean isOpen()
-
close
public void close() throws IOException- 指定者:
close在接口中Protocol<XMessage>- 抛出:
IOException
-
isSqlResultPending
public boolean isSqlResultPending()
-
setMaxAllowedPacket
public void setMaxAllowedPacket(int maxAllowedPacket)
-
send
public void send(Message message, int packetLen)
-
readServerCapabilities
public ServerCapabilities readServerCapabilities()
Get the capabilities from the server.NOTE: This must be called before authentication.
- 指定者:
readServerCapabilities在接口中Protocol<XMessage>- 返回:
- capabilities mapped by name
-
reset
public void reset()
从接口复制的说明:ProtocolReturn Protocol to its initial state right after successful connect.
-
getExceptionInterceptor
public ExceptionInterceptor getExceptionInterceptor()
- 指定者:
getExceptionInterceptor在接口中Protocol<XMessage>- 覆盖:
getExceptionInterceptor在类中AbstractProtocol<XMessage>
-
changeDatabase
public void changeDatabase(String database)
- 指定者:
changeDatabase在接口中Protocol<XMessage>
-
versionMeetsMinimum
public boolean versionMeetsMinimum(int major, int minor, int subminor)- 指定者:
versionMeetsMinimum在接口中Protocol<XMessage>
-
readMessage
public XMessage readMessage(XMessage reuse)
从接口复制的说明:ProtocolRead one message from the MySQL server into the reusable buffer if provided or into the new one.- 指定者:
readMessage在接口中Protocol<XMessage>- 参数:
reuse-Messageinstance to read into, may be null- 返回:
- the message from the server.
-
checkErrorMessage
public XMessage checkErrorMessage()
从接口复制的说明:ProtocolRead one message from the MySQL server, checks for errors in it, and if none, returns the message, ready for reading- 指定者:
checkErrorMessage在接口中Protocol<XMessage>- 返回:
- a message ready for reading.
-
sendCommand
public XMessage sendCommand(Message queryPacket, boolean skipCheck, int timeoutMillis)
从接口复制的说明:ProtocolSend a command to the MySQL server.- 指定者:
sendCommand在接口中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- timeout- 返回:
- the response packet from the server
-
read
public <T extends ProtocolEntity> T read(Class<T> requiredClass, ProtocolEntityFactory<T,XMessage> protocolEntityFactory) throws IOException
- 指定者:
read在接口中Protocol<XMessage>- 抛出:
IOException
-
read
public <T extends ProtocolEntity> T read(Class<Resultset> requiredClass, int maxRows, boolean streamResults, XMessage resultPacket, boolean isBinaryEncoded, ColumnDefinition metadata, ProtocolEntityFactory<T,XMessage> protocolEntityFactory) throws IOException
从接口复制的说明:ProtocolRead protocol entity.- 指定者:
read在接口中Protocol<XMessage>- 类型参数:
T- object extending theProtocolEntity- 参数:
requiredClass- 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-ProtocolEntityFactoryinstance- 返回:
ProtocolEntityinstance- 抛出:
IOException- if an error occurs
-
setLocalInfileInputStream
public void setLocalInfileInputStream(InputStream stream)
从接口复制的说明:ProtocolSets 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. This stream will be read to completion upon execution of a "LOAD DATA LOCAL INFILE" statement, and will automatically be closed by the driver, so it needs to be reset before each call to execute*() that would cause the MySQL server to request data to fulfill the request for "LOAD DATA LOCAL INFILE". If this value is set to NULL, the driver will revert to using a FileInputStream or URLInputStream as required.- 指定者:
setLocalInfileInputStream在接口中Protocol<XMessage>- 参数:
stream- input stream
-
getLocalInfileInputStream
public InputStream getLocalInfileInputStream()
从接口复制的说明:ProtocolReturns the InputStream instance that will be used to send data in response to a "LOAD DATA LOCAL INFILE" statement. This method returns NULL if no such stream has been set via setLocalInfileInputStream().- 指定者:
getLocalInfileInputStream在接口中Protocol<XMessage>- 返回:
- input stream
-
getQueryComment
public String getQueryComment()
从接口复制的说明:ProtocolReturns the comment that will be prepended to all statements sent to the server.- 指定者:
getQueryComment在接口中Protocol<XMessage>- 返回:
- query comment string
-
setQueryComment
public void setQueryComment(String comment)
从接口复制的说明:ProtocolSets the comment that will be prepended to all statements sent to the server. Do not use slash-star or star-slash tokens in the comment as these will be added by the driver itself.- 指定者:
setQueryComment在接口中Protocol<XMessage>- 参数:
comment- query comment string
-
getValueEncoderSupplier
public java.util.function.Supplier<ValueEncoder> getValueEncoderSupplier(Object obj)
- 指定者:
getValueEncoderSupplier在接口中Protocol<XMessage>
-
-