Top Description Fields Constructors Methods
com.mysql.cj.protocol.x

public Class XProtocol

extends AbstractProtocol<XMessage>
implements Protocol<XMessage>
Class Inheritance
All Implemented Interfaces
com.mysql.cj.protocol.Protocol
Known Direct Subclasses
com.mysql.cj.xdevapi.ClientImpl.PooledXProtocol
Static Imports
java.util.stream.Collectors.toMap

Low-level interface to communications with X Plugin.

Field Summary

Modifier and TypeField and Description
private Map<String, Object>
private CompressionAlgorithm
private boolean
private String
private ResultStreamer
private String
private String
public String
private Closeable
managedResource

We take responsibility of the socket as the managed resource.

private Map<Class<? extends Message>, ProtocolEntityFactory<? extends ProtocolEntity, XMessage>>
private Map<Integer, PreparableStatement.PreparableStatementFinalizer>
private ReferenceQueue<PreparableStatement<?>>
private SequentialIdLease
private MessageReader<XMessageHeader, XMessage>
private static int
private int
private MessageSender<XMessage>
pack-priv XServerSession
private boolean
supportsPreparedStatements

Keeps track of whether this X Server session supports prepared statements.

pack-priv Boolean
Inherited from com.mysql.cj.protocol.AbstractProtocol:
authProviderexceptionInterceptorlogmessageBuilderpacketDebugRingBufferpropertySetqueryTimingUnitssessionsocketConnectiontransactionManageruseNanosForElapsedTime

Constructor Summary

AccessConstructor and Description
public
XProtocol(HostInfo hostInfo, PropertySet propertySet)

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
changeUser(String
DB user name
user
,
String
DB user password
password
,
String
database name
database
)

Implements com.mysql.cj.protocol.Protocol.changeUser.

Re-authenticates as the given user and password

public XMessage
checkErrorMessage()

Implements com.mysql.cj.protocol.Protocol.checkErrorMessage.

Read one message from the MySQL server, checks for errors in it, and if none, returns the message, ready for reading

public void
public void
public void
connect(String
DB user name
user
,
String
DB user password
password
,
String
database name
database
)

Implements com.mysql.cj.protocol.Protocol.connect.

Create a new session.

public void
drainRows()

Used only in tests

public boolean

Returns:

true if the exception was properly handled
failedPreparingStatement
(int
the id of the prepared statement that failed to prepare
preparedStatementId
,
XProtocolError e)

Informs this protocol instance that preparing a statement on the connected server failed.

public void
freePreparedStatementId(int
the prepared statement id to release
preparedStatementId
)

Frees a prepared statement id so that it can be reused.

private Map<String, CompressionAlgorithm>

Returns:

a map with all the supported compression algorithms, both natively supported and user configured.
getCompressionExtensions
(String
the value of the option 'xdevapi.compression-algorithm' containing a comma separated list of triplets with the format "algorithm-name:inflater-InputStream-class-name:deflater-OutputStream-class-name".
compressionExtensions
)

Parses and validates the value given for the connection option 'xdevapi.compression-extensions'.

private Map<String, String>
public ExceptionInterceptor
public InputStream
getLocalInfileInputStream()

Implements com.mysql.cj.protocol.Protocol.getLocalInfileInputStream.

Returns the InputStream instance that will be used to send data in response to a "LOAD DATA LOCAL INFILE" statement.

public int

Returns:

a new identifier to be used as prepared statement id
getNewPreparedStatementId
(PreparableStatement<?> preparableStatement)

Returns an id to be used as a client-managed prepared statement id. The method freePreparedStatementId(int) must be called when the prepared statement is deallocated so that the same id can be re-used.

public ServerSession
public Supplier<ValueEncoder>
public boolean
public boolean

Returns:

true if there are result rows
hasResults
()

Used only in tests

public void
public void
public boolean
public boolean
public void
negotiateCompression()

Negotiates compression capabilities with the server.

public void
protected void
newCommand()

Signal the intent to start processing a new command.

public <M extends Message, R extends QueryResult> R
query(M message, ResultBuilder<R> resultBuilder)

public <M extends Message, R extends QueryResult> CompletableFuture<R>
queryAsync(M message, ResultBuilder<R> resultBuilder)

public <T extends ProtocolEntity> T
read(Class<T> requiredClass, ProtocolEntityFactory<T, XMessage> protocolEntityFactory)

