[libpostgresql-jdbc-java] 19/24: Fix equals-method of the wrapper returned by PGXAConnection.getConnection()
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 21:17:40 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL9_3_1103
in repository libpostgresql-jdbc-java.
commit a0247663234db69ba838b252d7e3a90ff12e2152
Author: Heikki Linnakangas <heikki.linnakangas at iki.fi>
Date: Wed Feb 26 14:50:17 2014 +0200
Fix equals-method of the wrapper returned by PGXAConnection.getConnection()
Patch by Florent Guillaume
---
org/postgresql/test/xa/XADataSourceTest.java | 8 ++++++++
org/postgresql/xa/PGXAConnection.java | 17 +++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/org/postgresql/test/xa/XADataSourceTest.java b/org/postgresql/test/xa/XADataSourceTest.java
index 731c3ca..fc80dae 100644
--- a/org/postgresql/test/xa/XADataSourceTest.java
+++ b/org/postgresql/test/xa/XADataSourceTest.java
@@ -127,6 +127,14 @@ public class XADataSourceTest extends TestCase {
}
}
+ /*
+ * Check that the equals method works for the connection wrapper returned
+ * by PGXAConnection.getConnection().
+ */
+ public void testWrapperEquals() throws Exception {
+ assertTrue("Wrappers should be equal", conn.equals(conn));
+ }
+
public void testOnePhase() throws Exception {
Xid xid = new CustomXid(1);
xaRes.start(xid, XAResource.TMNOFLAGS);
diff --git a/org/postgresql/xa/PGXAConnection.java b/org/postgresql/xa/PGXAConnection.java
index 4086dc9..f1e2921 100644
--- a/org/postgresql/xa/PGXAConnection.java
+++ b/org/postgresql/xa/PGXAConnection.java
@@ -150,6 +150,23 @@ public class PGXAConnection extends PGPooledConnection implements XAConnection,
}
}
try {
+ /*
+ * If the argument to equals-method is also a wrapper,
+ * present the original unwrapped connection to the underlying
+ * equals method.
+ */
+ if (method.getName().equals("equals")) {
+ Object arg = args[0];
+ if (Proxy.isProxyClass(arg.getClass())) {
+ InvocationHandler h = Proxy.getInvocationHandler(arg);
+ if (h instanceof ConnectionHandler) {
+ // unwrap argument
+ args = new Object[] {
+((ConnectionHandler) h).con };
+ }
+ }
+ }
+
return method.invoke(con, args);
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list