Skip to content

Commit 9db065b

Browse files
author
Barry Lind
committed
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
1 parent 88e5240 commit 9db065b

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/interfaces/jdbc/org/postgresql/jdbc2/optional/PooledConnectionImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.sql.*;
55
import java.util.*;
66
import java.lang.reflect.*;
7+
import org.postgresql.PGConnection;
78

89
/**
910
* PostgreSQL implementation of the PooledConnection interface. This shouldn't
@@ -12,7 +13,7 @@
1213
* @see ConnectionPool
1314
*
1415
* @author Aaron Mulder (ammulder@chariotsolutions.com)
15-
* @version $Revision: 1.5 $
16+
* @version $Revision: 1.6 $
1617
*/
1718
public class PooledConnectionImpl implements PooledConnection
1819
{
@@ -114,7 +115,7 @@ public Connection getConnection() throws SQLException
114115
con.setAutoCommit(autoCommit);
115116
ConnectionHandler handler = new ConnectionHandler(con);
116117
last = handler;
117-
Connection con = (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class}, handler);
118+
Connection con = (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler);
118119
last.setProxy(con);
119120
return con;
120121
}
@@ -213,7 +214,7 @@ public Object invoke(Object proxy, Method method, Object[] args)
213214
throw e.getTargetException();
214215
}
215216
}
216-
// All the rest is from the Connection interface
217+
// All the rest is from the Connection or PGConnection interface
217218
if (method.getName().equals("isClosed"))
218219
{
219220
return con == null ? Boolean.TRUE : Boolean.FALSE;

src/interfaces/jdbc/org/postgresql/test/jdbc2/optional/BaseDataSourceTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import junit.framework.TestCase;
44
import org.postgresql.test.TestUtil;
55
import org.postgresql.jdbc2.optional.BaseDataSource;
6+
import org.postgresql.PGConnection;
67

78
import java.sql.*;
89
import java.util.*;
@@ -16,7 +17,7 @@
1617
* tests.
1718
*
1819
* @author Aaron Mulder (ammulder@chariotsolutions.com)
19-
* @version $Revision: 1.4 $
20+
* @version $Revision: 1.5 $
2021
*/
2122
public abstract class BaseDataSourceTest extends TestCase
2223
{
@@ -179,6 +180,24 @@ public void testNotPooledConnection()
179180
}
180181
}
181182

183+
/**
184+
* Test to make sure that PGConnection methods can be called on the
185+
* pooled Connection.
186+
*/
187+
public void testPGConnection()
188+
{
189+
try
190+
{
191+
con = getDataSourceConnection();
192+
((PGConnection)con).getEncoding().name();
193+
con.close();
194+
}
195+
catch (Exception e)
196+
{
197+
fail("Unable to call PGConnection method on pooled connection due to "+e.getClass().getName()+" ("+e.getMessage()+")");
198+
}
199+
}
200+
182201
/**
183202
* Uses the mini-JNDI implementation for testing purposes
184203
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy