Modified:
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Buffer.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Clob.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/StringUtils.java
Log:
Better caching of character set converters (per-connection) to remove a bottleneck for
multibyte character sets.
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Buffer.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Buffer.java 2006-06-20 00:01:17 UTC
(rev 5416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Buffer.java 2006-06-20 21:33:56 UTC
(rev 5417)
@@ -563,7 +563,8 @@
// Write a String using the specified character
// encoding
final void writeLenString(String s, String encoding, String serverEncoding,
- SingleByteCharsetConverter converter, boolean parserKnowsUnicode)
+ SingleByteCharsetConverter converter, boolean parserKnowsUnicode,
+ Connection conn)
throws UnsupportedEncodingException, SQLException {
byte[] b = null;
@@ -571,7 +572,7 @@
b = converter.toBytes(s);
} else {
b = StringUtils.getBytes(s, encoding, serverEncoding,
- parserKnowsUnicode);
+ parserKnowsUnicode, conn);
}
int len = b.length;
@@ -622,10 +623,10 @@
}
// Write null-terminated string in the given encoding
- final void writeString(String s, String encoding) throws SQLException {
+ final void writeString(String s, String encoding, Connection conn) throws SQLException {
ensureCapacity((s.length() * 2) + 1);
try {
- writeStringNoNull(s, encoding, encoding, false);
+ writeStringNoNull(s, encoding, encoding, false, conn);
} catch (UnsupportedEncodingException ue) {
throw new SQLException(ue.toString(), SQLError.SQL_STATE_GENERAL_ERROR);
}
@@ -649,10 +650,10 @@
// Write a String using the specified character
// encoding
final void writeStringNoNull(String s, String encoding,
- String serverEncoding, boolean parserKnowsUnicode)
+ String serverEncoding, boolean parserKnowsUnicode, Connection conn)
throws UnsupportedEncodingException, SQLException {
byte[] b = StringUtils.getBytes(s, encoding, serverEncoding,
- parserKnowsUnicode);
+ parserKnowsUnicode, conn);
int len = b.length;
ensureCapacity(len);
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Clob.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Clob.java 2006-06-20 00:01:17 UTC
(rev 5416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Clob.java 2006-06-20 21:33:56 UTC
(rev 5417)
@@ -243,7 +243,7 @@
if (streamSize < this.charData.length()) {
try {
out.write(StringUtils
- .getBytes(this.charData, null, null, false),
+ .getBytes(this.charData, null, null, false, null),
streamSize, this.charData.length() - streamSize);
} catch (SQLException ex) {
//
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-06-20 00:01:17
UTC (rev 5416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2006-06-20 21:33:56
UTC (rev 5417)
@@ -57,6 +57,7 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -1411,6 +1412,8 @@
private String origDatabaseToConnectTo;
private String errorMessageEncoding = "Cp1252"; // to begin with, changes after we talk
to the server
+
+ private boolean usePlatformCharsetConverters;
/**
@@ -3314,16 +3317,23 @@
return null;
}
+ if (this.usePlatformCharsetConverters) {
+ return null; // we'll use Java's built-in routines for this
+ // they're finally fast enough
+ }
+
SingleByteCharsetConverter converter = null;
synchronized (this.charsetConverterMap) {
- converter = (SingleByteCharsetConverter) this.charsetConverterMap
+ Object asObject = this.charsetConverterMap
.get(javaEncodingName);
- if (converter == CHARSET_CONVERTER_NOT_AVAILABLE_MARKER) {
+ if (asObject == CHARSET_CONVERTER_NOT_AVAILABLE_MARKER) {
return null;
}
-
+
+ converter = (SingleByteCharsetConverter)asObject;
+
if (converter == null) {
try {
converter = SingleByteCharsetConverter.getInstance(
@@ -3332,9 +3342,9 @@
if (converter == null) {
this.charsetConverterMap.put(javaEncodingName,
CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
+ } else {
+ this.charsetConverterMap.put(javaEncodingName, converter);
}
-
- this.charsetConverterMap.put(javaEncodingName, converter);
} catch (UnsupportedEncodingException unsupEncEx) {
this.charsetConverterMap.put(javaEncodingName,
CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
@@ -3793,6 +3803,8 @@
private void initializeDriverProperties(Properties info)
throws SQLException {
initializeProperties(info);
+
+ this.usePlatformCharsetConverters = getUseJvmCharsetConverters();
this.log = LogFactory.getLogger(getLogger(), LOGGER_INSTANCE_NAME);
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
===================================================================
---
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2006-06-20
00:01:17 UTC (rev 5416)
+++
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2006-06-20
21:33:56 UTC (rev 5417)
@@ -1397,6 +1397,11 @@
+ ZERO_DATETIME_BEHAVIOR_CONVERT_TO_NULL + "'.", "3.1.4",
MISC_CATEGORY, Integer.MIN_VALUE);
+ private BooleanConnectionProperty useJvmCharsetConverters = new
BooleanConnectionProperty("useJvmCharsetConverters",
+ true, "Always use the character encoding routines built into the JVM, rather than
using "
+ + "lookup tables for single-byte character sets? (The default of \"true\" for this is
appropriate for "
+ + "newer JVMs", "5.0.1", PERFORMANCE_CATEGORY, Integer.MIN_VALUE);
+
private BooleanConnectionProperty useGmtMillisForDatetimes = new
BooleanConnectionProperty("useGmtMillisForDatetimes", false, "Convert between session
timezone and GMT before creating Date and Timestamp instances (value of \"false\" is
legacy behavior, \"true\" leads to more JDBC-compliant behavior.", "3.1.12",
MISC_CATEGORY, Integer.MIN_VALUE);
private BooleanConnectionProperty dumpMetadataOnColumnNotFound = new
BooleanConnectionProperty("dumpMetadataOnColumnNotFound", false, "Should the driver dump
the field-level metadata of a result set into " + "the exception message when
ResultSet.findColumn() fails?", "3.1.13", DEBUGING_PROFILING_CATEGORY,
Integer.MIN_VALUE);
@@ -3693,4 +3698,12 @@
boolean jdbcCompliantTruncationForReads) {
this.jdbcCompliantTruncationForReads = jdbcCompliantTruncationForReads;
}
+
+ protected boolean getUseJvmCharsetConverters() {
+ return this.useJvmCharsetConverters.getValueAsBoolean();
+ }
+
+ protected void setUseJvmCharsetConverters(boolean flag) {
+ this.useJvmCharsetConverters.setValue(flag);
+ }
}
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-06-20 00:01:17
UTC (rev 5416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java 2006-06-20 21:33:56
UTC (rev 5417)
@@ -1210,16 +1210,16 @@
}
// User/Password data
- packet.writeString(user, "Cp1252");
+ packet.writeString(user, "Cp1252", this.connection);
if (this.protocolVersion > 9) {
- packet.writeString(Util.newCrypt(password, this.seed), "Cp1252");
+ packet.writeString(Util.newCrypt(password, this.seed), "Cp1252",
this.connection);
} else {
- packet.writeString(Util.oldCrypt(password, this.seed), "Cp1252");
+ packet.writeString(Util.oldCrypt(password, this.seed), "Cp1252",
this.connection);
}
if (this.useConnectWithDb) {
- packet.writeString(database, "Cp1252");
+ packet.writeString(database, "Cp1252", this.connection);
}
send(packet, packet.getPosition());
@@ -1541,7 +1541,7 @@
this.sendPacket.writeStringNoNull(extraData,
extraDataCharEncoding,
this.connection.getServerCharacterEncoding(),
- this.connection.parserKnowsUnicode());
+ this.connection.parserKnowsUnicode(), this.connection);
}
} else if (command == MysqlDefs.PROCESS_KILL) {
long id = new Long(extraData).longValue();
@@ -1627,7 +1627,8 @@
if (this.platformDbCharsetMatches) {
this.sendPacket.writeStringNoNull(query, characterEncoding,
this.connection.getServerCharacterEncoding(),
- this.connection.parserKnowsUnicode());
+ this.connection.parserKnowsUnicode(),
+ this.connection);
} else {
if (StringUtils.startsWithIgnoreCaseAndWs(query, "LOAD DATA")) {
//$NON-NLS-1$
this.sendPacket.writeBytesNoNull(query.getBytes());
@@ -1635,7 +1636,8 @@
this.sendPacket.writeStringNoNull(query,
characterEncoding,
this.connection.getServerCharacterEncoding(),
- this.connection.parserKnowsUnicode());
+ this.connection.parserKnowsUnicode(),
+ this.connection);
}
}
} else {
@@ -3075,18 +3077,18 @@
}
// User/Password data
- packet.writeString(user, "Cp1252");
+ packet.writeString(user, "Cp1252", this.connection);
if (password.length() != 0) {
/* Prepare false scramble */
- packet.writeString(FALSE_SCRAMBLE, "Cp1252");
+ packet.writeString(FALSE_SCRAMBLE, "Cp1252", this.connection);
} else {
/* For empty password*/
- packet.writeString("", "Cp1252"); //$NON-NLS-1$
+ packet.writeString("", "Cp1252", this.connection); //$NON-NLS-1$
}
if (this.useConnectWithDb) {
- packet.writeString(database, "Cp1252");
+ packet.writeString(database, "Cp1252", this.connection);
}
send(packet, packet.getPosition());
@@ -3164,7 +3166,7 @@
mysqlScrambleBuff), password);
Buffer packet2 = new Buffer(packLength);
- packet2.writeString(scrambledPassword, "Cp1252");
+ packet2.writeString(scrambledPassword, "Cp1252",
this.connection);
this.packetSequence++;
send(packet2, 24);
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-06-20
00:01:17 UTC (rev 5416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-06-20
21:33:56 UTC (rev 5417)
@@ -292,7 +292,7 @@
this.staticSql[i] = StringUtils.getBytes(temp,
encoding, connection
.getServerCharacterEncoding(),
- connection.parserKnowsUnicode());
+ connection.parserKnowsUnicode(), conn);
}
}
}
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-06-20 00:01:17
UTC (rev 5416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-06-20 21:33:56
UTC (rev 5417)
@@ -1672,7 +1672,8 @@
return StringUtils.getBytes(stringVal, this.connection
.getEncoding(), this.connection
.getServerCharacterEncoding(), this.connection
- .parserKnowsUnicode());
+ .parserKnowsUnicode(),
+ this.connection);
}
return null;
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
---
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-06-20
00:01:17 UTC (rev 5416)
+++
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2006-06-20
21:33:56 UTC (rev 5417)
@@ -2108,7 +2108,8 @@
packet.writeLenString((String) value, this.charEncoding,
this.connection.getServerCharacterEncoding(),
this.charConverter, this.connection
- .parserKnowsUnicode());
+ .parserKnowsUnicode(),
+ this.connection);
} else {
packet.writeLenBytes(((String) value).getBytes());
}
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/StringUtils.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/StringUtils.java 2006-06-20
00:01:17 UTC (rev 5416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/StringUtils.java 2006-06-20
21:33:56 UTC (rev 5417)
@@ -443,11 +443,17 @@
}
public static final byte[] getBytes(char[] c, String encoding,
- String serverEncoding, boolean parserKnowsUnicode)
+ String serverEncoding, boolean parserKnowsUnicode, Connection conn)
throws SQLException {
try {
- SingleByteCharsetConverter converter = SingleByteCharsetConverter
- .getInstance(encoding, null);
+
+ SingleByteCharsetConverter converter = null;
+
+ if (conn != null) {
+ converter = conn.getCharsetConverter(encoding);
+ } else {
+ converter = SingleByteCharsetConverter.getInstance(encoding, null);
+ }
return getBytes(c, converter, encoding, serverEncoding,
parserKnowsUnicode);
@@ -594,11 +600,16 @@
* if an encoding unsupported by the JVM is supplied.
*/
public static final byte[] getBytes(String s, String encoding,
- String serverEncoding, boolean parserKnowsUnicode)
+ String serverEncoding, boolean parserKnowsUnicode, Connection conn)
throws SQLException {
try {
- SingleByteCharsetConverter converter = SingleByteCharsetConverter
- .getInstance(encoding, null);
+ SingleByteCharsetConverter converter = null;
+
+ if (conn != null) {
+ converter = conn.getCharsetConverter(encoding);
+ } else {
+ converter = SingleByteCharsetConverter.getInstance(encoding, null);
+ }
return getBytes(s, converter, encoding, serverEncoding,
parserKnowsUnicode);
| Thread |
|---|
| • Connector/J commit: r5417 - branches/branch_5_0/connector-j/src/com/mysql/jdbc | mmatthews | 20 Jun |