jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r600980 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
Date Tue, 04 Dec 2007 15:41:26 GMT
Author: dpfister
Date: Tue Dec  4 07:41:25 2007
New Revision: 600980

URL: http://svn.apache.org/viewvc?rev=600980&view=rev
Log:
JCR-1254 - DatabaseJournal commits twice inside a transaction, causing an error with MySQL

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java?rev=600980&r1=600979&r2=600980&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
Tue Dec  4 07:41:25 2007
@@ -139,6 +139,11 @@
      * Statement appending a new record.
      */
     private PreparedStatement insertRevisionStmt;
+    
+    /**
+     * Auto commit level.
+     */
+    private int lockLevel;
 
     /**
      * Locked revision.
@@ -315,8 +320,9 @@
 
         try {
             checkConnection();
-
-            connection.setAutoCommit(false);
+            if (lockLevel++ == 0) {
+                setAutoCommit(connection, false);
+            }
         } catch (SQLException e) {
             close(true);
 
@@ -348,8 +354,7 @@
         } finally {
             close(rs);
             if (!succeeded) {
-                rollback(connection);
-                setAutoCommit(connection, true);
+                doUnlock(false);
             }
         }
     }
@@ -358,10 +363,14 @@
      * {@inheritDoc}
      */
     protected void doUnlock(boolean successful) {
-        if (!successful) {
-            rollback(connection);
+        if (--lockLevel == 0) {
+            if (successful) {
+                commit(connection);
+            } else {
+                rollback(connection);
+            }
+            setAutoCommit(connection, true);
         }
-        setAutoCommit(connection, true);
     }
 
     /**
@@ -384,19 +393,14 @@
         try {
             checkConnection();
 
-            try {
-                insertRevisionStmt.clearParameters();
-                insertRevisionStmt.clearWarnings();
-                insertRevisionStmt.setLong(1, record.getRevision());
-                insertRevisionStmt.setString(2, getId());
-                insertRevisionStmt.setString(3, record.getProducerId());
-                insertRevisionStmt.setBinaryStream(4, in, length);
-                insertRevisionStmt.execute();
+            insertRevisionStmt.clearParameters();
+            insertRevisionStmt.clearWarnings();
+            insertRevisionStmt.setLong(1, record.getRevision());
+            insertRevisionStmt.setString(2, getId());
+            insertRevisionStmt.setString(3, record.getProducerId());
+            insertRevisionStmt.setBinaryStream(4, in, length);
+            insertRevisionStmt.execute();
 
-                connection.commit();
-            } finally {
-                setAutoCommit(connection, true);
-            }
         } catch (SQLException e) {
             close(true);
 
@@ -455,6 +459,23 @@
         }
     }
 
+    /**
+     * Commit a connection. Does nothing if the connection passed is
+     * <code>null</code> and logs any exception as warning.
+     *
+     * @param connection connection.
+     */
+    private static void commit(Connection connection) {
+        if (connection != null) {
+            try {
+                connection.commit();
+            } catch (SQLException e) {
+                String msg = "Error while committing connection: " + e.getMessage();
+                log.warn(msg);
+            }
+        }
+    }
+    
     /**
      * Rollback a connection. Does nothing if the connection passed is
      * <code>null</code> and logs any exception as warning.



Mime
View raw message