Implements com.mysql.cj.protocol.Protocol.read.

public <T extends ProtocolEntity> T
read(Class<Resultset>
required Resultset class
requiredClass
,
int
the maximum number of rows to read (-1 means all rows)
maxRows
,
boolean
should the driver leave the results on the wire, and read them only when needed?
streamResults
,
XMessage
the first packet of information in the result set
resultPacket
,
boolean
true if the binary protocol is used (for server prepared statements)
isBinaryEncoded
,
ColumnDefinition
use this metadata instead of the one provided on wire
metadata
,
ProtocolEntityFactory<T, XMessage> protocolEntityFactory)

Implements com.mysql.cj.protocol.Protocol.read.

Read protocol entity.

public byte[]
public void
public XMessage
readMessage(XMessage
Message instance to read into, may be null
reuse
)

Implements com.mysql.cj.protocol.Protocol.readMessage.

Read one message from the MySQL server into the reusable buffer if provided or into the new one.

public ColumnDefinition
public ColumnDefinition
readMetadata(Consumer<Notice> noticeConsumer)

public ColumnDefinition
readMetadata(Field f, Consumer<Notice> noticeConsumer)

public <T extends QueryResult> T
readQueryResult(ResultBuilder<T>
ResultBuilder instance
resultBuilder
)

Implements com.mysql.cj.protocol.Protocol.readQueryResult.

Read messages from server and deliver them to resultBuilder.

public XProtocolRow
readRowOrNull(ColumnDefinition metadata, Consumer<Notice> noticeConsumer)

public ServerCapabilities

Returns:

capabilities mapped by name
readServerCapabilities
()

Implements com.mysql.cj.protocol.Protocol.readServerCapabilities.

Get the capabilities from the server.

public boolean

Returns:

true if enough executions have been done since last time a prepared statement failed to prepare
readyForPreparingStatements
()

Checks if enough statements have been executed in this MySQL server so that another prepare statement attempt should be done.

public void
reset()

Overrides com.mysql.cj.protocol.AbstractProtocol.reset.

Implements com.mysql.cj.protocol.Protocol.reset.

Return Protocol to its initial state right after successful connect.

public void
send(Message
Message instance
message
,
int
length of header + payload
packetLen
)

Implements com.mysql.cj.protocol.Protocol.send.

public void
sendCapabilities(Map<String, Object>
capabilities name/value map
keyValuePair
)

Set client capabilities of current session.

public XMessage
sendCommand(Message
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 MysqlDefs
queryPacket
,
boolean
do not call checkErrorPacket() if true
skipCheck
,
int
timeout
timeoutMillis
)

Implements com.mysql.cj.protocol.Protocol.sendCommand.

Send a command to the MySQL server.

public void
setLocalInfileInputStream(InputStream
input stream
stream
)

Implements com.mysql.cj.protocol.Protocol.setLocalInfileInputStream.

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.

public void
setMaxAllowedPacket(int maxAllowedPacket)

public boolean

Returns:

true if the MySQL server currently connected supports prepared statements.
supportsPreparedStatements
()

Checks if the MySQL server currently connected supports prepared statements.

public boolean
versionMeetsMinimum(int major, int minor, int subminor)

Implements com.mysql.cj.protocol.Protocol.versionMeetsMinimum.

Inherited from com.mysql.cj.protocol.AbstractProtocol:
addListenergetAuthenticationProvidergetMessageBuildergetPacketReceivedTimeHoldergetPacketSentTimeHoldergetPropertySetgetQueryTimingUnitsgetSocketConnectioninvokeListenersremoveListenersetPacketReceivedTimeHoldersetPacketSentTimeHoldersetPropertySet

Field Detail

clientCapabilitiesback to summary
private Map<String, Object> clientCapabilities
compressionAlgorithmback to summary
private CompressionAlgorithm compressionAlgorithm
compressionEnabledback to summary
private boolean compressionEnabled
currDatabaseback to summary
private String currDatabase
currentResultStreamerback to summary
private ResultStreamer currentResultStreamer
currPasswordback to summary
private String currPassword
currUserback to summary
private String currUser
defaultSchemaNameback to summary
public String defaultSchemaName
managedResourceback to summary
private Closeable managedResource

We take responsibility of the socket as the managed resource. We close it when we're done.

messageToProtocolEntityFactoryback to summary
private Map<Class<? extends Message>, ProtocolEntityFactory<? extends ProtocolEntity, XMessage>> messageToProtocolEntityFactory
preparableStatementFinalizerReferencesback to summary
private Map<Integer, PreparableStatement.PreparableStatementFinalizer> preparableStatementFinalizerReferences
preparableStatementRefQueueback to summary
private ReferenceQueue<PreparableStatement<?>> preparableStatementRefQueue
preparedStatementIdsback to summary
private SequentialIdLease preparedStatementIds
readerback to summary
private MessageReader<XMessageHeader, XMessage> reader
RETRY_PREPARE_STATEMENT_COUNTDOWNback to summary
private static int RETRY_PREPARE_STATEMENT_COUNTDOWN
retryPrepareStatementCountdownback to summary
private int retryPrepareStatementCountdown
senderback to summary
private MessageSender<XMessage> sender
serverSessionback to summary
pack-priv XServerSession serverSession
supportsPreparedStatementsback to summary
private boolean supportsPreparedStatements

Keeps track of whether this X Server session supports prepared statements. True by default until first failure of a statement prepare.

useSessionResetKeepOpenback to summary
pack-priv Boolean useSessionResetKeepOpen

Constructor Detail

XProtocolback to summary
public XProtocol(HostInfo hostInfo, PropertySet propertySet)

Method Detail

afterHandshakeback to summary
public void afterHandshake()

Implements com.mysql.cj.protocol.Protocol.afterHandshake.

Annotations
@Override
beforeHandshakeback to summary
public void beforeHandshake()

Implements com.mysql.cj.protocol.Protocol.beforeHandshake.

Annotations
@Override
changeDatabaseback to summary
public void changeDatabase(String database)

Implements com.mysql.cj.protocol.Protocol.changeDatabase.

Annotations
@Override
changeUserback to summary
public void changeUser(String user, String password, String database)

Implements com.mysql.cj.protocol.Protocol.changeUser.

Doc from com.mysql.cj.protocol.Protocol.changeUser.

Re-authenticates as the given user and password

Parameters
user:String

DB user name

password:String

DB user password

database:String

database name

Annotations
@Override
checkErrorMessageback to summary
public XMessage checkErrorMessage()

Implements com.mysql.cj.protocol.Protocol.checkErrorMessage.

Doc from com.mysql.cj.protocol.Protocol.checkErrorMessage.

Read one message from the MySQL server, checks for errors in it, and if none, returns the message, ready for reading

Returns:XMessage

a message ready for reading.

Annotations
@Override
closeback to summary
public void close() throws IOException

Implements com.mysql.cj.protocol.Protocol.close.

Annotations
@Override
configureTimeZoneback to summary
public void configureTimeZone()

Implements com.mysql.cj.protocol.Protocol.configureTimeZone.

Annotations
@Override
connectback to summary
public void connect(String user, String password, String database)

Implements com.mysql.cj.protocol.Protocol.connect.

Doc from com.mysql.cj.protocol.Protocol.connect.

Create a new session. This generally happens once at the beginning of a connection.

Parameters
user:String

DB user name

password:String

DB user password

database:String

database name

Annotations
@Override
drainRowsback to summary
public void drainRows()

Used only in tests

failedPreparingStatementback to summary
public boolean failedPreparingStatement(int preparedStatementId, XProtocolError e)

Informs this protocol instance that preparing a statement on the connected server failed.

Parameters
preparedStatementId:int

the id of the prepared statement that failed to prepare

e:XProtocolError

XProtocolError

Returns:boolean

true if the exception was properly handled

freePreparedStatementIdback to summary
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.

Parameters
preparedStatementId:int

the prepared statement id to release

getCompressionExtensionsback to summary
private Map<String, CompressionAlgorithm> getCompressionExtensions(String compressionExtensions)

Parses and validates the value given for the connection option 'xdevapi.compression-extensions'. With the information obtained, creates a map of supported compression algorithms.

Parameters
compressionExtensions:String

the value of the option 'xdevapi.compression-algorithm' containing a comma separated list of triplets with the format "algorithm-name:inflater-InputStream-class-name:deflater-OutputStream-class-name".

Returns:Map<String, CompressionAlgorithm>

a map with all the supported compression algorithms, both natively supported and user configured.

