|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mysql.jdbc.MysqlIO
class MysqlIO
This class is used by Connection for communicating with the MySQL server.
Connection
Field Summary | |
---|---|
protected static int |
AUTH_411_OVERHEAD
|
protected static int |
CLIENT_CONNECT_WITH_DB
|
protected static int |
CLIENT_RESERVED
|
protected static int |
CLIENT_SECURE_CONNECTION
|
protected static int |
CLIENT_SSL
|
protected long |
clientParam
|
protected static int |
COMP_HEADER_LENGTH
|
protected ConnectionImpl |
connection
|
protected static int |
HEADER_LENGTH
|
protected java.lang.String |
host
|
protected static int |
INITIAL_PACKET_SIZE
|
protected long |
lastPacketReceivedTimeMs
|
protected long |
lastPacketSentTimeMs
|
protected static int |
MAX_QUERY_SIZE_TO_EXPLAIN
|
protected static int |
MAX_QUERY_SIZE_TO_LOG
|
protected int |
maxThreeBytes
|
protected static int |
MIN_COMPRESS_LEN
|
protected java.net.Socket |
mysqlConnection
The connection to the server |
protected java.io.InputStream |
mysqlInput
|
protected java.io.BufferedOutputStream |
mysqlOutput
Data to the server |
protected static int |
NULL_LENGTH
|
protected int |
port
|
protected java.lang.String |
seed
|
(package private) static int |
SERVER_MORE_RESULTS_EXISTS
|
protected int |
serverCapabilities
|
protected int |
serverCharsetIndex
|
protected static java.lang.String |
ZERO_DATE_VALUE_MARKER
We need to have a 'marker' for all-zero datetimes so that ResultSet can decide what to do based on connection setting |
protected static java.lang.String |
ZERO_DATETIME_VALUE_MARKER
|
Constructor Summary | |
---|---|
MysqlIO(java.lang.String host,
int port,
java.util.Properties props,
java.lang.String socketFactoryClassName,
ConnectionImpl conn,
int socketTimeout,
int useBufferRowSizeThreshold)
Constructor: Connect to the MySQL server and setup a stream connection. |
Method Summary | |
---|---|
protected void |
changeUser(java.lang.String userName,
java.lang.String password,
java.lang.String database)
Re-authenticates as the given user and password |
protected Buffer |
checkErrorPacket()
Checks for errors in the reply packet, and if none, returns the reply packet, ready for reading |
protected void |
checkForCharsetMismatch()
Determines if the database charset is the same as the platform charset |
protected void |
clearInputStream()
|
(package private) void |
closeStreamer(RowData streamer)
|
(package private) void |
disableMultiQueries()
|
(package private) void |
doHandshake(java.lang.String user,
java.lang.String password,
java.lang.String database)
Initialize communications with the MySQL server. |
protected void |
dumpPacketRingBuffer()
|
(package private) void |
enableMultiQueries()
|
protected void |
explainSlowQuery(byte[] querySQL,
java.lang.String truncatedQuery)
Runs an 'EXPLAIN' on the given query and dumps the results to the log |
protected java.util.List |
fetchRowsViaCursor(java.util.List fetchedRows,
long statementId,
Field[] columnTypes,
int fetchSize,
boolean useBufferRowExplicit)
|
protected void |
forceClose()
Forcibly closes the underlying socket to MySQL. |
protected int |
getCommandCount()
|
protected long |
getCurrentTimeNanosOrMillis()
|
protected ExceptionInterceptor |
getExceptionInterceptor()
|
(package private) java.lang.String |
getHost()
Returns the host this IO is connected to |
protected long |
getLastPacketReceivedTimeMs()
|
protected long |
getLastPacketSentTimeMs()
DOCUMENT ME! |
(package private) static int |
getMaxBuf()
|
protected java.lang.String |
getQueryTimingUnits()
|
protected ResultSetImpl |
getResultSet(StatementImpl callingStatement,
long columnCount,
int maxRows,
int resultSetType,
int resultSetConcurrency,
boolean streamResults,
java.lang.String catalog,
boolean isBinaryEncoded,
Field[] metadataFromCache)
Build a result set. |
(package private) int |
getServerMajorVersion()
Get the major version of the MySQL server we are talking to. |
(package private) int |
getServerMinorVersion()
Get the minor version of the MySQL server we are talking to. |
protected int |
getServerStatus()
|
(package private) int |
getServerSubMinorVersion()
Get the sub-minor version of the MySQL server we are talking to. |
(package private) java.lang.String |
getServerVersion()
Get the version string of the server we are talking to |
(package private) Buffer |
getSharedSendPacket()
Returns the packet used for sending data (used by PreparedStatement) Guarded by external synchronization on a mutex. |
protected long |
getSlowQueryThreshold()
|
protected long |
getThreadId()
|
(package private) boolean |
hadWarnings()
|
boolean |
hasLongColumnInfo()
Does the server send back extra column info? |
protected boolean |
inTransactionOnServer()
|
(package private) ResultSetInternalMethods |
invokeStatementInterceptorsPost(java.lang.String sql,
Statement interceptedStatement,
ResultSetInternalMethods originalResultSet,
boolean forceExecute,
java.sql.SQLException statementException)
|
(package private) ResultSetInternalMethods |
invokeStatementInterceptorsPre(java.lang.String sql,
Statement interceptedStatement,
boolean forceExecute)
|
protected boolean |
isDataAvailable()
|
protected boolean |
isSetNeededForAutoCommitMode(boolean autoCommitFlag)
|
(package private) boolean |
isVersion(int major,
int minor,
int subminor)
Is the version of the MySQL server we are connected to the given version? |
(package private) ResultSetRow |
nextRow(Field[] fields,
int columnCount,
boolean isBinaryEncoded,
int resultSetConcurrency,
boolean useBufferRowIfPossible,
boolean useBufferRowExplicit,
boolean canReuseRowPacketForBufferRow,
Buffer existingRowPacket)
Retrieve one row from the MySQL server. |
(package private) ResultSetRow |
nextRowFast(Field[] fields,
int columnCount,
boolean isBinaryEncoded,
int resultSetConcurrency,
boolean useBufferRowIfPossible,
boolean useBufferRowExplicit,
boolean canReuseRowPacket)
|
(package private) void |
quit()
Log-off of the MySQL server and close the socket. |
(package private) ResultSetImpl |
readAllResults(StatementImpl callingStatement,
int maxRows,
int resultSetType,
int resultSetConcurrency,
boolean streamResults,
java.lang.String catalog,
Buffer resultPacket,
boolean isBinaryEncoded,
long preSentColumnCount,
Field[] metadataFromCache)
|
protected Buffer |
readPacket()
Read one packet from the MySQL server |
protected ResultSetImpl |
readResultsForQueryOrUpdate(StatementImpl callingStatement,
int maxRows,
int resultSetType,
int resultSetConcurrency,
boolean streamResults,
java.lang.String catalog,
Buffer resultPacket,
boolean isBinaryEncoded,
long preSentColumnCount,
Field[] metadataFromCache)
Reads one result set off of the wire, if the result is actually an update count, creates an update-count only result set. |
(package private) void |
resetMaxBuf()
Sets the buffer size to max-buf |
protected void |
resetReadPacketSequence()
|
(package private) void |
scanForAndThrowDataTruncation()
|
(package private) void |
secureAuth411(Buffer packet,
int packLength,
java.lang.String user,
java.lang.String password,
java.lang.String database,
boolean writeClientParams)
Secure authentication for 4.1.1 and newer servers. |
(package private) Buffer |
sendCommand(int command,
java.lang.String extraData,
Buffer queryPacket,
boolean skipCheck,
java.lang.String extraDataCharEncoding,
int timeoutMillis)
Send a command to the MySQL server If data is to be sent with command, it should be put in extraData. |
protected void |
setStatementInterceptors(java.util.List statementInterceptors)
|
protected boolean |
shouldIntercept()
|
protected void |
skipPacket()
Reads and discards a single MySQL packet from the input stream. |
(package private) ResultSetInternalMethods |
sqlQueryDirect(StatementImpl callingStatement,
java.lang.String query,
java.lang.String characterEncoding,
Buffer queryPacket,
int maxRows,
int resultSetType,
int resultSetConcurrency,
boolean streamResults,
java.lang.String catalog,
Field[] cachedMetadata)
Send a query stored in a packet directly to the server. |
(package private) boolean |
tackOnMoreStreamingResults(ResultSetImpl addingTo)
|
protected Field |
unpackField(Buffer packet,
boolean extractDefaultValues)
Unpacks the Field information from the given packet. |
static boolean |
useBufferRowExplicit(Field[] fields)
|
protected boolean |
useNanosForElapsedTime()
|
(package private) boolean |
versionMeetsMinimum(int major,
int minor,
int subminor)
Does the version of the MySQL server we are connected to meet the given minimums? |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int NULL_LENGTH
protected static final int COMP_HEADER_LENGTH
protected static final int MIN_COMPRESS_LEN
protected static final int HEADER_LENGTH
protected static final int AUTH_411_OVERHEAD
protected static final int CLIENT_CONNECT_WITH_DB
protected static final int CLIENT_SSL
protected static final int CLIENT_RESERVED
protected static final int CLIENT_SECURE_CONNECTION
static final int SERVER_MORE_RESULTS_EXISTS
protected static final int MAX_QUERY_SIZE_TO_LOG
protected static final int MAX_QUERY_SIZE_TO_EXPLAIN
protected static final int INITIAL_PACKET_SIZE
protected static final java.lang.String ZERO_DATE_VALUE_MARKER
protected static final java.lang.String ZERO_DATETIME_VALUE_MARKER
protected int serverCharsetIndex
protected java.io.BufferedOutputStream mysqlOutput
protected ConnectionImpl connection
protected java.io.InputStream mysqlInput
protected java.net.Socket mysqlConnection
protected java.lang.String host
protected java.lang.String seed
protected int maxThreeBytes
protected int port
protected int serverCapabilities
protected long clientParam
protected long lastPacketSentTimeMs
protected long lastPacketReceivedTimeMs
Constructor Detail |
---|
public MysqlIO(java.lang.String host, int port, java.util.Properties props, java.lang.String socketFactoryClassName, ConnectionImpl conn, int socketTimeout, int useBufferRowSizeThreshold) throws java.io.IOException, java.sql.SQLException
host
- the hostname to connect toport
- the port number that the server is listening onprops
- the Properties from DriverManager.getConnection()socketFactoryClassName
- the socket factory to useconn
- the Connection that is creating ussocketTimeout
- the timeout to set for the socket (0 means no
timeout)
java.io.IOException
- if an IOException occurs during connect.
java.sql.SQLException
- if a database access error occurs.Method Detail |
---|
public boolean hasLongColumnInfo()
protected boolean isDataAvailable() throws java.sql.SQLException
java.sql.SQLException
protected long getLastPacketSentTimeMs()
protected long getLastPacketReceivedTimeMs()
protected ResultSetImpl getResultSet(StatementImpl callingStatement, long columnCount, int maxRows, int resultSetType, int resultSetConcurrency, boolean streamResults, java.lang.String catalog, boolean isBinaryEncoded, Field[] metadataFromCache) throws java.sql.SQLException
callingStatement
- DOCUMENT ME!columnCount
- the number of columns in the result setmaxRows
- the maximum number of rows to read (-1 means all rows)resultSetType
- (TYPE_FORWARD_ONLY, TYPE_SCROLL_????)resultSetConcurrency
- the type of result set (CONCUR_UPDATABLE or
READ_ONLY)streamResults
- should the result set be read all at once, or
streamed?catalog
- the database name in use when the result set was createdisBinaryEncoded
- is this result set in native encoding?unpackFieldInfo
- should we read MYSQL_FIELD info (if available)?
java.sql.SQLException
- if a database access error occursprotected final void forceClose()
protected final void skipPacket() throws java.sql.SQLException
java.sql.SQLException
- if the network fails while skipping the
packet.protected final Buffer readPacket() throws java.sql.SQLException
java.sql.SQLException
- DOCUMENT ME!
CommunicationsException
- DOCUMENT ME!protected final Field unpackField(Buffer packet, boolean extractDefaultValues) throws java.sql.SQLException
packet
- the packet containing the field informationextractDefaultValues
- should default values be extracted?
java.sql.SQLException
- DOCUMENT ME!protected boolean isSetNeededForAutoCommitMode(boolean autoCommitFlag)
protected boolean inTransactionOnServer()
protected void changeUser(java.lang.String userName, java.lang.String password, java.lang.String database) throws java.sql.SQLException
userName
- DOCUMENT ME!password
- DOCUMENT ME!database
- DOCUMENT ME!
java.sql.SQLException
- DOCUMENT ME!protected Buffer checkErrorPacket() throws java.sql.SQLException
java.sql.SQLException
- is the packet is an error packetprotected void checkForCharsetMismatch()
protected void clearInputStream() throws java.sql.SQLException
java.sql.SQLException
protected void resetReadPacketSequence()
protected void dumpPacketRingBuffer() throws java.sql.SQLException
java.sql.SQLException
protected void explainSlowQuery(byte[] querySQL, java.lang.String truncatedQuery) throws java.sql.SQLException
querySQL
- DOCUMENT ME!truncatedQuery
- DOCUMENT ME!
java.sql.SQLException
- DOCUMENT ME!static int getMaxBuf()
final int getServerMajorVersion()
final int getServerMinorVersion()
final int getServerSubMinorVersion()
java.lang.String getServerVersion()
void doHandshake(java.lang.String user, java.lang.String password, java.lang.String database) throws java.sql.SQLException
user
- DOCUMENT ME!password
- DOCUMENT ME!database
- DOCUMENT ME!
java.sql.SQLException
- DOCUMENT ME!
CommunicationsException
- DOCUMENT ME!final ResultSetRow nextRow(Field[] fields, int columnCount, boolean isBinaryEncoded, int resultSetConcurrency, boolean useBufferRowIfPossible, boolean useBufferRowExplicit, boolean canReuseRowPacketForBufferRow, Buffer existingRowPacket) throws java.sql.SQLException
fields
- DOCUMENT ME!columnCount
- DOCUMENT ME!isBinaryEncoded
- DOCUMENT ME!resultSetConcurrency
- DOCUMENT ME!b
-
java.sql.SQLException
- DOCUMENT ME!final ResultSetRow nextRowFast(Field[] fields, int columnCount, boolean isBinaryEncoded, int resultSetConcurrency, boolean useBufferRowIfPossible, boolean useBufferRowExplicit, boolean canReuseRowPacket) throws java.sql.SQLException
java.sql.SQLException
final void quit() throws java.sql.SQLException
java.sql.SQLException
- DOCUMENT ME!Buffer getSharedSendPacket()
void closeStreamer(RowData streamer) throws java.sql.SQLException
java.sql.SQLException
boolean tackOnMoreStreamingResults(ResultSetImpl addingTo) throws java.sql.SQLException
java.sql.SQLException
ResultSetImpl readAllResults(StatementImpl callingStatement, int maxRows, int resultSetType, int resultSetConcurrency, boolean streamResults, java.lang.String catalog, Buffer resultPacket, boolean isBinaryEncoded, long preSentColumnCount, Field[] metadataFromCache) throws java.sql.SQLException
java.sql.SQLException
void resetMaxBuf()
final Buffer sendCommand(int command, java.lang.String extraData, Buffer queryPacket, boolean skipCheck, java.lang.String extraDataCharEncoding, int timeoutMillis) throws java.sql.SQLException
command
- the MySQL protocol 'command' from MysqlDefsextraData
- any 'string' data for the commandqueryPacket
- a packet pre-loaded with data for the protocol (i.e.
from a client-side prepared statement).skipCheck
- do not call checkErrorPacket() if trueextraDataCharEncoding
- the character encoding of the extraData
parameter.
java.sql.SQLException
- if an I/O error or SQL error occursprotected boolean shouldIntercept()
final ResultSetInternalMethods sqlQueryDirect(StatementImpl callingStatement, java.lang.String query, java.lang.String characterEncoding, Buffer queryPacket, int maxRows, int resultSetType, int resultSetConcurrency, boolean streamResults, java.lang.String catalog, Field[] cachedMetadata) throws java.lang.Exception
callingStatement
- DOCUMENT ME!resultSetConcurrency
- DOCUMENT ME!characterEncoding
- DOCUMENT ME!queryPacket
- DOCUMENT ME!maxRows
- DOCUMENT ME!conn
- DOCUMENT ME!resultSetType
- DOCUMENT ME!resultSetConcurrency
- DOCUMENT ME!streamResults
- DOCUMENT ME!catalog
- DOCUMENT ME!unpackFieldInfo
- should we read MYSQL_FIELD info (if available)?
java.lang.Exception
- DOCUMENT ME!ResultSetInternalMethods invokeStatementInterceptorsPre(java.lang.String sql, Statement interceptedStatement, boolean forceExecute) throws java.sql.SQLException
java.sql.SQLException
ResultSetInternalMethods invokeStatementInterceptorsPost(java.lang.String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, boolean forceExecute, java.sql.SQLException statementException) throws java.sql.SQLException
java.sql.SQLException
protected long getCurrentTimeNanosOrMillis()
java.lang.String getHost()
boolean isVersion(int major, int minor, int subminor)
major
- the major versionminor
- the minor versionsubminor
- the subminor version
boolean versionMeetsMinimum(int major, int minor, int subminor)
major
- DOCUMENT ME!minor
- DOCUMENT ME!subminor
- DOCUMENT ME!
protected final ResultSetImpl readResultsForQueryOrUpdate(StatementImpl callingStatement, int maxRows, int resultSetType, int resultSetConcurrency, boolean streamResults, java.lang.String catalog, Buffer resultPacket, boolean isBinaryEncoded, long preSentColumnCount, Field[] metadataFromCache) throws java.sql.SQLException
callingStatement
- DOCUMENT ME!maxRows
- the maximum rows to return in the result set.resultSetType
- scrollabilityresultSetConcurrency
- updatabilitystreamResults
- should the driver leave the results on the wire,
and read them only when needed?catalog
- the catalog in useresultPacket
- the first packet of information in the result setisBinaryEncoded
- is this result set from a prepared statement?preSentColumnCount
- do we already know the number of columns?unpackFieldInfo
- should we unpack the field information?
java.sql.SQLException
- if an error occurs while reading the rowspublic static boolean useBufferRowExplicit(Field[] fields)
void enableMultiQueries() throws java.sql.SQLException
java.sql.SQLException
void disableMultiQueries() throws java.sql.SQLException
java.sql.SQLException
boolean hadWarnings()
void scanForAndThrowDataTruncation() throws java.sql.SQLException
java.sql.SQLException
void secureAuth411(Buffer packet, int packLength, java.lang.String user, java.lang.String password, java.lang.String database, boolean writeClientParams) throws java.sql.SQLException
packet
- DOCUMENT ME!packLength
- user
- password
- database
- DOCUMENT ME!writeClientParams
-
java.sql.SQLException
protected int getServerStatus()
protected java.util.List fetchRowsViaCursor(java.util.List fetchedRows, long statementId, Field[] columnTypes, int fetchSize, boolean useBufferRowExplicit) throws java.sql.SQLException
java.sql.SQLException
protected long getThreadId()
protected boolean useNanosForElapsedTime()
protected long getSlowQueryThreshold()
protected java.lang.String getQueryTimingUnits()
protected int getCommandCount()
protected void setStatementInterceptors(java.util.List statementInterceptors)
protected ExceptionInterceptor getExceptionInterceptor()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |