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 1pgLYd-0001vj-S9 for pgsql-jdbc@arkaria.postgresql.org; Sun, 26 Mar 2023 08:16:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pgLYc-0005XI-GP for pgsql-jdbc@arkaria.postgresql.org; Sun, 26 Mar 2023 08:16:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgLYc-0005V5-6c for pgsql-jdbc@lists.postgresql.org; Sun, 26 Mar 2023 08:16:54 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pgLYZ-0003yn-7X for pgsql-jdbc@lists.postgresql.org; Sun, 26 Mar 2023 08:16:53 +0000 Received: by mail-oi1-x229.google.com with SMTP id bm2so4274222oib.4 for ; Sun, 26 Mar 2023 01:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679818608; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=v41WqWw/wGTT1miyYhalfYXXFYtjeqkSxYJv63BC71A=; b=ComtqZtNOYxkguFFyazx/wQqyE3XkLOrebFnitF9SXYFPwZgLx5YrB8yaLLRZ+VDVj gyXeur+tVZ/+qJddBGz8bUubErd+uTiJQM+5aio9u3ZkI5Fz4nhAtVJYVWiF9MxTQSkY cGWjojQwR9efeZNtLKdrKgzA+k2/9gjY9YSqhUY50kkYIfXRDuhos5L2c3aSmpGt8nE9 y9Grf5rYjSTxBJ4DRlJukBBLZPzV3XEqr1b6SFGJsQ4YQsZUYoDT5p7YbZRfG0dS+xjw SE5YUk4ZKeLy8NVw3KMnIgCccELYP+TQ/x2x5IQxCLPh/qAh8aRdXllTvK4bgz43zy6D KzwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679818608; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=v41WqWw/wGTT1miyYhalfYXXFYtjeqkSxYJv63BC71A=; b=a+Cqa6Gv6qlgZWxf9glMVvDlxO8K6hy1r10H+ehdYqJveei1iIUfnoVtTXwyWtGYsB 5QA/WsBWkMX7Vlb43dpUZpQOZyvKTl8Y6QAyJnUYqvdyiFgTXl/NLfy655YAKPFuDhiM 9jOHnvSMyA3y3bFyqPPV+dO3GtR8C/sZ7o66bIDIlxmRo3ZOsRDaA6p8jgWuHGwCp308 3h0m61Yg4CvhfIuqE0Qt33Fm5mHnX3v6rDFEU8m0Jxs0/ZYytY/HXeo0jd6BqjO/eJml 7LBvPc8IFBzfGyiAqztY75vauvga5I15tN2+ENhZRkxtA23GY/U7vc+try9pl6JO4y/C 1CWQ== X-Gm-Message-State: AO0yUKWMZvIeLBP7c/pZxD3SO4LWZbYMyBzMFy6DCt0HlE3PawrLE6iy BovMUIE2pLlWxae5F5VWNyAo885r8c7LGm4D6B5dUPaaPCs= X-Google-Smtp-Source: AK7set/CQ/FipjP5GrIpoTgTDQZ06/qyRKK+J56naSM+XR4dN3igWS9bB7VaNaQdPVrd1lvs/znEP6Sv1+rXrvJBXdU= X-Received: by 2002:a05:6808:1452:b0:386:a109:57c8 with SMTP id x18-20020a056808145200b00386a10957c8mr2235544oiv.5.1679818608684; Sun, 26 Mar 2023 01:16:48 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Fan Date: Sun, 26 Mar 2023 16:16:37 +0800 Message-ID: Subject: Re: Duplicate Proxy.newProxyInstance calls during PGXAConnection.getConnection? To: pgsql-jdbc@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000075341e05f7c93fbc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000075341e05f7c93fbc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Please forgive me, I was totally wrong here. Sorry for the noise. On Sun, Mar 26, 2023 at 3:16=E2=80=AFPM Andy Fan = wrote: > In the PGXAConnection.GetConnection() [1], we can see the below code: > > @Override > public Connection getConnection() throws SQLException { > > // *the first time ConnectionHandler has been created.* > Connection conn =3D super.getConnection(); > > // When we're outside an XA transaction, autocommit > // is supposed to be true, per usual JDBC convention. > // When an XA transaction is in progress, it should be > // false. > if (state =3D=3D State.IDLE) { > conn.setAutoCommit(true); > } > > /* > * Wrap the connection in a proxy to forbid application from fiddling= with transaction state > * directly during an XA transaction > */ > > // *ConnectionHandler is created again here. * > ConnectionHandler handler =3D new ConnectionHandler(conn); > return (Connection) Proxy.newProxyInstance(getClass().getClassLoader(= ), > new Class[]{Connection.class, PGConnection.class}, handler); > } > > > However I think the proxy has already been created at the first line: > super.getConnection(), > and then it is created later. Is it a duplication? > > [1] > https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/pos= tgresql/xa/PGXAConnection.java#L86 > > > -- > Best Regards > Andy Fan > --=20 Best Regards Andy Fan --00000000000075341e05f7c93fbc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Please forgive me, I was totally wrong here.=C2=A0 Sorry f= or=C2=A0the noise.=C2=A0

On Sun, Mar 26, 2023 at 3:16=E2=80=AFPM Andy Fan &l= t;zhihui.fan1213@gmail.com&= gt; wrote:
In the PGXAConnection.GetConnection() [1], we can see the below= code:

 =
 @Override
  public Connection getConnection() throws SQLException {
    // the first time Connect=
ionHandler has been created.
    Connection conn =3D super.getConnection();  =20

    // When we're outside an XA transaction, autocommit
    // is supposed to be true, per usual JDBC convention.
    // When an XA transaction is in progress, it should be
    // false.
    if (state =3D=3D State.IDLE) {
      conn.setAutoCommit(true);
    }

    /*
     * Wrap the connection in a proxy to forbid application from fiddling w=
ith transaction state
     * directly during an XA transaction
     */
    // ConnectionHandler is created again here. 
    ConnectionHandler handler =3D new ConnectionHandler(conn);
    return (Connection) Proxy.newProxyInstance(getClass().getClassLoader(),
        new Class[]{Connection.class, PGConnection.class}, handler);
  }

However I think the proxy ha= s already been created at the first line: super.getConnection(),=C2=A0
and then it is created later.=C2=A0 Is it a duplication?=C2=A0
<= div>


--
Best Regards
Andy Fan
--00000000000075341e05f7c93fbc--