Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kz0LQ-00043T-Pg for pgsql-jdbc@arkaria.postgresql.org; Mon, 11 Jan 2021 16:47:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kz0LP-0004pu-NT for pgsql-jdbc@arkaria.postgresql.org; Mon, 11 Jan 2021 16:47:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kz0LP-0004pL-E0 for pgsql-jdbc@lists.postgresql.org; Mon, 11 Jan 2021 16:47:03 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kz0LN-0007DC-9R for pgsql-jdbc@lists.postgresql.org; Mon, 11 Jan 2021 16:47:02 +0000 Received: by mail-il1-x136.google.com with SMTP id w17so154737ilj.8 for ; Mon, 11 Jan 2021 08:47:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=rLjbnydlBk6VXEhOjF0ztHV7qfs4Nxmn/EnUxYaBmIo=; b=dt+sh5gLuZX7J/JSNHHLEx3S9pg97Foo2ie8J/9mwcdEYxolyRAkRpIVHTUQnaici/ LgS6zAGKd+IJIt2/b9v96F/G8MS7LP7qfJ7LRpWiB7YE2r8/4duUkl9vxTBTbIZNOsk9 Pb+Y37s+EknPr+VMZ0DwSeIe44WQGNb0MQXP1h5U5vs3Sw3TMGqy6yppqQYPaHuV5cj2 WWYGYl8GDjDY77fVtiERgMpBLq+ACxFJPkVCRI27EzDX0stMf/fEGaFqDvxhjeRkeA21 K1UvyeIaxF4hUP06OkgngYIQ5Ia+WZDiZWEI6pB/E9/e98FOs7/+m38Ze0VqS1wVrdh2 bV7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=rLjbnydlBk6VXEhOjF0ztHV7qfs4Nxmn/EnUxYaBmIo=; b=RVVYR1jVD9lkt+mS42SHcOrf08Wae3/RL4Osbit6jbZSQkDeee4Oq8Trz2/9kGtvJx PLkh6rpowZ25bgbfkZct6DsPyoCodmc8quaRs/yyC9S/MYEDo0jMDe+bqfn5UqsPduM+ yBS9kil2K2dQr9+E+UyQyYeQ8nPE/ZjCxvnUM8WedbW5K89+CX4By2D6bHpNDnhNHdU+ FLuPe9JS8om50Mterm7+jDdr3p5mkP3UqSJvFpi5MOAHMvsVBRKehsxjb+3UKzkNAAiG ModbCZrNHw3NFV9CyQTs29dahlOjHpZTdwkSg+XmhErbAPVMVf4oMQHifL3YW8nDWT0E poKw== X-Gm-Message-State: AOAM532Hr90DnFf574/Pb4WJab/k/cSQCgpmg6FzvS0FW4pgcXp6VxXh gT3EWcwv+zOMy1U9+ebrtxJWVEdhRFfAeQ== X-Google-Smtp-Source: ABdhPJzV6GaVyMN+d/4IRS2GNh2VFX4ItXI/ru3iOUqmuJtWVJmiJl51FHQeMeIK8SKZbNNDtbI4bA== X-Received: by 2002:a92:603:: with SMTP id x3mr16066ilg.107.1610383620183; Mon, 11 Jan 2021 08:47:00 -0800 (PST) Received: from ?IPv6:2601:681:5500:dde0:98ac:7770:b84:2909? ([2601:681:5500:dde0:98ac:7770:b84:2909]) by smtp.gmail.com with ESMTPSA id f6sm41673ioh.2.2021.01.11.08.46.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Jan 2021 08:46:59 -0800 (PST) Subject: Re: CopyManager uses BaseConnection and I've lost mine To: =?UTF-8?Q?Jorge_Sol=c3=b3rzano?= Cc: "pgsql-jdbc@lists.postgresql.org" References: From: Rob Sargent Message-ID: Date: Mon, 11 Jan 2021 09:46:58 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------5F5A998BBF5D81605D189D3B" Content-Language: en-CA List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------5F5A998BBF5D81605D189D3B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 > 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, MapcsvIds){ > >         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? > > > > --------------5F5A998BBF5D81605D189D3B Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

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> 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?
>
>

--------------5F5A998BBF5D81605D189D3B--