Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.mysql.jdbc
Class MysqlIO  view MysqlIO download MysqlIO.java

java.lang.Object
  extended bycom.mysql.jdbc.MysqlIO

public class MysqlIO
extends java.lang.Object

This class is used by Connection for communicating with the MySQL server.

Version:
$Id: MysqlIO.java,v 1.32.2.61 2004/08/27 21:50:12 mmatthew Exp $

Field Summary
private  boolean clearStreamBeforeEachQuery
           
private static int CLIENT_COMPRESS
           
private static int CLIENT_CONNECT_WITH_DB
           
private static int CLIENT_FOUND_ROWS
           
private static int CLIENT_IGNORE_SPACE
           
private static int CLIENT_INTERACTIVE
           
private static int CLIENT_LOCAL_FILES
           
private static int CLIENT_LONG_FLAG
           
private static int CLIENT_LONG_PASSWORD
           
private static int CLIENT_PROTOCOL_41
           
private static int CLIENT_RESERVED
           
private static int CLIENT_SECURE_CONNECTION
           
private static int CLIENT_SSL
           
private  int clientParam
           
private  boolean colDecimalNeedsBump
           
(package private) static int COMP_HEADER_LENGTH
           
private  Connection connection
           
private  java.util.zip.Deflater deflater
           
private static java.lang.String FALSE_SCRAMBLE
           
private  boolean has41NewNewProt
           
private  boolean hasLongColumnInfo
          Does the server support long column info?
(package private) static int HEADER_LENGTH
           
private  java.lang.String host
           
private  java.util.zip.Inflater inflater
           
private  boolean isInteractiveClient
           
private static java.lang.String jvmPlatformCharset
          We store the platform 'encoding' here, only used to avoid munging filenames for LOAD DATA LOCAL INFILE...
private  java.lang.ref.SoftReference loadFileBufRef
           
private static int MAX_QUERY_LENGTH_TO_LOG
           
private  int maxAllowedPacket
           
private static int maxBufferSize
           
private  int maxThreeBytes
           
(package private) static int MIN_COMPRESS_LEN
           
private  java.net.Socket mysqlConnection
          The connection to the server
private  java.io.InputStream mysqlInput
          Data from the server
private  java.io.BufferedOutputStream mysqlOutput
          Data to the server
(package private) static int NULL_LENGTH
           
private  byte[] packetHeaderBuf
           
private  byte packetSequence
           
private  boolean platformDbCharsetMatches
          Does the character set of this connection match the character set of the platform
private  int port
           
private  boolean profileSql
           
private  byte protocolVersion
           
private  Buffer reusablePacket
           
private  java.lang.String seed
           
private  Buffer sendPacket
           
private  int serverCapabilities
           
protected  int serverCharsetIndex
           
private  int serverMajorVersion
           
private  int serverMinorVersion
           
private  int serverSubMinorVersion
           
private  java.lang.String serverVersion
           
private  Buffer sharedSendPacket
           
private  SocketFactory socketFactory
           
private  java.lang.String socketFactoryClassName
           
private  java.lang.ref.SoftReference splitBufRef
           
private  RowData streamingData
           
private  boolean use41Extensions
          Should we use 4.1 protocol extensions?
private  boolean useCompression
           
private  boolean useNewLargePackets
           
private  boolean useNewUpdateCounts
           
private  java.sql.SQLWarning warningChain
           
 
Constructor Summary
protected MysqlIO(java.lang.String host, int port, java.lang.String socketFactoryClassName, java.util.Properties props, Connection conn, int socketTimeout)
          Constructor: Connect to the MySQL server and setup a stream connection.
 
Method Summary
private  int alignPacketSize(int a, int l)
           
private  ResultSet buildResultSetWithRows(java.lang.String catalog, Field[] fields, RowData rows, int resultSetConcurrency)
           
private  ResultSet buildResultSetWithUpdates(Buffer resultPacket)
           
protected  void changeUser(java.lang.String userName, java.lang.String password, java.lang.String database)
          Re-authenticates as the given user and password
private  Buffer checkErrorPacket()
          Checks for errors in the reply packet, and if none, returns the reply packet, ready for reading
private  Buffer checkErrorPacket(int command)
          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
private  void checkForOutstandingStreamingData()
           
private  void clearInputStream()
           
(package private)  void closeStreamer(RowData streamer)
           
private  Buffer compressPacket(Buffer packet, int offset, int packetLen, int headerLength)
           
private  SocketFactory createSocketFactory()
           
(package private)  void doHandshake(java.lang.String user, java.lang.String password, java.lang.String database)
          Initialize communications with the MySQL server.
protected  void forceClose()
          Forcibly closes the underlying socket to MySQL.
(package private)  java.lang.String getHost()
          Returns the host this IO is connected to
(package private) static int getMaxBuf()
           
protected  ResultSet getResultSet(long columnCount, int maxRows, int resultSetType, boolean streamResults, java.lang.String catalog)
          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.
(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  boolean hasLongColumnInfo()
          Does the server send back extra column info?
(package private)  byte[][] nextRow(int columnCount)
          Retrieve one row from the MySQL server.
(package private)  void quit()
          Log-off of the MySQL server and close the socket.
private  int readFully(java.io.InputStream in, byte[] b, int off, int len)
           
private  Buffer readPacket()
          Read one packet from the MySQL server
private  void reclaimLargeReusablePacket()
          Don't hold on to overly-large packets
private  void reclaimLargeSharedSendPacket()
          Ensures that we don't hold on to overly-large send packets
(package private)  void resetMaxBuf()
          Sets the buffer size to max-buf
private  Buffer reuseAndReadPacket(Buffer reuse)
          Re-use a packet to read from the MySQL server
private  void secureAuth(Buffer packet, int packLength, java.lang.String user, java.lang.String password, java.lang.String database, boolean writeClientParams)
          Secure authentication for 4.1 and newer servers.
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.
private  void secureAuth411(int packLength, int serverCapabilities, long clientParam, java.lang.String user, java.lang.String password, java.lang.String database)
          Secure authentication for 4.1.1 and newer servers.
private  void send(Buffer packet)
          Send a packet to the MySQL server
private  void send(Buffer packet, int packetLen)
           
(package private)  Buffer sendCommand(int command, java.lang.String extraData, Buffer queryPacket)
          Send a command to the MySQL server If data is to be sent with command, it should be put in ExtraData Raw packets can be sent by setting QueryPacket to something other than null.
private  ResultSet sendFileToServer(java.lang.String fileName)
          Reads and sends a file to the server for LOAD DATA LOCAL INFILE
private  void sendSplitPackets(Buffer packet)
          Sends a large packet to the server as a series of smaller packets
protected  void setProfileSql(boolean flag)
          Should the driver generate SQL statement profiles?
(package private)  ResultSet sqlQuery(java.lang.String query, int maxRows, java.lang.String characterEncoding, Connection conn, int resultSetType, boolean streamResults, java.lang.String catalog)
          Send a query specified in the String "Query" to the MySQL server.
(package private)  ResultSet sqlQueryDirect(Buffer queryPacket, int maxRows, Connection conn, int resultSetType, boolean streamResults, java.lang.String catalog)
          Send a query stored in a packet directly to the server.
protected  Field unpackField(Buffer packet, boolean extractDefaultValues)
          Unpacks the Field information from the given packet.
(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

NULL_LENGTH

static final int NULL_LENGTH
See Also:
Constant Field Values

COMP_HEADER_LENGTH

static final int COMP_HEADER_LENGTH
See Also:
Constant Field Values

MIN_COMPRESS_LEN

static final int MIN_COMPRESS_LEN
See Also:
Constant Field Values

HEADER_LENGTH

static final int HEADER_LENGTH
See Also:
Constant Field Values

maxBufferSize

private static int maxBufferSize

CLIENT_COMPRESS

private static final int CLIENT_COMPRESS
See Also:
Constant Field Values

CLIENT_CONNECT_WITH_DB

private static final int CLIENT_CONNECT_WITH_DB
See Also:
Constant Field Values

CLIENT_FOUND_ROWS

private static final int CLIENT_FOUND_ROWS
See Also:
Constant Field Values

CLIENT_IGNORE_SPACE

private static final int CLIENT_IGNORE_SPACE
See Also:
Constant Field Values

CLIENT_LOCAL_FILES

private static final int CLIENT_LOCAL_FILES
See Also:
Constant Field Values

CLIENT_LONG_FLAG

private static final int CLIENT_LONG_FLAG
See Also:
Constant Field Values

CLIENT_LONG_PASSWORD

private static final int CLIENT_LONG_PASSWORD
See Also:
Constant Field Values

CLIENT_PROTOCOL_41

private static final int CLIENT_PROTOCOL_41
See Also:
Constant Field Values

CLIENT_INTERACTIVE

private static final int CLIENT_INTERACTIVE
See Also:
Constant Field Values

CLIENT_SSL

private static final int CLIENT_SSL
See Also:
Constant Field Values

CLIENT_RESERVED

private static final int CLIENT_RESERVED
See Also:
Constant Field Values

CLIENT_SECURE_CONNECTION

private static final int CLIENT_SECURE_CONNECTION
See Also:
Constant Field Values

FALSE_SCRAMBLE

private static final java.lang.String FALSE_SCRAMBLE
See Also:
Constant Field Values

jvmPlatformCharset

private static java.lang.String jvmPlatformCharset
We store the platform 'encoding' here, only used to avoid munging filenames for LOAD DATA LOCAL INFILE...


reusablePacket

private Buffer reusablePacket

sendPacket

private Buffer sendPacket

sharedSendPacket

private Buffer sharedSendPacket

mysqlOutput

private java.io.BufferedOutputStream mysqlOutput
Data to the server


connection

private Connection connection

deflater

private java.util.zip.Deflater deflater

inflater

private java.util.zip.Inflater inflater

mysqlInput

private java.io.InputStream mysqlInput
Data from the server


streamingData

private RowData streamingData

warningChain

private java.sql.SQLWarning warningChain

mysqlConnection

private java.net.Socket mysqlConnection
The connection to the server


socketFactory

private SocketFactory socketFactory

loadFileBufRef

private java.lang.ref.SoftReference loadFileBufRef

splitBufRef

private java.lang.ref.SoftReference splitBufRef

host

private java.lang.String host

seed

private java.lang.String seed

serverVersion

private java.lang.String serverVersion

socketFactoryClassName

private java.lang.String socketFactoryClassName

packetHeaderBuf

private byte[] packetHeaderBuf

clearStreamBeforeEachQuery

private boolean clearStreamBeforeEachQuery

colDecimalNeedsBump

private boolean colDecimalNeedsBump

has41NewNewProt

private boolean has41NewNewProt

hasLongColumnInfo

private boolean hasLongColumnInfo
Does the server support long column info?


isInteractiveClient

private boolean isInteractiveClient

platformDbCharsetMatches

private boolean platformDbCharsetMatches
Does the character set of this connection match the character set of the platform


profileSql

private boolean profileSql

use41Extensions

private boolean use41Extensions
Should we use 4.1 protocol extensions?


useCompression

private boolean useCompression

useNewLargePackets

private boolean useNewLargePackets

useNewUpdateCounts

private boolean useNewUpdateCounts

packetSequence

private byte packetSequence

protocolVersion

private byte protocolVersion

clientParam

private int clientParam

maxAllowedPacket

private int maxAllowedPacket

maxThreeBytes

private int maxThreeBytes

port

private int port

serverCapabilities

private int serverCapabilities

serverMajorVersion

private int serverMajorVersion

serverMinorVersion

private int serverMinorVersion

serverSubMinorVersion

private int serverSubMinorVersion

serverCharsetIndex

protected int serverCharsetIndex

MAX_QUERY_LENGTH_TO_LOG

private static final int MAX_QUERY_LENGTH_TO_LOG
See Also:
Constant Field Values
Constructor Detail

MysqlIO

protected MysqlIO(java.lang.String host,
                  int port,
                  java.lang.String socketFactoryClassName,
                  java.util.Properties props,
                  Connection conn,
                  int socketTimeout)
           throws java.io.IOException,
                  java.sql.SQLException
Constructor: Connect to the MySQL server and setup a stream connection.

Method Detail

setProfileSql

protected void setProfileSql(boolean flag)
Should the driver generate SQL statement profiles?


getResultSet

protected ResultSet getResultSet(long columnCount,
                                 int maxRows,
                                 int resultSetType,
                                 boolean streamResults,
                                 java.lang.String catalog)
                          throws java.lang.Exception
Build a result set. Delegates to buildResultSetWithRows() to build a JDBC-version-specific ResultSet, given rows as byte data, and field information.


forceClose

protected final void forceClose()
Forcibly closes the underlying socket to MySQL.


changeUser

protected void changeUser(java.lang.String userName,
                          java.lang.String password,
                          java.lang.String database)
                   throws java.sql.SQLException
Re-authenticates as the given user and password


hasLongColumnInfo

protected boolean hasLongColumnInfo()
Does the server send back extra column info?


unpackField

protected final Field unpackField(Buffer packet,
                                  boolean extractDefaultValues)
                           throws java.sql.SQLException
Unpacks the Field information from the given packet. Understands pre 4.1 and post 4.1 server version field packet structures.


checkForCharsetMismatch

protected void checkForCharsetMismatch()
Determines if the database charset is the same as the platform charset


getMaxBuf

static int getMaxBuf()

getServerMajorVersion

final int getServerMajorVersion()
Get the major version of the MySQL server we are talking to.


getServerMinorVersion

final int getServerMinorVersion()
Get the minor version of the MySQL server we are talking to.


getServerSubMinorVersion

final int getServerSubMinorVersion()
Get the sub-minor version of the MySQL server we are talking to.


getServerVersion

java.lang.String getServerVersion()
Get the version string of the server we are talking to


doHandshake

void doHandshake(java.lang.String user,
                 java.lang.String password,
                 java.lang.String database)
           throws java.sql.SQLException
Initialize communications with the MySQL server. Handles logging on, and handling initial connection errors.


nextRow

final byte[][] nextRow(int columnCount)
                throws java.lang.Exception
Retrieve one row from the MySQL server. Note: this method is not thread-safe, but it is only called from methods that are guarded by synchronizing on this object.


quit

final void quit()
         throws java.sql.SQLException
Log-off of the MySQL server and close the socket.


getSharedSendPacket

Buffer getSharedSendPacket()
Returns the packet used for sending data (used by PreparedStatement) Guarded by external synchronization on a mutex.


closeStreamer

void closeStreamer(RowData streamer)
             throws java.sql.SQLException

resetMaxBuf

void resetMaxBuf()
Sets the buffer size to max-buf


sendCommand

final Buffer sendCommand(int command,
                         java.lang.String extraData,
                         Buffer queryPacket)
                  throws java.lang.Exception
Send a command to the MySQL server If data is to be sent with command, it should be put in ExtraData Raw packets can be sent by setting QueryPacket to something other than null.


sqlQuery

final ResultSet sqlQuery(java.lang.String query,
                         int maxRows,
                         java.lang.String characterEncoding,
                         Connection conn,
                         int resultSetType,
                         boolean streamResults,
                         java.lang.String catalog)
                  throws java.lang.Exception
Send a query specified in the String "Query" to the MySQL server. This method uses the specified character encoding to get the bytes from the query string.


sqlQueryDirect

final ResultSet sqlQueryDirect(Buffer queryPacket,
                               int maxRows,
                               Connection conn,
                               int resultSetType,
                               boolean streamResults,
                               java.lang.String catalog)
                        throws java.lang.Exception
Send a query stored in a packet directly to the server.


getHost

java.lang.String getHost()
Returns the host this IO is connected to


versionMeetsMinimum

boolean versionMeetsMinimum(int major,
                            int minor,
                            int subminor)
Does the version of the MySQL server we are connected to meet the given minimums?


readFully

private final int readFully(java.io.InputStream in,
                            byte[] b,
                            int off,
                            int len)
                     throws java.io.IOException

readPacket

private final Buffer readPacket()
                         throws java.sql.SQLException
Read one packet from the MySQL server


buildResultSetWithRows

private ResultSet buildResultSetWithRows(java.lang.String catalog,
                                         Field[] fields,
                                         RowData rows,
                                         int resultSetConcurrency)
                                  throws java.sql.SQLException

buildResultSetWithUpdates

private ResultSet buildResultSetWithUpdates(Buffer resultPacket)
                                     throws java.sql.SQLException

reclaimLargeReusablePacket

private void reclaimLargeReusablePacket()
Don't hold on to overly-large packets


reuseAndReadPacket

private final Buffer reuseAndReadPacket(Buffer reuse)
                                 throws java.sql.SQLException
Re-use a packet to read from the MySQL server


send

private final void send(Buffer packet)
                 throws java.sql.SQLException
Send a packet to the MySQL server


send

private final void send(Buffer packet,
                        int packetLen)
                 throws java.sql.SQLException

sendFileToServer

private final ResultSet sendFileToServer(java.lang.String fileName)
                                  throws java.sql.SQLException
Reads and sends a file to the server for LOAD DATA LOCAL INFILE


checkErrorPacket

private Buffer checkErrorPacket()
                         throws java.sql.SQLException
Checks for errors in the reply packet, and if none, returns the reply packet, ready for reading


checkErrorPacket

private Buffer checkErrorPacket(int command)
                         throws java.sql.SQLException
Checks for errors in the reply packet, and if none, returns the reply packet, ready for reading


sendSplitPackets

private final void sendSplitPackets(Buffer packet)
                             throws java.sql.SQLException
Sends a large packet to the server as a series of smaller packets


alignPacketSize

private int alignPacketSize(int a,
                            int l)

checkForOutstandingStreamingData

private void checkForOutstandingStreamingData()
                                       throws java.sql.SQLException

clearInputStream

private void clearInputStream()
                       throws java.sql.SQLException

compressPacket

private Buffer compressPacket(Buffer packet,
                              int offset,
                              int packetLen,
                              int headerLength)
                       throws java.sql.SQLException

createSocketFactory

private SocketFactory createSocketFactory()
                                   throws java.sql.SQLException

reclaimLargeSharedSendPacket

private void reclaimLargeSharedSendPacket()
Ensures that we don't hold on to overly-large send packets


secureAuth

private void secureAuth(Buffer packet,
                        int packLength,
                        java.lang.String user,
                        java.lang.String password,
                        java.lang.String database,
                        boolean writeClientParams)
                 throws java.sql.SQLException
Secure authentication for 4.1 and newer servers.


secureAuth411

private void secureAuth411(Buffer packet,
                           int packLength,
                           java.lang.String user,
                           java.lang.String password,
                           java.lang.String database,
                           boolean writeClientParams)
                    throws java.sql.SQLException
Secure authentication for 4.1.1 and newer servers.


secureAuth411

private void secureAuth411(int packLength,
                           int serverCapabilities,
                           long clientParam,
                           java.lang.String user,
                           java.lang.String password,
                           java.lang.String database)
                    throws java.sql.SQLException
Secure authentication for 4.1.1 and newer servers.