Duplicate Proxy.newProxyInstance calls during PGXAConnection.getConnection?

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: pgsql-jdbc(at)lists(dot)postgresql(dot)org
Subject: Duplicate Proxy.newProxyInstance calls during PGXAConnection.getConnection?
Date: 2023-03-26 07:16:59
Message-ID: CAKU4AWog5YvO7wOBQ7nyGhV5JAm2s9sLoANGJMuG6BjJbDPAKA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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 = 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 == 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 = 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/postgresql/xa/PGXAConnection.java#L86

--
Best Regards
Andy Fan

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Andy Fan 2023-03-26 08:16:37 Re: Duplicate Proxy.newProxyInstance calls during PGXAConnection.getConnection?
Previous Message Dave Cramer 2023-02-20 21:21:15 [pgjdbc/pgjdbc] 05b129: Pull fixes for PR#2556 into master (#2826)