pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
[pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
7+ messages / 2 participants
[nested] [flat]

* [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
@ 2025-12-18 13:07  "davecramer (@davecramer)" <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: davecramer (@davecramer) @ 2025-12-18 13:07 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

fixes #3892 

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
@ 2026-01-05 15:51  "CTH57 (@CTH57)" <[email protected]>
  5 siblings, 0 replies; 7+ messages in thread

From: CTH57 (@CTH57) @ 2026-01-05 15:51 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Are you sure of your correction ?
If the connection is read only, the attempt to execute the prepare transaction will throw an exception. 
The test conn.isReadOnly should be before.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
@ 2026-01-05 15:53  "CTH57 (@CTH57)" <[email protected]>
  5 siblings, 0 replies; 7+ messages in thread

From: CTH57 (@CTH57) @ 2026-01-05 15:53 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Proposition 👍 

    if (conn.isReadOnly()) {
      return XA_RDONLY;
    }
    
    state = State.IDLE;
    preparedXid = currentXid;
    currentXid = null;

    try {
      String s = RecoveredXid.xidToString(xid);

      try (Statement stmt = conn.createStatement()) {
        stmt.executeUpdate("PREPARE TRANSACTION '" + s + "'");
      }
      conn.setAutoCommit(localAutoCommitMode);
      
      return XA_OK;
    } catch (SQLException ex) {
      throw new PGXAException(GT.tr("Error preparing transaction. prepare xid={0}", xid), ex, mapSQLStateToXAErrorCode(ex));
    }

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
@ 2026-01-05 15:57  "davecramer (@davecramer)" <[email protected]>
  5 siblings, 0 replies; 7+ messages in thread

From: davecramer (@davecramer) @ 2026-01-05 15:57 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Is it not possible to have a XA transaction on read only connections ?

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
@ 2026-01-06 07:19  "CTH57 (@CTH57)" <[email protected]>
  5 siblings, 0 replies; 7+ messages in thread

From: CTH57 (@CTH57) @ 2026-01-06 07:19 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

If during a transaction, a read only connextion is used to select data and another connection is used to insert data, boths connections are enlist in the XATransaction.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
@ 2026-01-06 10:47  "davecramer (@davecramer)" <[email protected]>
  5 siblings, 0 replies; 7+ messages in thread

From: davecramer (@davecramer) @ 2026-01-06 10:47 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

After doing more reading I'm not even sure we should be returning XA_RDONLY at all, this is the job of the XA manager. XA_RDONLY is returned by prepare when no data has changed, ie the transaction only reads data. As such no commit is necessary. see https://www.ibm.com/docs/en/i/7.6.0?topic=applications-example-using-cli-xa-transaction-connection-a... or https://docs.oracle.com/javase/8/docs/api/javax/transaction/xa/XAResource.html#XA_RDONLY. If in fact you provide a read only connection and a writer connection and expect data to be written the correct thing to do here is throw an exception as the data was not written and can't possibly be written.

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only
@ 2026-01-06 11:04  "CTH57 (@CTH57)" <[email protected]>
  5 siblings, 0 replies; 7+ messages in thread

From: CTH57 (@CTH57) @ 2026-01-06 11:04 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

"XA_RDONLY is returned by prepare when no data has changed, ie the transaction only reads data"

Yes and it's obviously the case if the connection is read only.

In my case, the read only connection is used only to read data, so no need to commit this connection. 

^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2026-01-06 11:04 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-18 13:07 [pgjdbc/pgjdbc] PR #3897: fix: issue #3892, PGXAConnection.prepare(Xid) should return XA_RDONLY if the connection is read only "davecramer (@davecramer)" <[email protected]>
2026-01-05 15:51 ` "CTH57 (@CTH57)" <[email protected]>
2026-01-05 15:53 ` "CTH57 (@CTH57)" <[email protected]>
2026-01-05 15:57 ` "davecramer (@davecramer)" <[email protected]>
2026-01-06 07:19 ` "CTH57 (@CTH57)" <[email protected]>
2026-01-06 10:47 ` "davecramer (@davecramer)" <[email protected]>
2026-01-06 11:04 ` "CTH57 (@CTH57)" <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox