From 9db065ba56558b5556c2293fdc417d315d0cf71d Mon Sep 17 00:00:00 2001
From: Barry Lind <barry@xythos.com>
Date: Tue, 14 Jan 2003 05:46:49 +0000
Subject: [PATCH] Patch from Aaron Mulder to have pooled connections implement
 PGConnection

 Modified Files:
 	jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java
 	jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
---
 .../jdbc2/optional/PooledConnectionImpl.java  |  7 ++++---
 .../jdbc2/optional/BaseDataSourceTest.java    | 21 ++++++++++++++++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java b/src/interfaces/jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java
index 50996d22b54..4970240a030 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java
@@ -4,6 +4,7 @@ import javax.sql.*;
 import java.sql.*;
 import java.util.*;
 import java.lang.reflect.*;
+import org.postgresql.PGConnection;
 
 /**
  * PostgreSQL implementation of the PooledConnection interface.  This shouldn't
@@ -12,7 +13,7 @@ import java.lang.reflect.*;
  * @see ConnectionPool
  *
  * @author Aaron Mulder (ammulder@chariotsolutions.com)
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
  */
 public class PooledConnectionImpl implements PooledConnection
 {
@@ -114,7 +115,7 @@ public class PooledConnectionImpl implements PooledConnection
 		con.setAutoCommit(autoCommit);
 		ConnectionHandler handler = new ConnectionHandler(con);
 		last = handler;
-		Connection con = (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class}, handler);
+		Connection con = (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler);
         last.setProxy(con);
         return con;
 	}
@@ -213,7 +214,7 @@ public class PooledConnectionImpl implements PooledConnection
                                     throw e.getTargetException();
                                 }
 			}
-			// All the rest is from the Connection interface
+			// All the rest is from the Connection or PGConnection interface
 			if (method.getName().equals("isClosed"))
 			{
 				return con == null ? Boolean.TRUE : Boolean.FALSE;
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
index 8add0b19d80..403d9b2b68e 100644
--- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
+++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java
@@ -3,6 +3,7 @@ package org.postgresql.test.jdbc2.optional;
 import junit.framework.TestCase;
 import org.postgresql.test.TestUtil;
 import org.postgresql.jdbc2.optional.BaseDataSource;
+import org.postgresql.PGConnection;
 
 import java.sql.*;
 import java.util.*;
@@ -16,7 +17,7 @@ import javax.naming.*;
  * tests.
  *
  * @author Aaron Mulder (ammulder@chariotsolutions.com)
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
  */
 public abstract class BaseDataSourceTest extends TestCase
 {
@@ -179,6 +180,24 @@ public abstract class BaseDataSourceTest extends TestCase
 		}
 	}
 
+    /**
+     * Test to make sure that PGConnection methods can be called on the
+     * pooled Connection.
+     */
+    public void testPGConnection()
+    {
+        try
+        {
+            con = getDataSourceConnection();
+            ((PGConnection)con).getEncoding().name();
+            con.close();
+        }
+        catch (Exception e)
+        {
+            fail("Unable to call PGConnection method on pooled connection due to "+e.getClass().getName()+" ("+e.getMessage()+")");
+        }
+    }
+
     /**
      * Uses the mini-JNDI implementation for testing purposes
      */
-- 
GitLab