[libpostgresql-jdbc-java] 01/11: When the Connection retrieved from XAConnection.getConnection() is closed we do not want to rollback the transaction because the underlying connection is not closed and the transaction is being managed by the XAResource, not the Connection.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:52 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_1_406
in repository libpostgresql-jdbc-java.

commit 4ad14452bc6795681b13516f8fcfdf9352aa2b84
Author: Kris Jurka <books at ejurka.com>
Date:   Wed Apr 26 18:59:31 2006 +0000

    When the Connection retrieved from XAConnection.getConnection() is
    closed we do not want to rollback the transaction because the
    underlying connection is not closed and the transaction is being
    managed by the XAResource, not the Connection.
    
    As reported by Niels Beekman.
---
 org/postgresql/ds/common/PooledConnectionImpl.java | 15 +++++++++++----
 org/postgresql/test/xa/XADataSourceTest.java       | 13 +++++++++++++
 org/postgresql/xa/PGXAConnection.java              |  2 +-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/org/postgresql/ds/common/PooledConnectionImpl.java b/org/postgresql/ds/common/PooledConnectionImpl.java
index f18652b..d8a6115 100644
--- a/org/postgresql/ds/common/PooledConnectionImpl.java
+++ b/org/postgresql/ds/common/PooledConnectionImpl.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/ds/common/PooledConnectionImpl.java,v 1.9 2005/01/14 01:20:17 oliver Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/ds/common/PooledConnectionImpl.java,v 1.10 2005/01/17 10:59:04 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -32,16 +32,23 @@ public class PooledConnectionImpl implements PooledConnection
     private List listeners = new LinkedList();
     private Connection con;
     private ConnectionHandler last;
-    private boolean autoCommit;
+    private final boolean autoCommit;
+    private final boolean isXA;
 
     /**
      * Creates a new PooledConnection representing the specified physical
      * connection.
      */
-    public PooledConnectionImpl(Connection con, boolean autoCommit)
+    public PooledConnectionImpl(Connection con, boolean autoCommit, boolean isXA)
     {
         this.con = con;
         this.autoCommit = autoCommit;
+        this.isXA = isXA;
+    }
+
+    public PooledConnectionImpl(Connection con, boolean autoCommit)
+    {
+        this(con, autoCommit, false);
     }
 
     /**
@@ -306,7 +313,7 @@ public class PooledConnectionImpl implements PooledConnection
                     return null;
 
                 SQLException ex = null;
-                if (!con.getAutoCommit())
+                if (!isXA && !con.getAutoCommit())
                 {
                     try
                     {
diff --git a/org/postgresql/test/xa/XADataSourceTest.java b/org/postgresql/test/xa/XADataSourceTest.java
index e676393..45a4632 100644
--- a/org/postgresql/test/xa/XADataSourceTest.java
+++ b/org/postgresql/test/xa/XADataSourceTest.java
@@ -142,6 +142,19 @@ public class XADataSourceTest extends TestCase {
         xaRes.commit(xid, false);
     }
 
+    public void testCloseBeforeCommit() throws Exception {
+        Xid xid = new CustomXid(5);
+        xaRes.start(xid, XAResource.TMNOFLAGS);
+        assertEquals(1, conn.createStatement().executeUpdate("INSERT INTO testxa1 VALUES (1)"));
+        conn.close();
+        xaRes.end(xid, XAResource.TMSUCCESS);
+        xaRes.commit(xid, true);
+
+        ResultSet rs = _conn.createStatement().executeQuery("SELECT foo FROM testxa1");
+        assertTrue(rs.next());
+        assertEquals(1, rs.getInt(1));
+    }
+
     public void testRecover() throws Exception {
         Xid xid = new CustomXid(12345);
         xaRes.start(xid, XAResource.TMNOFLAGS);
diff --git a/org/postgresql/xa/PGXAConnection.java b/org/postgresql/xa/PGXAConnection.java
index ce66ac6..77ca9d0 100644
--- a/org/postgresql/xa/PGXAConnection.java
+++ b/org/postgresql/xa/PGXAConnection.java
@@ -48,7 +48,7 @@ public class PGXAConnection extends PooledConnectionImpl implements XAConnection
 
     PGXAConnection(BaseConnection conn) throws SQLException
     {
-        super(conn, false);
+        super(conn, false, true);
         this.conn = conn;
         this.conn.setAutoCommit(false);
         this.state = STATE_IDLE;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list