servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r490828 - in /incubator/servicemix/trunk/core: servicemix-audit/src/main/java/org/apache/servicemix/jbi/audit/jdbc/ servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/ servicemix-services/src/main/java/org/apache/servicemi...
Date Thu, 28 Dec 2006 21:22:27 GMT
Author: gnodet
Date: Thu Dec 28 13:22:26 2006
New Revision: 490828

URL: http://svn.apache.org/viewvc?view=rev&rev=490828
Log:
SM-742: Need to explicitely set autoCommit to false

Modified:
    incubator/servicemix/trunk/core/servicemix-audit/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java
    incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
    incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java

Modified: incubator/servicemix/trunk/core/servicemix-audit/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-audit/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java?view=diff&rev=490828&r1=490827&r2=490828
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-audit/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java
(original)
+++ incubator/servicemix/trunk/core/servicemix-audit/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java
Thu Dec 28 13:22:26 2006
@@ -81,8 +81,13 @@
             statements.setStoreTableName(tableName);
         }
         Connection connection = null;
+        boolean restoreAutoCommit = false;
         try {
             connection = getDataSource().getConnection();
+            if (connection.getAutoCommit()) {
+                connection.setAutoCommit(false);
+                restoreAutoCommit = true;
+            }
             adapter = JDBCAdapterFactory.getAdapter(connection);
             if (statements == null) {
                 statements = new Statements();
@@ -96,12 +101,7 @@
         } catch (SQLException e) {
             throw (IOException) new IOException("Exception while creating database").initCause(e);

         } finally {
-            if (connection != null) {
-                try {
-                    connection.close();
-                } catch (Exception e) {
-                }
-            }
+            close(connection, restoreAutoCommit);
         }
         init(getContainer());
         if (autoStart) {
@@ -120,28 +120,24 @@
             ExchangePacket packet = ((MessageExchangeImpl) exchange).getPacket();
             String id = packet.getExchangeId();
             byte[] data = packet.getData();
-            Connection connection = dataSource.getConnection();
+            Connection connection = null;
+            boolean restoreAutoCommit = false;
             try {
+                connection = dataSource.getConnection();
+                if (connection.getAutoCommit()) {
+                    connection.setAutoCommit(false);
+                    restoreAutoCommit = true;
+                }
                 store(connection, id, data);
                 connection.commit();
             } finally {
-                close(connection);
+                close(connection, restoreAutoCommit);
             }
         } catch (Exception e) {
             log.error("Could not persist exchange", e);
         }
     }
     
-    private static void close(Connection connection) {
-        if (connection != null) {
-            try {
-                connection.close();
-            } catch (SQLException e) {
-            }
-        }
-        
-    }
-
     protected void store(Connection connection, String id, byte[] data) throws Exception
{
         if (adapter.doLoadData(connection, id) != null) {
             adapter.doUpdateData(connection, id, data);
@@ -169,7 +165,7 @@
         } catch (Exception e) {
             throw new AuditorException("Could not retrieve exchange count", e);
         } finally {
-            close(connection);
+            close(connection, false);
         }
     }
 
@@ -195,7 +191,7 @@
         } catch (Exception e) {
             throw new AuditorException("Could not retrieve exchange ids", e);
         } finally {
-            close(connection);
+            close(connection, false);
         }
     }
 
@@ -214,7 +210,7 @@
         } catch (Exception e) {
             throw new AuditorException("Could not retrieve exchanges", e);
         } finally {
-            close(connection);
+            close(connection, false);
         }
     }
 
@@ -223,16 +219,22 @@
      */
     public int deleteExchanges(String[] ids) throws AuditorException {
         Connection connection = null;
+        boolean restoreAutoCommit = false;
         try {
             connection = dataSource.getConnection();
+            if (connection.getAutoCommit()) {
+                connection.setAutoCommit(false);
+                restoreAutoCommit = true;
+            }
             for (int row = 0; row < ids.length; row++) {
                 adapter.doRemoveData(connection, ids[row]);
             }
+            connection.commit();
             return -1;
         } catch (Exception e) {
             throw new AuditorException("Could not delete exchanges", e);
         } finally {
-            close(connection);
+            close(connection, restoreAutoCommit);
         }
     }
     
@@ -266,5 +268,16 @@
         this.autoStart = autoStart;
     }
 
-    
+    private static void close(Connection connection, boolean restoreAutoCommit) {
+        if (connection != null) {
+            try {
+                if (restoreAutoCommit) {
+                    connection.setAutoCommit(true);
+                }
+                connection.close();
+            } catch (SQLException e) {
+            }
+        }
+    }
+
 }

Modified: incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java?view=diff&rev=490828&r1=490827&r2=490828
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
(original)
+++ incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
Thu Dec 28 13:22:26 2006
@@ -68,8 +68,6 @@
     public void doCreateTables(Connection connection) throws SQLException, IOException {
         Statement s = null;
         try {
-            connection.setAutoCommit(false);
-            
             // Check to see if the table already exists.  If it does, then don't log warnings
during startup.
             // Need to run the scripts anyways since they may contain ALTER statements that
upgrade a previous version of the table
             boolean alreadyExists = false;
@@ -111,8 +109,6 @@
                     }
                 }
             }
-            connection.commit();
-            
         }
         finally {
             close(s);
@@ -137,7 +133,6 @@
                     JDBCAdapterFactory.log("Failure details: ", e);
                 }
             }
-            connection.commit();
         }
         finally {
             close(s);

Modified: incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java?view=diff&rev=490828&r1=490827&r2=490828
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
(original)
+++ incubator/servicemix/trunk/core/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
Thu Dec 28 13:22:26 2006
@@ -58,13 +58,7 @@
         } catch (Exception e) {
             throw (IOException) new IOException("Error storing object").initCause(e);
         } finally {
-            if (connection != null) {
-                try {
-                    connection.close();
-                } catch (Exception e) {
-                    throw (IOException) new IOException("Error closing connection").initCause(e);
-                }
-            }
+            close(connection);
         }
     }
 
@@ -90,12 +84,16 @@
         } catch (Exception e) {
             throw (IOException) new IOException("Error storing object").initCause(e);
         } finally {
-            if (connection != null) {
-                try {
-                    connection.close();
-                } catch (Exception e) {
-                    throw (IOException) new IOException("Error closing connection").initCause(e);
-                }
+            close(connection);
+        }
+    }
+
+    protected void close(Connection connection) throws IOException {
+        if (connection != null) {
+            try {
+                connection.close();
+            } catch (Exception e) {
+                throw (IOException) new IOException("Error closing connection").initCause(e);
             }
         }
     }



Mime
View raw message