db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1841138 - in /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util: TorqueConnectionImpl.java TransactionManagerImpl.java
Date Mon, 17 Sep 2018 19:49:31 GMT
Author: tv
Date: Mon Sep 17 19:49:31 2018
New Revision: 1841138

URL: http://svn.apache.org/viewvc?rev=1841138&view=rev
Log:
Move connection state tracking to TransactionManagerImpl

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TorqueConnectionImpl.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TorqueConnectionImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TorqueConnectionImpl.java?rev=1841138&r1=1841137&r2=1841138&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TorqueConnectionImpl.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TorqueConnectionImpl.java
Mon Sep 17 19:49:31 2018
@@ -68,23 +68,43 @@ public class TorqueConnectionImpl implem
     }
 
     /**
-     * Has commit() been called successfully on this connection?
-     * (for testing)
+     * Called by TransactionManagerImpl.commit() to track state
      *
-     * @return true, if commit() has been called.
+     * @param committed the committed state to set
      */
-    public boolean isCommitted()
+    protected void setCommitted(boolean committed)
+    {
+        this.committed = committed;
+    }
+
+    /**
+     * Has Transaction.commit() been called successfully on
+     * this connection?
+     *
+     * @return true, if Transaction.commit() has been called.
+     */
+    protected boolean isCommitted()
     {
         return committed;
     }
 
     /**
-     * Has rollback() been called successfully on this connection?
-     * (for testing)
+     * Called by TransactionManagerImpl.rollback() to track state
+     *
+     * @param rolledBack the rolledBack state to set
+     */
+    protected void setRolledBack(boolean rolledBack)
+    {
+        this.rolledBack = rolledBack;
+    }
+
+    /**
+     * Has Transaction.rollback() been called successfully on
+     * this connection?
      *
-     * @return true, if rollback() has been called.
+     * @return true, if Transaction.rollback() has been called.
      */
-    public boolean isRolledBack()
+    protected boolean isRolledBack()
     {
         return rolledBack;
     }
@@ -168,7 +188,6 @@ public class TorqueConnectionImpl implem
     public void commit() throws SQLException
     {
         connection.commit();
-        this.committed = true;
     }
 
     /**
@@ -178,7 +197,6 @@ public class TorqueConnectionImpl implem
     public void rollback() throws SQLException
     {
         connection.rollback();
-        this.rolledBack = true;
     }
 
     /**
@@ -189,14 +207,13 @@ public class TorqueConnectionImpl implem
     {
         try
         {
-            if (!this.committed && !this.rolledBack
-                    && !connection.getAutoCommit())
+            if (!isCommitted())
             {
                 // calls close on the connection
                 Transaction.safeRollback(connection);
-                this.rolledBack = true;
             }
 
+            // Justin Case
             if (!connection.isClosed())
             {
                 connection.close();
@@ -204,7 +221,7 @@ public class TorqueConnectionImpl implem
         }
         catch (SQLException e)
         {
-            throw new TorqueException(e);
+            throw ExceptionMapper.getInstance().toTorqueException(e);
         }
     }
 

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java?rev=1841138&r1=1841137&r2=1841138&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java
Mon Sep 17 19:49:31 2018
@@ -105,11 +105,16 @@ public class TransactionManagerImpl impl
                     && !con.getAutoCommit())
             {
                 con.commit();
+
+                if (con instanceof TorqueConnectionImpl)
+                {
+                    ((TorqueConnectionImpl) con).setCommitted(true);
+                }
             }
         }
         catch (SQLException e)
         {
-            throw new TorqueException(e);
+            throw ExceptionMapper.getInstance().toTorqueException(e);
         }
         finally
         {
@@ -145,6 +150,11 @@ public class TransactionManagerImpl impl
                         && !con.getAutoCommit())
                 {
                     con.rollback();
+
+                    if (con instanceof TorqueConnectionImpl)
+                    {
+                        ((TorqueConnectionImpl) con).setRolledBack(true);
+                    }
                 }
             }
             catch (SQLException e)
@@ -152,7 +162,7 @@ public class TransactionManagerImpl impl
                 log.error("An attempt was made to rollback a transaction "
                         + "but the database did not allow the operation to be "
                         + "rolled back.", e);
-                throw new TorqueException(e);
+                throw ExceptionMapper.getInstance().toTorqueException(e);
             }
             finally
             {



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message