Modified:
branches/branch_3_1/connector-j/CHANGES
branches/branch_3_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java
branches/branch_3_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java
branches/branch_5_0/connector-j/CHANGES
branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java
branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java
branches/branch_5_1/connector-j/CHANGES
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java
branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java
Log:
Fixed BUG#16791 - NullPointerException in MysqlDataSourceFactory
due to Reference containing RefAddrs with null content.
Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES 2006-06-16 18:35:35 UTC (rev 5400)
+++ branches/branch_3_1/connector-j/CHANGES 2006-06-16 20:23:21 UTC (rev 5401)
@@ -14,6 +14,9 @@
- Fixed BUG#19726 - Connection fails to localhost when using
timeout and IPv6 is configured.
+ - Fixed BUG#16791 - NullPointerException in MysqlDataSourceFactory
+ due to Reference containing RefAddrs with null content.
+
05-26-06 - Version 3.1.13
- Fixed BUG#15464 - INOUT parameter does not store IN value.
Modified:
branches/branch_3_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java
===================================================================
---
branches/branch_3_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java 2006-06-16
18:35:35 UTC (rev 5400)
+++
branches/branch_3_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java 2006-06-16
20:23:21 UTC (rev 5401)
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2002-2004 MySQL AB
+ Copyright (C) 2002-2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
@@ -28,6 +28,7 @@
import javax.naming.Context;
import javax.naming.Name;
+import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
@@ -84,46 +85,43 @@
int portNumber = 3306;
- String portNumberAsString = (String) ref.get("port").getContent();
-
+ String portNumberAsString = nullSafeRefAddrStringGet("port", ref);
+
if (portNumberAsString != null) {
portNumber = Integer.parseInt(portNumberAsString);
}
dataSource.setPort(portNumber);
+
+ String user = nullSafeRefAddrStringGet(NonRegisteringDriver.USER_PROPERTY_KEY, ref);
- String user = (String) ref.get(
- NonRegisteringDriver.USER_PROPERTY_KEY).getContent();
-
if (user != null) {
dataSource.setUser(user);
}
- String password = (String) ref.get(
- NonRegisteringDriver.PASSWORD_PROPERTY_KEY).getContent();
+ String password = nullSafeRefAddrStringGet(NonRegisteringDriver.PASSWORD_PROPERTY_KEY,
ref);
if (password != null) {
dataSource.setPassword(password);
}
- String serverName = (String) ref.get("serverName").getContent();
+ String serverName = nullSafeRefAddrStringGet("serverName", ref);
if (serverName != null) {
dataSource.setServerName(serverName);
}
- String databaseName = (String) ref.get("databaseName").getContent();
+ String databaseName = nullSafeRefAddrStringGet("databaseName", ref);
if (databaseName != null) {
dataSource.setDatabaseName(databaseName);
}
- String explicitUrlAsString = (String) ref.get("explicitUrl")
- .getContent();
+ String explicitUrlAsString = nullSafeRefAddrStringGet("explicitUrl", ref);
if (explicitUrlAsString != null) {
if (Boolean.valueOf(explicitUrlAsString).booleanValue()) {
- dataSource.setUrl((String) ref.get("url").getContent());
+ dataSource.setUrl(nullSafeRefAddrStringGet("url", ref));
}
}
@@ -135,4 +133,12 @@
// We can't create an instance of the reference
return null;
}
+
+ private String nullSafeRefAddrStringGet(String referenceName, Reference ref) {
+ RefAddr refAddr = ref.get(referenceName);
+
+ String asString = refAddr != null ? (String)refAddr.getContent() : null;
+
+ return asString;
+ }
}
Modified:
branches/branch_3_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java
===================================================================
---
branches/branch_3_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16
18:35:35 UTC (rev 5400)
+++
branches/branch_3_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16
20:23:21 UTC (rev 5401)
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2002-2004 MySQL AB
+ Copyright (C) 2002-2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
@@ -36,6 +36,7 @@
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NameParser;
+import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import javax.sql.ConnectionPoolDataSource;
@@ -45,7 +46,10 @@
import testsuite.BaseTestCase;
import testsuite.simple.DataSourceTest;
+import com.mysql.jdbc.NonRegisteringDriver;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
+import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
+import com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory;
/**
* Tests fixes for bugs related to datasources.
@@ -273,6 +277,27 @@
}
}
+ /**
+ * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
+ * due to Reference containing RefAddrs with null content.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug16791() throws Exception {
+ MysqlDataSource myDs = new MysqlDataSource();
+ myDs.setUrl(dbUrl);
+ Reference asRef = myDs.getReference();
+ System.out.println(asRef);
+
+ removeFromRef(asRef, "port");
+ removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
+ removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
+ removeFromRef(asRef, "serverName");
+ removeFromRef(asRef, "databaseName");
+
+ MysqlDataSource newDs = (MysqlDataSource)new
MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
+ }
+
private void bindDataSource(String name, DataSource ds) throws Exception {
this.ctx.bind(this.tempDir.getAbsolutePath() + name, ds);
}
@@ -374,4 +399,16 @@
}
}
}
+
+ private void removeFromRef(Reference ref, String key) {
+ int size = ref.size();
+
+ for (int i = 0; i < size; i++) {
+ RefAddr refAddr = ref.get(i);
+ if (refAddr.getType().equals(key)) {
+ ref.remove(i);
+ break;
+ }
+ }
+ }
}
Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES 2006-06-16 18:35:35 UTC (rev 5400)
+++ branches/branch_5_0/connector-j/CHANGES 2006-06-16 20:23:21 UTC (rev 5401)
@@ -154,6 +154,9 @@
- Fixed BUG#19726 - Connection fails to localhost when using
timeout and IPv6 is configured.
+ - Fixed BUG#16791 - NullPointerException in MysqlDataSourceFactory
+ due to Reference containing RefAddrs with null content.
+
05-26-06 - Version 3.1.13
- Fixed BUG#15464 - INOUT parameter does not store IN value.
Modified:
branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java
===================================================================
---
branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java 2006-06-16
18:35:35 UTC (rev 5400)
+++
branches/branch_5_0/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java 2006-06-16
20:23:21 UTC (rev 5401)
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2002-2004 MySQL AB
+ Copyright (C) 2002-2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
@@ -28,6 +28,7 @@
import javax.naming.Context;
import javax.naming.Name;
+import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
@@ -84,46 +85,43 @@
int portNumber = 3306;
- String portNumberAsString = (String) ref.get("port").getContent();
-
+ String portNumberAsString = nullSafeRefAddrStringGet("port", ref);
+
if (portNumberAsString != null) {
portNumber = Integer.parseInt(portNumberAsString);
}
dataSource.setPort(portNumber);
+
+ String user = nullSafeRefAddrStringGet(NonRegisteringDriver.USER_PROPERTY_KEY, ref);
- String user = (String) ref.get(
- NonRegisteringDriver.USER_PROPERTY_KEY).getContent();
-
if (user != null) {
dataSource.setUser(user);
}
- String password = (String) ref.get(
- NonRegisteringDriver.PASSWORD_PROPERTY_KEY).getContent();
+ String password = nullSafeRefAddrStringGet(NonRegisteringDriver.PASSWORD_PROPERTY_KEY,
ref);
if (password != null) {
dataSource.setPassword(password);
}
- String serverName = (String) ref.get("serverName").getContent();
+ String serverName = nullSafeRefAddrStringGet("serverName", ref);
if (serverName != null) {
dataSource.setServerName(serverName);
}
- String databaseName = (String) ref.get("databaseName").getContent();
+ String databaseName = nullSafeRefAddrStringGet("databaseName", ref);
if (databaseName != null) {
dataSource.setDatabaseName(databaseName);
}
- String explicitUrlAsString = (String) ref.get("explicitUrl")
- .getContent();
+ String explicitUrlAsString = nullSafeRefAddrStringGet("explicitUrl", ref);
if (explicitUrlAsString != null) {
if (Boolean.valueOf(explicitUrlAsString).booleanValue()) {
- dataSource.setUrl((String) ref.get("url").getContent());
+ dataSource.setUrl(nullSafeRefAddrStringGet("url", ref));
}
}
@@ -135,4 +133,12 @@
// We can't create an instance of the reference
return null;
}
+
+ private String nullSafeRefAddrStringGet(String referenceName, Reference ref) {
+ RefAddr refAddr = ref.get(referenceName);
+
+ String asString = refAddr != null ? (String)refAddr.getContent() : null;
+
+ return asString;
+ }
}
Modified:
branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java
===================================================================
---
branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16
18:35:35 UTC (rev 5400)
+++
branches/branch_5_0/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16
20:23:21 UTC (rev 5401)
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2002-2004 MySQL AB
+ Copyright (C) 2002-2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
@@ -24,7 +24,11 @@
*/
package testsuite.regression;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -37,6 +41,7 @@
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NameParser;
+import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import javax.sql.ConnectionPoolDataSource;
@@ -46,8 +51,10 @@
import testsuite.BaseTestCase;
import testsuite.simple.DataSourceTest;
+import com.mysql.jdbc.NonRegisteringDriver;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
+import com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory;
/**
* Tests fixes for bugs related to datasources.
@@ -275,6 +282,37 @@
}
}
+ /**
+ * Tests fix for BUG#19169 - ConnectionProperties (and thus some
+ * subclasses) are not serializable, even though some J2EE containers
+ * expect them to be.
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug19169() throws Exception {
+ MysqlDataSource toSerialize = new MysqlDataSource();
+ toSerialize.setZeroDateTimeBehavior("convertToNull");
+
+ boolean testBooleanFlag = !toSerialize.getAllowLoadLocalInfile();
+ toSerialize.setAllowLoadLocalInfile(testBooleanFlag);
+
+ int testIntFlag = toSerialize.getBlobSendChunkSize() + 1;
+ toSerialize.setBlobSendChunkSize(String.valueOf(testIntFlag));
+
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ ObjectOutputStream objOut = new ObjectOutputStream(bOut);
+ objOut.writeObject(toSerialize);
+ objOut.flush();
+
+ ObjectInputStream objIn = new ObjectInputStream(new
ByteArrayInputStream(bOut.toByteArray()));
+
+ MysqlDataSource thawedDs = (MysqlDataSource)objIn.readObject();
+
+ assertEquals("convertToNull", thawedDs.getZeroDateTimeBehavior());
+ assertEquals(testBooleanFlag, thawedDs.getAllowLoadLocalInfile());
+ assertEquals(testIntFlag, thawedDs.getBlobSendChunkSize());
+ }
+
private void bindDataSource(String name, DataSource ds) throws Exception {
this.ctx.bind(this.tempDir.getAbsolutePath() + name, ds);
}
@@ -376,4 +414,37 @@
}
}
}
+
+ /**
+ * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
+ * due to Reference containing RefAddrs with null content.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug16791() throws Exception {
+ MysqlDataSource myDs = new MysqlDataSource();
+ myDs.setUrl(dbUrl);
+ Reference asRef = myDs.getReference();
+ System.out.println(asRef);
+
+ removeFromRef(asRef, "port");
+ removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
+ removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
+ removeFromRef(asRef, "serverName");
+ removeFromRef(asRef, "databaseName");
+
+ MysqlDataSource newDs = (MysqlDataSource)new
MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
+ }
+
+ private void removeFromRef(Reference ref, String key) {
+ int size = ref.size();
+
+ for (int i = 0; i < size; i++) {
+ RefAddr refAddr = ref.get(i);
+ if (refAddr.getType().equals(key)) {
+ ref.remove(i);
+ break;
+ }
+ }
+ }
}
Modified: branches/branch_5_1/connector-j/CHANGES
===================================================================
--- branches/branch_5_1/connector-j/CHANGES 2006-06-16 18:35:35 UTC (rev 5400)
+++ branches/branch_5_1/connector-j/CHANGES 2006-06-16 20:23:21 UTC (rev 5401)
@@ -128,6 +128,9 @@
- Fixed BUG#19726 - Connection fails to localhost when using
timeout and IPv6 is configured.
+ - Fixed BUG#16791 - NullPointerException in MysqlDataSourceFactory
+ due to Reference containing RefAddrs with null content.
+
05-26-06 - Version 3.1.13
- Fixed BUG#15464 - INOUT parameter does not store IN value.
Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java
===================================================================
---
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java 2006-06-16
18:35:35 UTC (rev 5400)
+++
branches/branch_5_1/connector-j/src/com/mysql/jdbc/jdbc2/optional/MysqlDataSourceFactory.java 2006-06-16
20:23:21 UTC (rev 5401)
@@ -28,6 +28,7 @@
import javax.naming.Context;
import javax.naming.Name;
+import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
@@ -84,46 +85,43 @@
int portNumber = 3306;
- String portNumberAsString = (String) ref.get("port").getContent();
-
+ String portNumberAsString = nullSafeRefAddrStringGet("port", ref);
+
if (portNumberAsString != null) {
portNumber = Integer.parseInt(portNumberAsString);
}
dataSource.setPort(portNumber);
+
+ String user = nullSafeRefAddrStringGet(NonRegisteringDriver.USER_PROPERTY_KEY, ref);
- String user = (String) ref.get(
- NonRegisteringDriver.USER_PROPERTY_KEY).getContent();
-
if (user != null) {
dataSource.setUser(user);
}
- String password = (String) ref.get(
- NonRegisteringDriver.PASSWORD_PROPERTY_KEY).getContent();
+ String password = nullSafeRefAddrStringGet(NonRegisteringDriver.PASSWORD_PROPERTY_KEY,
ref);
if (password != null) {
dataSource.setPassword(password);
}
- String serverName = (String) ref.get("serverName").getContent();
+ String serverName = nullSafeRefAddrStringGet("serverName", ref);
if (serverName != null) {
dataSource.setServerName(serverName);
}
- String databaseName = (String) ref.get("databaseName").getContent();
+ String databaseName = nullSafeRefAddrStringGet("databaseName", ref);
if (databaseName != null) {
dataSource.setDatabaseName(databaseName);
}
- String explicitUrlAsString = (String) ref.get("explicitUrl")
- .getContent();
+ String explicitUrlAsString = nullSafeRefAddrStringGet("explicitUrl", ref);
if (explicitUrlAsString != null) {
if (Boolean.valueOf(explicitUrlAsString).booleanValue()) {
- dataSource.setUrl((String) ref.get("url").getContent());
+ dataSource.setUrl(nullSafeRefAddrStringGet("url", ref));
}
}
@@ -135,4 +133,12 @@
// We can't create an instance of the reference
return null;
}
+
+ private String nullSafeRefAddrStringGet(String referenceName, Reference ref) {
+ RefAddr refAddr = ref.get(referenceName);
+
+ String asString = refAddr != null ? (String)refAddr.getContent() : null;
+
+ return asString;
+ }
}
Modified:
branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java
===================================================================
---
branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16
18:35:35 UTC (rev 5400)
+++
branches/branch_5_1/connector-j/src/testsuite/regression/DataSourceRegressionTest.java 2006-06-16
20:23:21 UTC (rev 5401)
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2002-2004 MySQL AB
+ Copyright (C) 2002-2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
@@ -24,7 +24,11 @@
*/
package testsuite.regression;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -37,6 +41,7 @@
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NameParser;
+import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import javax.sql.ConnectionPoolDataSource;
@@ -46,8 +51,10 @@
import testsuite.BaseTestCase;
import testsuite.simple.DataSourceTest;
+import com.mysql.jdbc.NonRegisteringDriver;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
+import com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory;
/**
* Tests fixes for bugs related to datasources.
@@ -69,6 +76,15 @@
public final static String DS_USER_PROP_NAME = "com.mysql.jdbc.test.ds.user";
+ /**
+ * Runs all test cases in this test suite
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(DataSourceTest.class);
+ }
+
private Context ctx;
private File tempDir;
@@ -85,15 +101,72 @@
// TODO Auto-generated constructor stub
}
+ private void bindDataSource(String name, DataSource ds) throws Exception {
+ this.ctx.bind(this.tempDir.getAbsolutePath() + name, ds);
+ }
+
/**
- * Runs all test cases in this test suite
+ * This method is separated from the rest of the example since you normally
+ * would NOT register a JDBC driver in your code. It would likely be
+ * configered into your naming and directory service using some GUI.
*
- * @param args
+ * @throws Exception
+ * if an error occurs
*/
- public static void main(String[] args) {
- junit.textui.TestRunner.run(DataSourceTest.class);
+ private void createJNDIContext() throws Exception {
+ this.tempDir = File.createTempFile("jnditest", null);
+ this.tempDir.delete();
+ this.tempDir.mkdir();
+ this.tempDir.deleteOnExit();
+
+ MysqlConnectionPoolDataSource ds;
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "com.sun.jndi.fscontext.RefFSContextFactory");
+ this.ctx = new InitialContext(env);
+ assertTrue("Naming Context not created", this.ctx != null);
+ ds = new MysqlConnectionPoolDataSource();
+ ds.setUrl(dbUrl); // from BaseTestCase
+ ds.setDatabaseName("test");
+ this.ctx.bind(this.tempDir.getAbsolutePath() + "/test", ds);
}
+ private DataSource lookupDatasourceInJNDI(String jndiName) throws Exception {
+ NameParser nameParser = this.ctx.getNameParser("");
+ Name datasourceName = nameParser.parse(this.tempDir.getAbsolutePath()
+ + jndiName);
+ Object obj = this.ctx.lookup(datasourceName);
+ DataSource boundDs = null;
+
+ if (obj instanceof DataSource) {
+ boundDs = (DataSource) obj;
+ } else if (obj instanceof Reference) {
+ //
+ // For some reason, this comes back as a Reference
+ // instance under CruiseControl !?
+ //
+ Reference objAsRef = (Reference) obj;
+ ObjectFactory factory = (ObjectFactory) Class.forName(
+ objAsRef.getFactoryClassName()).newInstance();
+ boundDs = (DataSource) factory.getObjectInstance(objAsRef,
+ datasourceName, this.ctx, new Hashtable());
+ }
+
+ return boundDs;
+ }
+
+ private void removeFromRef(Reference ref, String key) {
+ int size = ref.size();
+
+ for (int i = 0; i < size; i++) {
+ RefAddr refAddr = ref.get(i);
+ if (refAddr.getType().equals(key)) {
+ ref.remove(i);
+ break;
+ }
+ }
+ }
+
/**
* Sets up this test, calling registerDataSource() to bind a DataSource into
* JNDI, using the FSContext JNDI provider from Sun
@@ -122,19 +195,55 @@
}
/**
- * Tests fix for BUG#4808- Calling .close() twice on a PooledConnection
- * causes NPE.
+ * Tests fix for BUG#16791 - NullPointerException in MysqlDataSourceFactory
+ * due to Reference containing RefAddrs with null content.
*
- * @throws Exception
- * if an error occurs.
+ * @throws Exception if the test fails
*/
- public void testBug4808() throws Exception {
- MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
- ds.setURL(BaseTestCase.dbUrl);
- PooledConnection closeMeTwice = ds.getPooledConnection();
- closeMeTwice.close();
- closeMeTwice.close();
+ public void testBug16791() throws Exception {
+ MysqlDataSource myDs = new MysqlDataSource();
+ myDs.setUrl(dbUrl);
+ Reference asRef = myDs.getReference();
+ System.out.println(asRef);
+
+ removeFromRef(asRef, "port");
+ removeFromRef(asRef, NonRegisteringDriver.USER_PROPERTY_KEY);
+ removeFromRef(asRef, NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
+ removeFromRef(asRef, "serverName");
+ removeFromRef(asRef, "databaseName");
+
+ MysqlDataSource newDs = (MysqlDataSource)new
MysqlDataSourceFactory().getObjectInstance(asRef, null, null, null);
+ }
+ /**
+ * Tests fix for BUG#19169 - ConnectionProperties (and thus some
+ * subclasses) are not serializable, even though some J2EE containers
+ * expect them to be.
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug19169() throws Exception {
+ MysqlDataSource toSerialize = new MysqlDataSource();
+ toSerialize.setZeroDateTimeBehavior("convertToNull");
+
+ boolean testBooleanFlag = !toSerialize.getAllowLoadLocalInfile();
+ toSerialize.setAllowLoadLocalInfile(testBooleanFlag);
+
+ int testIntFlag = toSerialize.getBlobSendChunkSize() + 1;
+ toSerialize.setBlobSendChunkSize(String.valueOf(testIntFlag));
+
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ ObjectOutputStream objOut = new ObjectOutputStream(bOut);
+ objOut.writeObject(toSerialize);
+ objOut.flush();
+
+ ObjectInputStream objIn = new ObjectInputStream(new
ByteArrayInputStream(bOut.toByteArray()));
+
+ MysqlDataSource thawedDs = (MysqlDataSource)objIn.readObject();
+
+ assertEquals("convertToNull", thawedDs.getZeroDateTimeBehavior());
+ assertEquals(testBooleanFlag, thawedDs.getAllowLoadLocalInfile());
+ assertEquals(testIntFlag, thawedDs.getBlobSendChunkSize());
}
/**
@@ -275,60 +384,22 @@
}
}
- private void bindDataSource(String name, DataSource ds) throws Exception {
- this.ctx.bind(this.tempDir.getAbsolutePath() + name, ds);
- }
-
/**
- * This method is separated from the rest of the example since you normally
- * would NOT register a JDBC driver in your code. It would likely be
- * configered into your naming and directory service using some GUI.
+ * Tests fix for BUG#4808- Calling .close() twice on a PooledConnection
+ * causes NPE.
*
* @throws Exception
- * if an error occurs
+ * if an error occurs.
*/
- private void createJNDIContext() throws Exception {
- this.tempDir = File.createTempFile("jnditest", null);
- this.tempDir.delete();
- this.tempDir.mkdir();
- this.tempDir.deleteOnExit();
+ public void testBug4808() throws Exception {
+ MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
+ ds.setURL(BaseTestCase.dbUrl);
+ PooledConnection closeMeTwice = ds.getPooledConnection();
+ closeMeTwice.close();
+ closeMeTwice.close();
- MysqlConnectionPoolDataSource ds;
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.fscontext.RefFSContextFactory");
- this.ctx = new InitialContext(env);
- assertTrue("Naming Context not created", this.ctx != null);
- ds = new MysqlConnectionPoolDataSource();
- ds.setUrl(dbUrl); // from BaseTestCase
- ds.setDatabaseName("test");
- this.ctx.bind(this.tempDir.getAbsolutePath() + "/test", ds);
}
- private DataSource lookupDatasourceInJNDI(String jndiName) throws Exception {
- NameParser nameParser = this.ctx.getNameParser("");
- Name datasourceName = nameParser.parse(this.tempDir.getAbsolutePath()
- + jndiName);
- Object obj = this.ctx.lookup(datasourceName);
- DataSource boundDs = null;
-
- if (obj instanceof DataSource) {
- boundDs = (DataSource) obj;
- } else if (obj instanceof Reference) {
- //
- // For some reason, this comes back as a Reference
- // instance under CruiseControl !?
- //
- Reference objAsRef = (Reference) obj;
- ObjectFactory factory = (ObjectFactory) Class.forName(
- objAsRef.getFactoryClassName()).newInstance();
- boundDs = (DataSource) factory.getObjectInstance(objAsRef,
- datasourceName, this.ctx, new Hashtable());
- }
-
- return boundDs;
- }
-
public void testCSC4616() throws Exception {
MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
ds.setURL(BaseTestCase.dbUrl);
| Thread |
|---|
| • Connector/J commit: r5401 - in branches: branch_3_1/connector-j branch_3_1/connector-j/src/com/mysql/jdbc/jdbc2/optional branch_3_1/connector-j/src/te... | mmatthews | 16 Jun |