Title: [1009] trunk/activerecord-jdbc: 18846: retrying failing SQL statements is harmful when not autocommitting ( Craig McMillan)
Revision
1009
Author
nicksieger
Date
2008-06-03 23:16:57 -0400 (Tue, 03 Jun 2008)

Log Message

18846: retrying failing SQL statements is harmful when not autocommitting (Craig McMillan)

Modified Paths

Diff

Modified: trunk/activerecord-jdbc/History.txt (1008 => 1009)


--- trunk/activerecord-jdbc/History.txt	2008-06-04 03:16:52 UTC (rev 1008)
+++ trunk/activerecord-jdbc/History.txt	2008-06-04 03:16:57 UTC (rev 1009)
@@ -13,6 +13,7 @@
 - 20243: numerics improvements for MSSQL (Aslak Hellesøy)
 - 20172: don't quote table names for MSSQL (Thor Marius Henrichsen)
 - 19729: check for primary key existence in postgres during insert (Martin Luder)
+- 18846: retrying failing SQL statements is harmful when not autocommitting (Craig McMillan)
 
 == 0.8
 

Modified: trunk/activerecord-jdbc/src/java/jdbc_adapter/JdbcAdapterInternalService.java (1008 => 1009)


--- trunk/activerecord-jdbc/src/java/jdbc_adapter/JdbcAdapterInternalService.java	2008-06-04 03:16:52 UTC (rev 1008)
+++ trunk/activerecord-jdbc/src/java/jdbc_adapter/JdbcAdapterInternalService.java	2008-06-04 03:16:57 UTC (rev 1009)
@@ -233,27 +233,31 @@
         int tries = 1;
         int i = 0;
         Throwable toWrap = null;
+        boolean autoCommit = false;
         while (i < tries) {
             Connection c = getConnection(recv);
             try {
+                autoCommit = c.getAutoCommit();
                 return block.call(c);
             } catch (Exception e) {
                 toWrap = e;
                 while (toWrap.getCause() != null && toWrap.getCause() != toWrap) {
                     toWrap = toWrap.getCause();
                 }
-                if (i == 0) {
-                    tries = (int) rubyApi.convertToRubyInteger(config_value(recv, "retry_count")).getLongValue();
-                    if (tries <= 0) {
-                        tries = 1;
+                i++;
+                if (autoCommit) {
+                    if (i == 1) {
+                        tries = (int) rubyApi.convertToRubyInteger(config_value(recv, "retry_count")).getLongValue();
+                        if (tries <= 0) {
+                            tries = 1;
+                        }
                     }
+                    if (isConnectionBroken(recv, c)) {
+                        reconnect(recv);
+                    } else {
+                        throw wrap(recv, toWrap);
+                    }
                 }
-                i++;
-                if (isConnectionBroken(recv, c)) {
-                    reconnect(recv);
-                } else {
-                    throw wrap(recv, toWrap);
-                }
             }
         }
         throw wrap(recv, toWrap);
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to