From: Rob Sargent <robjsargent@gmail.com>
To: Jorge Solórzano <jorsol@gmail.com>
Cc: pgsql-jdbc@lists.postgresql.org <pgsql-jdbc@lists.postgresql.org>
Subject: Re: CopyManager uses BaseConnection and I've lost mine
Date: Mon, 11 Jan 2021 09:46:58 -0700
Message-ID: <f88b45ed-1238-f489-94d4-323794cbf876@gmail.com> (raw)
In-Reply-To: <CA+cVU8MzXFyNKyt9_+ONSAWO5n1KkmL==dNqePd7vrfiSFddKA@mail.gmail.com>
References: <e9998831-264c-2f70-f1c6-62905a4d75fb@gmail.com>
<CA+cVU8MzXFyNKyt9_+ONSAWO5n1KkmL==dNqePd7vrfiSFddKA@mail.gmail.com>
On 1/11/21 4:53 AM, Jorge Solórzano wrote:
> Hi Rob,
>
> The extension API should be used like this:
>
> CopyManager copyManager =
> getConnection().unwrap(org.postgresql.PGConnection.class).getCopyAPI();
>
>
> Please try and report if this works.
>
> Thanks,
Yes, thank you very much, that works perfectly. My apologies for not
finding the "uwwrap" call.
rjs
>
> On Mon, Jan 11, 2021 at 2:25 AM Rob Sargent <robjsargent@gmail.com
> <mailto:robjsargent@gmail.com>> wrote:
> >
> > Maybe I'm getting a little ahead of myself.
> >
> > java 15 (Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed
> mode, sharing)
> > tomcat 9.0.41 (org.apache.tomcat.jdbc.pool.DataSource)
> > postgresql:42.2.+
> > jooq 3.14
> >
> > Lots of db successful db interactions in this configuration, but
> when I want to use the CopyManager to slam lots of records home with
> >
> > private void writeSegmentWithCOPY(DSLContext topctx, UUID
> markers, Map<String,UUID>csvIds){
> > topctx.transaction(topconf -> {
> > DSLContext ctx = DSL.using(topconf);
> > CopyManager copyManager = new CopyManager((BaseConnection)
> getConnection());
> > String copyToStatement = String.format("COPY %s FROM STDIN
> CSV", getStagingTableName());
> > createStagingTable(ctx, getStagingTableName());
> > CopyIn copyIn = copyManager.copyIn(copyToStatement);
> >
> > where "getConnection()" is a simple getter on java.sql.Connection
> class member which in turn set from JNDI DataSource.getConnection()
> and I'm getting
> >
> > class com.sun.proxy.$Proxy4 cannot be cast to class
> org.postgresql.core.BaseConnection
> >
> > on the "new CopyManager" line. I had been using DriverManager, but
> thought that was inappropriate with tomcat in play.
> >
> > Two questions, aside from the obvious Walter Tango Foxtrot
> > 1. The javadoc for BaseConnect suggests "Application code should not
> use this interface" but CopyManager expects exactly that. Is that not
> a contradiction?
> > 2. Is DriverManager more appropriate?
> >
> >
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: robjsargent@gmail.com, jorsol@gmail.com
Subject: Re: CopyManager uses BaseConnection and I've lost mine
In-Reply-To: <f88b45ed-1238-f489-94d4-323794cbf876@gmail.com>
References: <e9998831-264c-2f70-f1c6-62905a4d75fb@gmail.com> <CA+cVU8MzXFyNKyt9_+ONSAWO5n1KkmL==dNqePd7vrfiSFddKA@mail.gmail.com> <f88b45ed-1238-f489-94d4-323794cbf876@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox