Re: Using CopyManager with pooled JCA connection

From: Jim Garrison <jim(dot)garrison(at)nwea(dot)org>
To: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Using CopyManager with pooled JCA connection
Date: 2013-09-12 21:11:08
Message-ID: 0C723FEB5B4E5642B25B451BA57E27303EE03383@S1P5DAG3C.EXCHPROD.USA.NET
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

>From: Sehrope Sarkuni [mailto:sehrope(at)jackdb(dot)com]
>Sent: Thursday, September 12, 2013 2:01 PM
>One other trick is that if you can get anything that implements java.sql.Connection you can usually get to the "raw" connection by first getting the DB meta data object and then getting the original connection from it.
Spring has a decent explanation of in SimpleNativeJdbcExtractor[1]. Basically you do conn.getMetaData().getConnection()
>If that doesn't work try to programmatically dump the interfaces implemented by the value returned by getPhysicalConnection() and see if any of those have an "unwrap" method on them. It's possible that the "physical connection" is itself a wrapper of the actual connection. I know some connection pools do that.

Looks like we're following the same path. I almost had this working:

private PGConnection getPGConnection(Connection con)
{
PGConnection temp = null;

if (con instanceof ConnectionHandle)
{
Object pc = ((ConnectionHandle) con).getAssociation().getPhysicalConnection();
temp = (PGConnection) pc;
}
else
temp = (PGConnection) con;

return temp;
}

But unfortunately, the two connection objects (source and target databases) are loaded by different classloaders, so the statement

If (con instanceof ConnectionHandle)

Works for one but fails for the second. I will try your getMetadata() suggestion

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2013-09-12 21:34:48 Re: Using CopyManager with pooled JCA connection
Previous Message Jim Garrison 2013-09-12 20:25:16 Re: Using CopyManager with pooled JCA connection