Modified:
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Field.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java
Log:
- Removed dead code in com.mysql.jdbc.Connection.
- Made construction of com.mysql.jdbc.Field (result set metadata)
instances more efficient for non-string types by not doing
character set initialization, or detection of type changes due to
temporary tables.
- Removed redundant code in com.mysql.jdbc.MysqlIO.
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2006-02-07 22:26:08
UTC (rev 4906)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2006-02-07 22:39:40
UTC (rev 4907)
@@ -1043,17 +1043,9 @@
*/
private static Map mapTransIsolationNameToValue = null;
- /** Table of multi-byte charsets. Initialized by loadCharacterSetMapping() */
- private static Map multibyteCharsetsMap;
-
/** Null logger shared by all connections at startup */
private static final Log NULL_LOGGER = new NullLogger(LOGGER_INSTANCE_NAME);
- // The command used to "ping" the database.
- // Newer versions of MySQL server have a ping() command,
- // but this works for everything.4
- private static final String PING_COMMAND = "SELECT 1";
-
private static Map roundRobinStatsMap;
private static final Map serverCollationByUrl = new HashMap();
@@ -1393,9 +1385,7 @@
private String origHostToConnectTo;
private int origPortToConnectTo;
private String origDatabaseToConnectTo;
- private String origUrl;
-
/**
* Creates a connection to a MySQL Server.
*
@@ -1415,7 +1405,7 @@
* if a database access error occurs
*/
Connection(String hostToConnectTo, int portToConnectTo, Properties info,
- String databaseToConnectTo, String url, NonRegisteringDriver d)
+ String databaseToConnectTo, String url)
throws SQLException {
this.connectionCreationTimeMillis = System.currentTimeMillis();
this.pointOfOrigin = new Throwable();
@@ -1510,12 +1500,12 @@
this.connectionId = this.io.getThreadId();
this.dbmd = new DatabaseMetaData(this, this.database);
} catch (SQLException ex) {
- cleanup(new Throwable(), ex);
+ cleanup(ex);
// don't clobber SQL exceptions
throw ex;
} catch (Exception ex) {
- cleanup(new Throwable(), ex);
+ cleanup(ex);
StringBuffer mesg = new StringBuffer();
@@ -1559,15 +1549,14 @@
this.origPortToConnectTo,
this.props,
this.origDatabaseToConnectTo,
- this.myURL,
- null);
+ this.myURL);
}
private void addToHistogram(int[] histogramCounts,
long[] histogramBreakpoints, long value, int numberOfTimes,
long currentLowerBound, long currentUpperBound) {
if (histogramCounts == null) {
- createInitialHistogram(histogramCounts, histogramBreakpoints,
+ createInitialHistogram(histogramBreakpoints,
currentLowerBound, currentUpperBound);
}
@@ -2003,7 +1992,7 @@
* @param whyCleanedUp
* DOCUMENT ME!
*/
- private void cleanup(Throwable fromWhere, Throwable whyCleanedUp) {
+ private void cleanup(Throwable whyCleanedUp) {
try {
if ((this.io != null) && !isClosed()) {
realClose(false, false, false, whyCleanedUp);
@@ -2112,8 +2101,8 @@
this.database);
}
- pStmt.setResultSetType(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE);
- pStmt.setResultSetConcurrency(java.sql.ResultSet.CONCUR_READ_ONLY);
+ pStmt.setResultSetType(resultSetType);
+ pStmt.setResultSetConcurrency(resultSetConcurrency);
return pStmt;
}
@@ -2194,8 +2183,8 @@
} else if (this.transactionsSupported) {
execSQL(null, "commit", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true,
false);
}
} catch (SQLException sqlException) {
@@ -2322,8 +2311,7 @@
execSQL(null, "SET NAMES utf8", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false, this.database, true,
- Statement.USES_VARIABLES_FALSE, false);
+ false, this.database, true, false);
}
setEncoding(realJavaEncoding);
@@ -2348,8 +2336,7 @@
-1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false, this.database, true,
- Statement.USES_VARIABLES_FALSE, false);
+ false, this.database, true, false);
}
// Switch driver's encoding now, since the server
@@ -2368,8 +2355,7 @@
execSQL(null, "SET NAMES " + mysqlEncodingName, -1,
null, java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY, false,
- false, this.database, true,
- Statement.USES_VARIABLES_FALSE, false);
+ this.database, true, false);
realJavaEncoding = getEncoding();
}
@@ -2385,8 +2371,8 @@
if (getCharacterSetResults() == null) {
execSQL(null, "SET character_set_results = NULL", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true,
false);
} else {
String charsetResults = getCharacterSetResults();
@@ -2409,9 +2395,8 @@
execSQL(null, setBuf.toString(), -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
- false);
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true, false);
}
if (getConnectionCollation() != null) {
@@ -2423,9 +2408,8 @@
execSQL(null, setBuf.toString(), -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
- false);
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true, false);
}
} else {
// Use what the server has specified
@@ -2510,7 +2494,7 @@
}
}
- private void createInitialHistogram(int[] counts, long[] breakpoints,
+ private void createInitialHistogram(long[] breakpoints,
long lowerBound, long upperBound) {
double bucketSize = (((double) upperBound - (double) lowerBound) / HISTOGRAM_BUCKETS) *
1.25;
@@ -2606,7 +2590,7 @@
// Server properties might be different
// from previous connection, so initialize
// again...
- initializePropsFromServer(this.props);
+ initializePropsFromServer();
if (isForReconnect) {
// Restore state from old connection
@@ -2733,7 +2717,7 @@
// Server properties might be different
// from previous connection, so initialize
// again...
- initializePropsFromServer(this.props);
+ initializePropsFromServer();
if (isForReconnect) {
// Restore state from old connection
@@ -2950,17 +2934,17 @@
// }
synchronized ResultSet execSQL(Statement callingStatement, String sql, int maxRows,
Buffer packet, int resultSetType, int resultSetConcurrency,
- boolean streamResults, boolean queryIsSelectOnly, String catalog,
+ boolean streamResults, String catalog,
boolean unpackFields) throws SQLException {
return execSQL(callingStatement, sql, maxRows, packet, resultSetType,
- resultSetConcurrency, streamResults, queryIsSelectOnly,
- catalog, unpackFields, Statement.USES_VARIABLES_FALSE, false);
+ resultSetConcurrency, streamResults,
+ catalog, unpackFields, false);
}
synchronized ResultSet execSQL(Statement callingStatement, String sql, int maxRows,
Buffer packet, int resultSetType, int resultSetConcurrency,
- boolean streamResults, boolean queryIsSelectOnly, String catalog,
- boolean unpackFields, byte queryUsesVariables,
+ boolean streamResults, String catalog,
+ boolean unpackFields,
boolean isBatch) throws SQLException {
//
// Fall-back if the master is back online if we've
@@ -3056,7 +3040,7 @@
if ((sqlState != null)
&& sqlState
.equals(SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE)) {
- cleanup(new Throwable(), sqlE);
+ cleanup(sqlE);
}
}
@@ -3065,7 +3049,7 @@
if ((getHighAvailability() || this.failedOver)) {
this.needsPing = true;
} else if (ex instanceof IOException) {
- cleanup(new Throwable(), ex);
+ cleanup(ex);
}
String exceptionType = ex.getClass().getName();
@@ -3149,7 +3133,7 @@
* DOCUMENT ME!
*/
protected void finalize() throws Throwable {
- cleanup(new Throwable(), null);
+ cleanup(null);
}
protected StringBuffer generateConnectionCommentBlock(StringBuffer buf) {
@@ -3740,7 +3724,7 @@
* @throws SQLException
* DOCUMENT ME!
*/
- private void initializePropsFromServer(Properties info) throws SQLException {
+ private void initializePropsFromServer() throws SQLException {
setSessionVariables();
//
@@ -4593,7 +4577,7 @@
oldHistBreakpoints[i] = histBreakpoints[i];
}
- createInitialHistogram(histCounts, histBreakpoints, currentLowerBound,
+ createInitialHistogram(histBreakpoints, currentLowerBound,
currentUpperBound);
for (int i = 0; i < HISTOGRAM_BUCKETS; i++) {
@@ -4632,7 +4616,7 @@
+ this.shortestQueryTimeMs + " ms");
logMessage
.append("\nAverage query execution time: "
- + ((double) this.totalQueryTimeMs / (double) this.numberOfQueriesIssued)
+ + (this.totalQueryTimeMs / this.numberOfQueriesIssued)
+ " ms");
logMessage.append("\nNumber of statements executed: "
+ this.numberOfQueriesIssued);
@@ -4926,9 +4910,8 @@
private void rollbackNoChecks() throws SQLException {
execSQL(null, "rollback", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
- false);
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true, false);
}
/**
@@ -5004,9 +4987,8 @@
execSQL(null, autoCommitFlag ? "SET autocommit=1"
: "SET autocommit=0", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
- false);
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true, false);
}
} else {
@@ -5073,9 +5055,8 @@
execSQL(null, query.toString(), -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
- false);
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true, false);
this.database = catalog;
}
@@ -5287,9 +5268,8 @@
execSQL(null, sql, -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
- false);
+ java.sql.ResultSet.CONCUR_READ_ONLY,false,
+ this.database, true, false);
this.isolationLevel = level;
}
@@ -5402,9 +5382,8 @@
&& (this.statementsUsingMaxRows.size() == 0)) {
execSQL(null, "SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1,
null, java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY, false, false,
- this.database, true, Statement.USES_VARIABLES_FALSE,
- false);
+ java.sql.ResultSet.CONCUR_READ_ONLY, false,
+ this.database, true, false);
this.maxRowsChanged = false;
}
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Field.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Field.java 2006-02-07 22:26:08 UTC
(rev 4906)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Field.java 2006-02-07 22:39:40 UTC
(rev 4907)
@@ -154,8 +154,6 @@
// charset
this.charsetIndex = charsetIndex;
- this.charsetName = this.connection
- .getCharsetNameForIndex(this.charsetIndex);
// Map MySqlTypes to java.sql Types
this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
@@ -174,35 +172,6 @@
}
}
- // Handle VARBINARY/BINARY (server doesn't have a different type
- // for this
-
- boolean isBinary = isBinary();
-
- if (this.connection.versionMeetsMinimum(4, 1, 0) &&
- this.mysqlType == MysqlDefs.FIELD_TYPE_VAR_STRING &&
- isBinary &&
- this.charsetIndex == 63) {
- if (this.isOpaqueBinary()) {
- this.sqlType = Types.VARBINARY;
- }
- }
-
- if (this.connection.versionMeetsMinimum(4, 1, 0) &&
- this.mysqlType == MysqlDefs.FIELD_TYPE_STRING &&
- isBinary && this.charsetIndex == 63) {
- //
- // Okay, this is a hack, but there's currently no way
- // to easily distinguish something like DATE_FORMAT( ..)
- // from the "BINARY" column type, other than looking
- // at the original column name.
- //
-
- if (isOpaqueBinary()) {
- this.sqlType = Types.BINARY;
- }
- }
-
if (this.sqlType == Types.TINYINT && this.length == 1
&& this.connection.getTinyInt1isBit()) {
// Adjust for pseudo-boolean
@@ -215,29 +184,68 @@
}
}
+
+ if (!isNativeNumericType() && !isNativeDateTimeType()) {
+ this.charsetName = this.connection
+ .getCharsetNameForIndex(this.charsetIndex);
- if (this.mysqlType == MysqlDefs.FIELD_TYPE_BIT) {
- if (this.length == 0) {
- this.sqlType = Types.BIT;
- } else {
- this.sqlType = Types.VARBINARY;
- this.colFlag |= 128; // we need to pretend this is a full
- this.colFlag |= 16; // binary blob
+
+ // Handle VARBINARY/BINARY (server doesn't have a different type
+ // for this
+
+ boolean isBinary = isBinary();
+
+ if (this.connection.versionMeetsMinimum(4, 1, 0) &&
+ this.mysqlType == MysqlDefs.FIELD_TYPE_VAR_STRING &&
+ isBinary &&
+ this.charsetIndex == 63) {
+ if (this.isOpaqueBinary()) {
+ this.sqlType = Types.VARBINARY;
+ }
+ }
+
+ if (this.connection.versionMeetsMinimum(4, 1, 0) &&
+ this.mysqlType == MysqlDefs.FIELD_TYPE_STRING &&
+ isBinary && this.charsetIndex == 63) {
+ //
+ // Okay, this is a hack, but there's currently no way
+ // to easily distinguish something like DATE_FORMAT( ..)
+ // from the "BINARY" column type, other than looking
+ // at the original column name.
+ //
+
+ if (isOpaqueBinary()) {
+ this.sqlType = Types.BINARY;
+ }
}
+
+
+
+ if (this.mysqlType == MysqlDefs.FIELD_TYPE_BIT) {
+ if (this.length == 0) {
+ this.sqlType = Types.BIT;
+ } else {
+ this.sqlType = Types.VARBINARY;
+ this.colFlag |= 128; // we need to pretend this is a full
+ this.colFlag |= 16; // binary blob
+ }
+ }
+
+ //
+ // Handle TEXT type (special case), Fix proposed by Peter McKeown
+ //
+ if ((this.sqlType == java.sql.Types.LONGVARBINARY) && !isBinary) {
+ this.sqlType = java.sql.Types.LONGVARCHAR;
+ } else if ((this.sqlType == java.sql.Types.VARBINARY) && !isBinary) {
+ this.sqlType = java.sql.Types.VARCHAR;
+ }
+
+ checkForImplicitTemporaryTable();
+ } else {
+ this.charsetName = "US-ASCII";
}
-
-
//
- // Handle TEXT type (special case), Fix proposed by Peter McKeown
- //
- if ((this.sqlType == java.sql.Types.LONGVARBINARY) && !isBinary) {
- this.sqlType = java.sql.Types.LONGVARCHAR;
- } else if ((this.sqlType == java.sql.Types.VARBINARY) && !isBinary) {
- this.sqlType = java.sql.Types.VARCHAR;
- }
-
- //
// Handle odd values for 'M' for floating point/decimal numbers
//
if (!isUnsigned()) {
@@ -262,8 +270,6 @@
break;
}
}
-
- checkForImplicitTemporaryTable();
}
/**
@@ -306,7 +312,7 @@
*
* @return the character set
*/
- public String getCharacterSet() {
+ public String getCharacterSet() throws SQLException {
return this.charsetName;
}
@@ -801,6 +807,21 @@
this.mysqlType = MysqlDefs.FIELD_TYPE_LONG_BLOB;
}
}
+
+ private boolean isNativeNumericType() {
+ return ((this.mysqlType >= MysqlDefs.FIELD_TYPE_TINY &&
+ this.mysqlType <= MysqlDefs.FIELD_TYPE_DOUBLE) ||
+ this.mysqlType == MysqlDefs.FIELD_TYPE_LONGLONG ||
+ this.mysqlType == MysqlDefs.FIELD_TYPE_YEAR);
+ }
+
+ private boolean isNativeDateTimeType() {
+ return (this.mysqlType == MysqlDefs.FIELD_TYPE_DATE ||
+ this.mysqlType == MysqlDefs.FIELD_TYPE_NEWDATE ||
+ this.mysqlType == MysqlDefs.FIELD_TYPE_DATETIME ||
+ this.mysqlType == MysqlDefs.FIELD_TYPE_TIME ||
+ this.mysqlType == MysqlDefs.FIELD_TYPE_TIMESTAMP);
+ }
/**
* DOCUMENT ME!
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java 2006-02-07 22:26:08
UTC (rev 4906)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java 2006-02-07 22:39:40
UTC (rev 4907)
@@ -756,7 +756,7 @@
packet.writeString(database);
}
- send(packet);
+ send(packet, packet.getPosition());
checkErrorPacket();
if (!localUseConnectWithDb) {
@@ -1187,7 +1187,7 @@
packet.writeString(database);
}
- send(packet);
+ send(packet, packet.getPosition());
}
} else {
negotiateSSLConnection(user, password, database, packLength);
@@ -1306,7 +1306,7 @@
Buffer packet = new Buffer(6);
this.packetSequence = -1;
packet.writeByte((byte) MysqlDefs.QUIT);
- send(packet);
+ send(packet, packet.getPosition());
forceClose();
}
@@ -1511,10 +1511,10 @@
this.sendPacket.writeLong(id);
}
- send(this.sendPacket);
+ send(this.sendPacket, this.sendPacket.getPosition());
} else {
this.packetSequence = -1;
- send(queryPacket); // packet passed by PreparedStatement
+ send(queryPacket, queryPacket.getPosition()); // packet passed by
PreparedStatement
}
} catch (SQLException sqlEx) {
// don't wrap SQLExceptions
@@ -2527,17 +2527,17 @@
*
* @throws SQLException DOCUMENT ME!
*/
- final void send(Buffer packet) throws SQLException {
- int l = packet.getPosition();
- send(packet, l);
+ //final void send(Buffer packet) throws SQLException {
+ // int l = packet.getPosition();
+ // send(packet, l);
//
// Don't hold on to large packets
//
- if (packet == this.sharedSendPacket) {
- reclaimLargeSharedSendPacket();
- }
- }
+ // if (packet == this.sharedSendPacket) {
+ // reclaimLargeSharedSendPacket();
+ // }
+ // }
private final void send(Buffer packet, int packetLen)
throws SQLException {
@@ -2689,7 +2689,7 @@
while ((bytesRead = fileIn.read(fileBuf)) != -1) {
filePacket.clear();
filePacket.writeBytesNoNull(fileBuf, 0, bytesRead);
- send(filePacket);
+ send(filePacket, filePacket.getPosition());
}
} catch (IOException ioEx) {
StringBuffer messageBuf = new StringBuffer(Messages.getString(
@@ -2727,14 +2727,14 @@
} else {
// file open failed, but server needs one packet
filePacket.clear();
- send(filePacket);
+ send(filePacket, filePacket.getPosition());
checkErrorPacket(); // to clear response off of queue
}
}
// send empty packet to mark EOF
filePacket.clear();
- send(filePacket);
+ send(filePacket, filePacket.getPosition());
Buffer resultPacket = checkErrorPacket();
@@ -3047,7 +3047,7 @@
packet.writeString(database);
}
- send(packet);
+ send(packet, packet.getPosition());
//
// Don't continue stages if password is empty
@@ -3218,7 +3218,7 @@
packet.writeString(database);
}
- send(packet);
+ send(packet, packet.getPosition());
byte savePacketSequence = this.packetSequence++;
@@ -3234,7 +3234,7 @@
String seed323 = this.seed.substring(0, 8);
packet.writeString(Util.newCrypt(password, seed323));
- send(packet);
+ send(packet, packet.getPosition());
/* Read what server thinks about out new auth message report */
checkErrorPacket();
@@ -3780,7 +3780,7 @@
packet.writeInt((int) this.clientParam);
}
- send(packet);
+ send(packet, packet.getPosition());
ExportControlled.transformSocketToSSLSocket(this);
@@ -3815,7 +3815,7 @@
packet.writeString(database);
}
- send(packet);
+ send(packet, packet.getPosition());
}
}
| Thread |
|---|
| • Connector/J commit: r4907 - branches/branch_5_0/connector-j/src/com/mysql/jdbc | mmatthews | 7 Feb |