getConnectionAttributesMapback to summary
private Map<String, String> getConnectionAttributesMap(String attStr)
getExceptionInterceptorback to summary
public ExceptionInterceptor getExceptionInterceptor()

Overrides com.mysql.cj.protocol.AbstractProtocol.getExceptionInterceptor.

Implements com.mysql.cj.protocol.Protocol.getExceptionInterceptor.

Annotations
@Override
getLocalInfileInputStreamback to summary
public InputStream getLocalInfileInputStream()

Implements com.mysql.cj.protocol.Protocol.getLocalInfileInputStream.

Doc from com.mysql.cj.protocol.Protocol.getLocalInfileInputStream.

Returns 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().

Returns:InputStream

input stream

Annotations
@Override
getNewPreparedStatementIdback to summary
public int getNewPreparedStatementId(PreparableStatement<?> preparableStatement)

Returns an id to be used as a client-managed prepared statement id. The method freePreparedStatementId(int) must be called when the prepared statement is deallocated so that the same id can be re-used.

Parameters
preparableStatement:PreparableStatement<?>

PreparableStatement

Returns:int

a new identifier to be used as prepared statement id

getServerSessionback to summary
public ServerSession getServerSession()

Implements com.mysql.cj.protocol.Protocol.getServerSession.

Annotations
@Override
getValueEncoderSupplierback to summary
public Supplier<ValueEncoder> getValueEncoderSupplier(Object obj)

Implements com.mysql.cj.protocol.Protocol.getValueEncoderSupplier.

Annotations
@Override
hasMoreResultsback to summary
public boolean hasMoreResults()
hasResultsback to summary
public boolean hasResults()

Used only in tests

Returns:boolean

true if there are result rows

initback to summary
public void init(Session sess, SocketConnection socketConn, PropertySet propSet, TransactionEventHandler trManager)

Overrides com.mysql.cj.protocol.AbstractProtocol.init.

Implements com.mysql.cj.protocol.Protocol.init.

Doc from com.mysql.cj.protocol.Protocol.init.

Init method takes the place of constructor. A constructor should be used unless the encapsulation of ProtocolFactory is necessary.

Parameters
sess:Session

Session

socketConn:SocketConnection

SocketConnection

propSet:PropertySet

PropertySet

trManager:TransactionEventHandler

TransactionEventHandler

Annotations
@Override
initServerSessionback to summary
public void initServerSession()

Implements com.mysql.cj.protocol.Protocol.initServerSession.

Annotations
@Override
isOpenback to summary
public boolean isOpen()
isSqlResultPendingback to summary
public boolean isSqlResultPending()
negotiateCompressionback to summary
public void negotiateCompression()

Negotiates compression capabilities with the server.

negotiateSSLConnectionback to summary
public void negotiateSSLConnection()

Implements com.mysql.cj.protocol.Protocol.negotiateSSLConnection.

Annotations
@Override
newCommandback to summary
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.

queryback to summary
public <M extends Message, R extends QueryResult> R query(M message, ResultBuilder<R> resultBuilder)
queryAsyncback to summary
public <M extends Message, R extends QueryResult> CompletableFuture<R> queryAsync(M message, ResultBuilder<R> resultBuilder)
readback to summary
public <T extends ProtocolEntity> T read(Class<T> requiredClass, ProtocolEntityFactory<T, XMessage> protocolEntityFactory) throws IOException

Implements com.mysql.cj.protocol.Protocol.read.

Annotations
@Override
readback to summary
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

Implements com.mysql.cj.protocol.Protocol.read.

Doc from com.mysql.cj.protocol.Protocol.read.

Read protocol entity.

Parameters
<T>
object extending the ProtocolEntity
requiredClass:Class<Resultset>

required Resultset class

maxRows:int

the maximum number of rows to read (-1 means all rows)

streamResults:boolean

should the driver leave the results on the wire, and read them only when needed?

resultPacket:XMessage

the first packet of information in the result set

isBinaryEncoded:boolean

true if the binary protocol is used (for server prepared statements)

metadata:ColumnDefinition

use this metadata instead of the one provided on wire

protocolEntityFactory:ProtocolEntityFactory<T, XMessage>

ProtocolEntityFactory instance

Returns:T

ProtocolEntity instance

Annotations
@Override
Exceptions
IOException:
if an error occurs
readAuthenticateContinueback to summary
public byte[] readAuthenticateContinue()
readAuthenticateOkback to summary
public void readAuthenticateOk()
readMessageback to summary
public XMessage readMessage(XMessage reuse)

