Modified:
branches/branch_5_1/CHANGES
branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java
branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java
Log:
Fixed BUG#35660 - Calling equals() on connections created with "jdbc:mysql:loadbalance:"
URLs did not have the same behavior as "plain" connections. The behavior we use
is the implementation in java.lang.Object, load-balanced connections just happened
to be using a java.lang.reflect.Proxy which required some custom behavior in
equals() to make it work the same as "plain" connections.
Note that there is no *specified* equals contract for JDBC connections in the
JDBC specification itself, but the test makes sure that our implementation is
at least consistent.
Modified: branches/branch_5_1/CHANGES
===================================================================
--- branches/branch_5_1/CHANGES 2008-03-31 14:56:21 UTC (rev 6766)
+++ branches/branch_5_1/CHANGES 2008-03-31 15:27:25 UTC (rev 6767)
@@ -15,6 +15,16 @@
- Fixed BUG#35666 - NullPointerException when using "logSlowQueries=true" with
server-side prepared statements enabled.
+
+ - Fixed BUG#35660 - Calling equals() on connections created with
"jdbc:mysql:loadbalance:"
+ URLs did not have the same behavior as "plain" connections. The behavior we use
+ is the implementation in java.lang.Object, load-balanced connections just happened
+ to be using a java.lang.reflect.Proxy which required some custom behavior in
+ equals() to make it work the same as "plain" connections.
+
+ Note that there is no *specified* equals contract for JDBC connections in the
+ JDBC specification itself, but the test makes sure that our implementation is
+ at least consistent.
03-06-08 - Version 5.1.6
Modified: branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java 2008-03-31
14:56:21 UTC (rev 6766)
+++ branches/branch_5_1/src/com/mysql/jdbc/LoadBalancingConnectionProxy.java 2008-03-31
15:27:25 UTC (rev 6767)
@@ -275,6 +275,14 @@
String methodName = method.getName();
+ if ("equals".equals(methodName) && args.length == 1) {
+ if (args[0] instanceof Proxy) {
+ return Boolean.valueOf((((Proxy)args[0]).equals(this)));
+ }
+
+ return Boolean.valueOf(equals(args[0]));
+ }
+
if ("close".equals(methodName)) {
synchronized (this.liveConnections) {
// close all underlying connections
Modified: branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java
===================================================================
--- branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java 2008-03-31
14:56:21 UTC (rev 6766)
+++ branches/branch_5_1/src/testsuite/regression/ConnectionRegressionTest.java 2008-03-31
15:27:25 UTC (rev 6767)
@@ -2393,4 +2393,20 @@
replConn.setReadOnly(readOnly);
}
}
+
+ public void testBug35660() throws Exception {
+
+ Connection lbConn = getLoadBalancedConnection(null);
+ Connection lbConn2 = getLoadBalancedConnection(null);
+
+ try {
+ assertEquals(this.conn, this.conn);
+ assertEquals(lbConn, lbConn);
+ assertFalse(lbConn.equals(this.conn));
+ assertFalse(lbConn.equals(lbConn2));
+ } finally {
+ lbConn.close();
+ lbConn2.close();
+ }
+ }
}
\ No newline at end of file
| Thread |
|---|
| • Connector/J commit: r6767 - in branches/branch_5_1: . src/com/mysql/jdbc src/testsuite/regression | mmatthews | 31 Mar |