jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r293324 - in /incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/state/ChangeLog.java test/org/apache/jackrabbit/core/XATest.java
Date Mon, 03 Oct 2005 12:45:13 GMT
Author: tripod
Date: Mon Oct  3 05:45:08 2005
New Revision: 293324

URL: http://svn.apache.org/viewcvs?rev=293324&view=rev
Log:
JCR-221 - NoSuchItemStateException if Node.checkin() is invoked within a transaction

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java?rev=293324&r1=293323&r2=293324&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java Mon
Oct  3 05:45:08 2005
@@ -186,21 +186,35 @@
      * @param other other change log
      */
     public void merge(ChangeLog other) {
-        /*
-         * Remove all states from our added set that have
-         * now been deleted
-         */
-        Iterator iter = other.deletedStates.keySet().iterator();
+        // Remove all states from our added set that have now been deleted
+        Iterator iter = other.deletedStates();
         while (iter.hasNext()) {
-            ItemId id = (ItemId) iter.next();
-            if (addedStates.remove(id) == null) {
-                deletedStates.put(id, other.deletedStates.get(id));
+            ItemState state = (ItemState) iter.next();
+            if (addedStates.remove(state.getId()) == null) {
+                deletedStates.put(state.getId(), state);
             }
+            // also remove from eventual modified state
+            modifiedStates.remove(state.getId());
         }
 
-        /* Now merge other changes */
-        addedStates.putAll(other.addedStates);
-        modifiedStates.putAll(other.modifiedStates);
+        // only add modified states that are not already 'added'
+        iter = other.modifiedStates();
+        while (iter.hasNext()) {
+            ItemState state = (ItemState) iter.next();
+            if (!addedStates.containsKey(state.getId())) {
+                modifiedStates.put(state.getId(), state);
+            }
+        }
+
+        // add 'added' state, but respect previously deleted
+        iter = other.addedStates();
+        while (iter.hasNext()) {
+            ItemState state = (ItemState) iter.next();
+            addedStates.put(state.getId(), state);
+            deletedStates.remove(state.getId());
+        }
+
+        // add refs
         modifiedRefs.putAll(other.modifiedRefs);
     }
 

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java?rev=293324&r1=293323&r2=293324&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/XATest.java Mon Oct  3
05:45:08 2005
@@ -43,6 +43,24 @@
         }
     }
 
+    public void testCheckin() throws Exception {
+        // get user transaction object
+        UserTransaction utx = new UserTransactionImpl(superuser);
+
+        // start transaction
+        utx.begin();
+
+        // add node and save
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        n.addMixin(mixVersionable);
+        testRootNode.save();
+
+        n.checkin();
+
+        // commit
+        utx.commit();
+    }
+
     /**
      * Add a node inside a transaction and commit changes. Make sure
      * node exists for other sessions only after commit.
@@ -138,6 +156,138 @@
         assertTrue(otherRootNode.hasProperty(propertyName1));
 
         // logout
+        otherSuperuser.logout();
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testAddAndSetProperty() throws Exception {
+        // prerequisite: non-existing property
+        if (testRootNode.hasProperty(propertyName1)) {
+            testRootNode.getProperty(propertyName1).remove();
+            testRootNode.save();
+        }
+
+        // get user transaction object
+        UserTransaction utx = new UserTransactionImpl(superuser);
+
+        // start transaction
+        utx.begin();
+
+        // 'add' property and save
+        testRootNode.setProperty(propertyName1, "0");
+        testRootNode.save();
+
+        // 'modify' property and save
+        testRootNode.setProperty(propertyName1, "1");
+        testRootNode.save();
+
+        // commit
+        utx.commit();
+
+        // check property value
+        Session otherSuperuser = helper.getSuperuserSession();
+        Node n = (Node) otherSuperuser.getItem(testRootNode.getPath());
+        assertEquals(n.getProperty(propertyName1).getString(), "1");
+        otherSuperuser.logout();
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testDeleteAndAddProperty() throws Exception {
+        // prerequisite: existing property
+        testRootNode.setProperty(propertyName1, "0");
+        testRootNode.save();
+
+        // get user transaction object
+        UserTransaction utx = new UserTransactionImpl(superuser);
+
+        // start transaction
+        utx.begin();
+
+        // 'delete' property and save
+        testRootNode.getProperty(propertyName1).remove();
+        testRootNode.save();
+
+        // 'add' property and save
+        testRootNode.setProperty(propertyName1, "1");
+        testRootNode.save();
+
+        // commit
+        utx.commit();
+
+        // check property value
+        Session otherSuperuser = helper.getSuperuserSession();
+        Node n = (Node) otherSuperuser.getItem(testRootNode.getPath());
+        assertEquals(n.getProperty(propertyName1).getString(), "1");
+        otherSuperuser.logout();
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testModifyAndDeleteProperty() throws Exception {
+        // prerequisite: existing property
+        testRootNode.setProperty(propertyName1, "0");
+        testRootNode.save();
+
+        // get user transaction object
+        UserTransaction utx = new UserTransactionImpl(superuser);
+
+        // start transaction
+        utx.begin();
+
+        // 'modify' property and save
+        testRootNode.setProperty(propertyName1, "1");
+        testRootNode.save();
+
+        // 'delete' property and save
+        testRootNode.getProperty(propertyName1).remove();
+        testRootNode.save();
+
+        // commit
+        utx.commit();
+
+        // check property value
+        Session otherSuperuser = helper.getSuperuserSession();
+        Node n = (Node) otherSuperuser.getItem(testRootNode.getPath());
+        assertFalse("Property must be deleted.", n.hasProperty(propertyName1));
+        otherSuperuser.logout();
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testAddAndDeleteProperty() throws Exception {
+        // prerequisite: non-existing property
+        if (testRootNode.hasProperty(propertyName1)) {
+            testRootNode.getProperty(propertyName1).remove();
+            testRootNode.save();
+        }
+
+        // get user transaction object
+        UserTransaction utx = new UserTransactionImpl(superuser);
+
+        // start transaction
+        utx.begin();
+
+        // 'add' property and save
+        testRootNode.setProperty(propertyName1, "1");
+        testRootNode.save();
+
+        // 'delete' property and save
+        testRootNode.getProperty(propertyName1).remove();
+        testRootNode.save();
+
+        // commit
+        utx.commit();
+
+        // check property value
+        Session otherSuperuser = helper.getSuperuserSession();
+        Node n = (Node) otherSuperuser.getItem(testRootNode.getPath());
+        assertFalse("Property must be deleted.", n.hasProperty(propertyName1));
         otherSuperuser.logout();
     }
 



Mime
View raw message