Implements com.mysql.cj.protocol.Protocol.readMessage.

Doc from com.mysql.cj.protocol.Protocol.readMessage.

Read one message from the MySQL server into the reusable buffer if provided or into the new one.

Parameters
reuse:XMessage

Message instance to read into, may be null

Returns:XMessage

the message from the server.

Annotations
@Override
readMetadataback to summary
public ColumnDefinition readMetadata()

Implements com.mysql.cj.protocol.Protocol.readMetadata.

Annotations
@Override
readMetadataback to summary
public ColumnDefinition readMetadata(Consumer<Notice> noticeConsumer)
readMetadataback to summary
public ColumnDefinition readMetadata(Field f, Consumer<Notice> noticeConsumer)
readQueryResultback to summary
public <T extends QueryResult> T readQueryResult(ResultBuilder<T> resultBuilder)

Implements com.mysql.cj.protocol.Protocol.readQueryResult.

Doc from com.mysql.cj.protocol.Protocol.readQueryResult.

Read messages from server and deliver them to resultBuilder.

Parameters
<T>
result type
resultBuilder:ResultBuilder<T>

ResultBuilder instance

Returns:T

QueryResult

Annotations
@Override
readRowOrNullback to summary
public XProtocolRow readRowOrNull(ColumnDefinition metadata, Consumer<Notice> noticeConsumer)
readServerCapabilitiesback to summary
public ServerCapabilities readServerCapabilities()

Implements com.mysql.cj.protocol.Protocol.readServerCapabilities.

Get the capabilities from the server.

Note

This must be called before authentication.

Returns:ServerCapabilities

capabilities mapped by name

Annotations
@Override
readyForPreparingStatementsback to summary
public boolean readyForPreparingStatements()

Checks if enough statements have been executed in this MySQL server so that another prepare statement attempt should be done.

Returns:boolean

true if enough executions have been done since last time a prepared statement failed to prepare

resetback to summary
public void reset()

Overrides com.mysql.cj.protocol.AbstractProtocol.reset.

Implements com.mysql.cj.protocol.Protocol.reset.

Doc from com.mysql.cj.protocol.Protocol.reset.

Return Protocol to its initial state right after successful connect.

Annotations
@Override
sendback to summary
public void send(Message message, int packetLen)

Implements com.mysql.cj.protocol.Protocol.send.

Parameters
message:Message

Doc from com.mysql.cj.protocol.Protocol.send.

Message instance

packetLen:int

Doc from com.mysql.cj.protocol.Protocol.send.

length of header + payload

Annotations
@Override
sendCapabilitiesback to summary
public void sendCapabilities(Map<String, Object> keyValuePair)

Set client capabilities of current session. Must be done before authentication (changeUser(String, String, String)).

Parameters
keyValuePair:Map<String, Object>

capabilities name/value map

sendCommandback to summary
public XMessage sendCommand(Message queryPacket, boolean skipCheck, int timeoutMillis)

Implements com.mysql.cj.protocol.Protocol.sendCommand.

Doc from com.mysql.cj.protocol.Protocol.sendCommand.

Send a command to the MySQL server.

Parameters
queryPacket:Message

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 MysqlDefs

skipCheck:boolean

do not call checkErrorPacket() if true

timeoutMillis:int

timeout

Returns:XMessage

the response packet from the server

Annotations
@Override
setLocalInfileInputStreamback to summary
public void setLocalInfileInputStream(InputStream stream)

Implements com.mysql.cj.protocol.Protocol.setLocalInfileInputStream.

Doc from com.mysql.cj.protocol.Protocol.setLocalInfileInputStream.

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. 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.

Parameters
stream:InputStream

input stream

Annotations
@Override
setMaxAllowedPacketback to summary
public void setMaxAllowedPacket(int maxAllowedPacket)
supportsPreparedStatementsback to summary
public boolean supportsPreparedStatements()

Checks if the MySQL server currently connected supports prepared statements.

Returns:boolean

true if the MySQL server currently connected supports prepared statements.

versionMeetsMinimumback to summary
public boolean versionMeetsMinimum(int major, int minor, int subminor)

Implements com.mysql.cj.protocol.Protocol.versionMeetsMinimum.

Annotations
@Override