This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_2_510 in repository libpostgresql-jdbc-java.
commit 5a5be9cd5166b76e8707cd1e34cf784ca7d14e38 Author: Kris Jurka <[email protected]> Date: Wed Jan 7 05:29:12 2009 +0000 The Statement and Connection proxies used for connection pooling code relied on the underlying real connection and statement code for equals and hashcode support. When the proxies are closed we discard the references to the real objects, so we can't rely on them for this support because we'll get a NullPointerException. As reported by Radu Buzila. --- .../ds/jdbc23/AbstractJdbc23PooledConnection.java | 38 +++++--------------- .../test/jdbc2/optional/PoolingDataSourceTest.java | 42 ++++++++++++++++++++-- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java b/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java index d6bd9a2..54a225d 100644 --- a/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java +++ b/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java @@ -3,7 +3,7 @@ * Copyright (c) 2004-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL$ +* $PostgreSQL: pgjdbc/org/postgresql/ds/jdbc23/AbstractJdbc23PooledConnection.java,v 1.1.2.1 2007/11/14 22:03:47 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -118,7 +118,7 @@ public abstract class AbstractJdbc23PooledConnection } // If any error occures while opening a new connection, the listeners // have to be notified. This gives a chance to connection pools to - // elliminate bad pooled connections. + // eliminate bad pooled connections. try { // Only one connection can be open at a time from this PooledConnection. See JDBC 2.0 Optional Package spec section 6.2.3 @@ -270,24 +270,13 @@ public abstract class AbstractJdbc23PooledConnection { return "Pooled connection wrapping physical connection " + con; } - if (method.getName().equals("hashCode")) + if (method.getName().equals("equals")) { - return new Integer(con.hashCode()); + return proxy == args[0]; } - if (method.getName().equals("equals")) + if (method.getName().equals("hashCode")) { - if (args[0] == null) - { - return Boolean.FALSE; - } - try - { - return Proxy.isProxyClass(args[0].getClass()) && ((ConnectionHandler) Proxy.getInvocationHandler(args[0])).con == con ? Boolean.TRUE : Boolean.FALSE; - } - catch (ClassCastException e) - { - return Boolean.FALSE; - } + return System.identityHashCode(proxy); } try { @@ -424,22 +413,11 @@ public abstract class AbstractJdbc23PooledConnection } if (method.getName().equals("hashCode")) { - return new Integer(st.hashCode()); + return System.identityHashCode(proxy); } if (method.getName().equals("equals")) { - if (args[0] == null) - { - return Boolean.FALSE; - } - try - { - return Proxy.isProxyClass(args[0].getClass()) && ((StatementHandler) Proxy.getInvocationHandler(args[0])).st == st ? Boolean.TRUE : Boolean.FALSE; - } - catch (ClassCastException e) - { - return Boolean.FALSE; - } + return proxy == args[0]; } return method.invoke(st, args); } diff --git a/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java b/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java index 384f406..60ba5e4 100644 --- a/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java +++ b/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java @@ -3,14 +3,13 @@ * Copyright (c) 2004-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java,v 1.6 2004/11/09 08:55:49 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/optional/PoolingDataSourceTest.java,v 1.7 2005/01/11 08:25:48 jurka Exp $ * *------------------------------------------------------------------------- */ package org.postgresql.test.jdbc2.optional; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import org.postgresql.test.TestUtil; import org.postgresql.jdbc2.optional.PoolingDataSource; import org.postgresql.ds.common.BaseDataSource; @@ -127,4 +126,41 @@ public class PoolingDataSourceTest extends BaseDataSourceTest stmt.close(); con.close(); } + + public void testConnectionObjectMethods() throws SQLException + { + con = getDataSourceConnection(); + + Connection conRef = con; + assertEquals(con, conRef); + + int hc1 = con.hashCode(); + con.close(); + int hc2 = con.hashCode(); + + assertEquals(con, conRef); + assertEquals(hc1, hc2); + } + + public void testStatementObjectMethods() throws SQLException + { + con = getDataSourceConnection(); + + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT 1"); + Statement stmtRef = stmt; + + assertEquals(stmt, stmtRef); + // Currently we aren't proxying ResultSet, so this doesn't + // work, see Bug #1010542. + // assertEquals(stmt, rs.getStatement()); + + int hc1 = stmt.hashCode(); + stmt.close(); + int hc2 = stmt.hashCode(); + + assertEquals(stmt, stmtRef); + assertEquals(hc1, hc2); + } + } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

