Re: Using CopyManager with pooled JCA connection - Mailing list pgsql-jdbc

From Jim Garrison
Subject Re: Using CopyManager with pooled JCA connection
Date
Msg-id 0C723FEB5B4E5642B25B451BA57E27303EE03383@S1P5DAG3C.EXCHPROD.USA.NET
Whole thread Raw
In response to Using CopyManager with pooled JCA connection  (Jim Garrison <jim.garrison@nwea.org>)
Responses Re: Using CopyManager with pooled JCA connection  (Jim Garrison <jim.garrison@nwea.org>)
Re: Using CopyManager with pooled JCA connection  (Kris Jurka <books@ejurka.com>)
List pgsql-jdbc
>From: Sehrope Sarkuni [mailto:sehrope@jackdb.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"
connectionby 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
thestatement 

    If (con instanceof ConnectionHandle)

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



pgsql-jdbc by date:

Previous
From: Jim Garrison
Date:
Subject: Re: Using CopyManager with pooled JCA connection
Next
From: Jim Garrison
Date:
Subject: Re: Using CopyManager with pooled JCA connection