Author: michiel
Date: 2010-01-21 17:33:14 +0100 (Thu, 21 Jan 2010)
New Revision: 40661

Modified:
   
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/storage/implementation/database/DatabaseStorageManager.java
Log:
MMB-1915

Modified: 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/storage/implementation/database/DatabaseStorageManager.java
===================================================================
--- 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/storage/implementation/database/DatabaseStorageManager.java
        2010-01-21 15:58:45 UTC (rev 40660)
+++ 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/storage/implementation/database/DatabaseStorageManager.java
        2010-01-21 16:33:14 UTC (rev 40661)
@@ -1095,33 +1095,44 @@
         try {
             return executeUpdate(query, node, fields);
         } catch (SQLException sqe) {
-            while (true) {
-                Statement s = null;
-                ResultSet rs = null;
+            if (! inTransaction) {
+                while (true) {
+                    Statement s = null;
+                    ResultSet rs = null;
+                    try {
+                        s = activeConnection.createStatement();
+                        rs = s.executeQuery("SELECT 1 FROM " + 
factory.getMMBase().getBuilder("object").getFullTableName() + " WHERE 1 = 0"); 
// if this goes wrong too it can't be the query
+                    } catch (SQLException isqe) {
+                        // so, connection must be broken.
+                        log.service("Found broken connection, closing it");
+                        if (activeConnection instanceof 
org.mmbase.module.database.MultiConnection) {
+                            ((org.mmbase.module.database.MultiConnection) 
activeConnection).realclose();
+                        } else {
+                            activeConnection.close();
+                        }
+                        getActiveConnection();
+                        if (activeConnection.isClosed()) {
+                            // don't know if that can happen, but if it 
happens, this would perhaps avoid an infinite loop (and exception will get 
thrown in stead)
+                            break;
+                        }
+                        continue;
+                    } finally {
+                        if (s != null) s.close();
+                        if (rs != null) rs.close();
+                    }
+                    break;
+                }
                 try {
-                    s = activeConnection.createStatement();
-                    rs = s.executeQuery("SELECT 1 FROM " + 
factory.getMMBase().getBuilder("object").getFullTableName() + " WHERE 1 = 0"); 
// if this goes wrong too it can't be the query
-                } catch (SQLException isqe) {
-                    // so, connection must be broken.
-                    log.service("Found broken connection, closing it");
-                    if (activeConnection instanceof 
org.mmbase.module.database.MultiConnection) {
-                        ((org.mmbase.module.database.MultiConnection) 
activeConnection).realclose();
-                    } else {
-                        activeConnection.close();
-                    }
-                    getActiveConnection();
-                    if (activeConnection.isClosed()) {
-                        // don't know if that can happen, but if it happens, 
this would perhaps avoid an infinite loop (and exception will get thrown in 
stead)
-                        break;
-                    }
-                    continue;
-                 } finally {
-                     if (s != null) s.close();
-                     if (rs != null) rs.close();
-                 }
-                break;
+                    log.info("Second try update with new connection");
+                    return executeUpdate(query, node, fields);
+                } catch (Exception e) {
+                    throw sqe;
+                }
+            } else {
+                // Dont' close connections in a transaction.
+                // In e.g. postgresql even the SELECT won't work then any 
more, so don't even try that.
+                throw sqe;
             }
-            return executeUpdate(query, node, fields);
         }
     }
 

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to