Modified:
trunk/src/com/mysql/jdbc/Buffer.java
trunk/src/com/mysql/jdbc/ConnectionImpl.java
trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
trunk/src/com/mysql/jdbc/MysqlIOprotocol.java
Log:
simplify the MysqlIO constructor to a connection and a properties file.
Modified: trunk/src/com/mysql/jdbc/Buffer.java
===================================================================
--- trunk/src/com/mysql/jdbc/Buffer.java 2008-01-15 22:17:45 UTC (rev 6711)
+++ trunk/src/com/mysql/jdbc/Buffer.java 2008-01-16 19:24:41 UTC (rev 6712)
@@ -49,12 +49,12 @@
protected boolean wasMultiPacket = false;
- Buffer(byte[] buf) {
+ public Buffer(byte[] buf) {
this.byteBuffer = buf;
setBufLength(buf.length);
}
- Buffer(int size) {
+ public Buffer(int size) {
this.byteBuffer = new byte[size];
setBufLength(this.byteBuffer.length);
this.position = MysqlIOprotocol.HEADER_LENGTH;
Modified: trunk/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- trunk/src/com/mysql/jdbc/ConnectionImpl.java 2008-01-15 22:17:45 UTC (rev 6711)
+++ trunk/src/com/mysql/jdbc/ConnectionImpl.java 2008-01-16 19:24:41 UTC (rev 6712)
@@ -49,6 +49,8 @@
import java.util.Timer;
import java.util.TreeMap;
+import javax.sql.ConnectionPoolDataSource;
+
import com.mysql.jdbc.log.Log;
import com.mysql.jdbc.log.LogFactory;
import com.mysql.jdbc.log.NullLogger;
@@ -5496,18 +5498,31 @@
}
private MysqlIO newMysqlIO(String host1, int port1, Properties props1,
- String getMysqlIOFactory,
- String socketFactoryClassName, ConnectionImpl conn, int socketTimeout,
- int largeRowSizeThreshold1) throws IOException, SQLException {
-
- Class[] argTypes = new Class[] { String.class, int.class,
- Properties.class, String.class, ConnectionImpl.class, int.class,
- int.class };
-
- Object[] args = new Object[] { host1, new Integer(port1), props1,
- socketFactoryClassName, conn, new Integer(socketTimeout),
- new Integer(largeRowSizeThreshold1) };
+ String getMysqlIOFactory, String socketFactoryClassName,
+ ConnectionImpl conn, int socketTimeout, int largeRowSizeThreshold1)
+ throws IOException, SQLException {
+ Properties mergedProps = new Properties(props1);
+ mergedProps.put(NonRegisteringDriver.HOST_PROPERTY_KEY, host1);
+
+ mergedProps.put(NonRegisteringDriver.PORT_PROPERTY_KEY, Integer
+ .toString(port1));
+
+ mergedProps.put(ConnectionPropertiesImpl.SOCKET_FACTORY_PROPERTY_KEY,
+ socketFactoryClassName);
+
+ mergedProps.put(
+ ConnectionPropertiesImpl.LARGE_ROW_SIZE_THRESHOLD_PROPERTY_KEY,
+ Integer.toString(largeRowSizeThreshold1));
+
+ mergedProps.put(ConnectionPropertiesImpl.SOCKET_TIMEOUT_PROPERTY_KEY,
+ Integer.toString(socketTimeout));
+
+ Class[] argTypes = new Class[] { Properties.class,
+ ConnectionImpl.class, };
+
+ Object[] args = new Object[] { mergedProps, conn };
+
return (MysqlIO) Util.getInstance(getMysqlIOFactory, argTypes, args);
}
-}
\ No newline at end of file
+}
Modified: trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
===================================================================
--- trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java 2008-01-15 22:17:45 UTC (rev 6711)
+++ trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java 2008-01-16 19:24:41 UTC (rev 6712)
@@ -51,8 +51,14 @@
*/
public class ConnectionPropertiesImpl implements Serializable, ConnectionProperties {
- private static final long serialVersionUID = 4257801713007640580L;
+ public static final String SOCKET_TIMEOUT_PROPERTY_KEY = "socketTimeout";
+ public static final String LARGE_ROW_SIZE_THRESHOLD_PROPERTY_KEY = "largeRowSizeThreshold";
+
+ public static final String SOCKET_FACTORY_PROPERTY_KEY = "socketFactory";
+
+ private static final long serialVersionUID = 4257801713007640580L;
+
class BooleanConnectionProperty extends ConnectionProperty implements Serializable {
private static final long serialVersionUID = 2540132501709159404L;
@@ -994,7 +1000,7 @@
private boolean jdbcCompliantTruncationForReads =
this.jdbcCompliantTruncation.getValueAsBoolean();
- protected MemorySizeConnectionProperty largeRowSizeThreshold = new MemorySizeConnectionProperty("largeRowSizeThreshold",
+ protected MemorySizeConnectionProperty largeRowSizeThreshold = new MemorySizeConnectionProperty(LARGE_ROW_SIZE_THRESHOLD_PROPERTY_KEY,
2048, 0, Integer.MAX_VALUE,
Messages.getString("ConnectionProperties.largeRowSizeThreshold"),
"5.1.1", PERFORMANCE_CATEGORY, Integer.MIN_VALUE);
@@ -1328,13 +1334,13 @@
10);
private StringConnectionProperty socketFactoryClassName = new StringConnectionProperty(
- "socketFactory", //$NON-NLS-1$
+ SOCKET_FACTORY_PROPERTY_KEY, //$NON-NLS-1$
StandardSocketFactory.class.getName(),
Messages.getString("ConnectionProperties.socketFactory"), //$NON-NLS-1$
"3.0.3", CONNECTION_AND_AUTH_CATEGORY, 4); //$NON-NLS-1$
private IntegerConnectionProperty socketTimeout = new IntegerConnectionProperty(
- "socketTimeout", //$NON-NLS-1$
+ SOCKET_TIMEOUT_PROPERTY_KEY, //$NON-NLS-1$
0,
0,
Integer.MAX_VALUE,
Modified: trunk/src/com/mysql/jdbc/MysqlIOprotocol.java
===================================================================
--- trunk/src/com/mysql/jdbc/MysqlIOprotocol.java 2008-01-15 22:17:45 UTC (rev 6711)
+++ trunk/src/com/mysql/jdbc/MysqlIOprotocol.java 2008-01-16 19:24:41 UTC (rev 6712)
@@ -252,6 +252,10 @@
public MysqlIOprotocol(String host, int port, Properties props,
String socketFactoryClassName, ConnectionImpl conn,
int socketTimeout, int useBufferRowSizeThreshold) throws IOException, SQLException {
+ }
+
+ public MysqlIOprotocol(Properties props, ConnectionImpl conn)
+ throws IOException, SQLException {
this.connection = conn;
if (this.connection.getEnablePacketDebug()) {
@@ -260,7 +264,9 @@
this.useAutoSlowLog = this.connection.getAutoSlowLog();
- this.useBufferRowSizeThreshold = useBufferRowSizeThreshold;
+ this.useBufferRowSizeThreshold = Integer
+ .parseInt((String) props
+ .get(ConnectionPropertiesImpl.LARGE_ROW_SIZE_THRESHOLD_PROPERTY_KEY));
this.useDirectRowUnpack = this.connection.getUseDirectRowUnpack();
this.logSlowQueries = this.connection.getLogSlowQueries();
@@ -268,21 +274,27 @@
this.reusablePacket = new Buffer(INITIAL_PACKET_SIZE);
this.sendPacket = new Buffer(INITIAL_PACKET_SIZE);
- this.port = port;
- this.host = host;
+ this.port = Integer.parseInt(props
+ .getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY));
+ this.host = (String) props.get(NonRegisteringDriver.HOST_PROPERTY_KEY);
- this.socketFactoryClassName = socketFactoryClassName;
+ this.socketFactoryClassName = (String) props
+ .get(ConnectionPropertiesImpl.SOCKET_FACTORY_PROPERTY_KEY);
this.socketFactory = createSocketFactory();
this.mysqlConnection = this.socketFactory.connect(this.host,
this.port, props);
- if (socketTimeout != 0) {
- try {
- this.mysqlConnection.setSoTimeout(socketTimeout);
- } catch (Exception ex) {
- /* Ignore if the platform does not support it */
- }
+ if (props
+ .containsKey(ConnectionPropertiesImpl.SOCKET_TIMEOUT_PROPERTY_KEY)) {
+ try {
+ this.mysqlConnection
+ .setSoTimeout(Integer
+ .parseInt((String) props
+ .get(ConnectionPropertiesImpl.SOCKET_TIMEOUT_PROPERTY_KEY)));
+ } catch (Exception ex) {
+ /* Ignore if the platform does not support it */
+ }
}
this.mysqlConnection = this.socketFactory.beforeHandshake();
| Thread |
|---|
| • Connector/J commit: r6712 - trunk/src/com/mysql/jdbc | eherman | 16 Jan |