jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1513388 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/test/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
Date Tue, 13 Aug 2013 08:26:07 GMT
Author: mduerig
Date: Tue Aug 13 08:26:07 2013
New Revision: 1513388

URL: http://svn.apache.org/r1513388
Log:
OAK-947 New node becomes existing after Session.refresh(true)
track node status in Tree implementations without relying on the underlying node builder

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTree.java?rev=1513388&r1=1513387&r2=1513388&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTree.java
Tue Aug 13 08:26:07 2013
@@ -97,6 +97,16 @@ public abstract class AbstractTree imple
     protected abstract AbstractTree createChild(@Nonnull String name);
 
     /**
+     * @return  {@code true} iff {@code getStatus() == Status.NEW}
+     */
+    protected abstract boolean isNew();
+
+    /**
+     * @return  {@code true} iff {@code getStatus() == Status.MODIFIED}
+     */
+    protected abstract boolean isModified();
+
+    /**
      * @return {@code true} if this tree has orderable children;
      *         {@code false} otherwise.
      */
@@ -174,9 +184,9 @@ public abstract class AbstractTree imple
 
     @Override
     public Status getStatus() {
-        if (nodeBuilder.isNew()) {
+        if (isNew()) {
             return NEW;
-        } else if (nodeBuilder.isModified()) {
+        } else if (isModified()) {
             return MODIFIED;
         } else {
             return EXISTING;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java?rev=1513388&r1=1513387&r2=1513388&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
Tue Aug 13 08:26:07 2013
@@ -155,6 +155,16 @@ public final class ImmutableTree extends
     }
 
     @Override
+    protected boolean isNew() {
+        return false;
+    }
+
+    @Override
+    protected boolean isModified() {
+        return false;
+    }
+
+    @Override
     public ImmutableTree getParent() {
         return parentProvider.getParent();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java?rev=1513388&r1=1513387&r2=1513388&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
Tue Aug 13 08:26:07 2013
@@ -103,6 +103,58 @@ public class MutableTree extends Abstrac
         return super.getStatus();
     }
 
+    private NodeState getBase() {
+        if (parent == null) {
+            return root.getBaseState();
+        } else {
+            return parent.getBase().getChildNode(name);
+        }
+    }
+
+    @Override
+    protected boolean isNew() {
+        return !getBase().exists();
+    }
+
+    @Override
+    protected boolean isModified() {
+        NodeState base = getBase();
+
+        // child node removed?
+        for (String name : base.getChildNodeNames()) {
+            if (!nodeBuilder.hasChildNode(name)) {
+                return true;
+            }
+        }
+
+        // child node added?
+        for (String name : nodeBuilder.getChildNodeNames()) {
+            if (!base.hasChildNode(name)) {
+                return true;
+            }
+        }
+
+        // property removed?
+        for (PropertyState p : base.getProperties()) {
+            if (!nodeBuilder.hasProperty(p.getName())) {
+                return true;
+            }
+        }
+
+        // property added or modified?
+        for (PropertyState p : nodeBuilder.getProperties()) {
+            PropertyState q = base.getProperty(p.getName());
+            if (q == null) {
+                return true;
+            }
+            if (!p.equals(q)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     @Override
     public boolean exists() {
         return enter();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java?rev=1513388&r1=1513387&r2=1513388&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootTest.java
Tue Aug 13 08:26:07 2013
@@ -37,7 +37,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.Type;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class RootTest extends OakBaseTest {
@@ -131,7 +130,7 @@ public class RootTest extends OakBaseTes
         assertFalse(z.exists());
 
         x.addChild("z");
-        assertEquals(Status.EXISTING, z.getStatus());
+        assertEquals(Status.NEW, z.getStatus());
 
         x.getChild("z").setProperty("p", "2");
         PropertyState p = z.getProperty("p");
@@ -163,8 +162,8 @@ public class RootTest extends OakBaseTes
 
         root.move("/parent", "/moved");
 
-        assertEquals(Status.EXISTING, parent.getStatus());
-        assertEquals(Status.EXISTING, n.getStatus());
+        assertEquals(Status.NEW, parent.getStatus());
+        assertEquals(Status.NEW, n.getStatus());
 
         assertEquals("/moved", parent.getPath());
         assertEquals("/moved/new", n.getPath());
@@ -316,7 +315,6 @@ public class RootTest extends OakBaseTes
     }
 
     @Test
-    @Ignore("OAK-947")  // FIXME OAK-947
     public void rebasePreservesStatus() throws CommitFailedException {
         Root root1 = session.getLatestRoot();
         Root root2 = session.getLatestRoot();
@@ -336,7 +334,6 @@ public class RootTest extends OakBaseTes
     }
 
     @Test
-    @Ignore("OAK-947")  // FIXME OAK-947
     public void purgePreservesStatus() throws CommitFailedException {
         Tree x = session.getLatestRoot().getTree("/x");
         Tree added = x.addChild("added");

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1513388&r1=1513387&r2=1513388&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Tue Aug 13 08:26:07 2013
@@ -1434,13 +1434,15 @@ public class RepositoryTest extends Abst
         Session session2 = createAdminSession();
         try {
             Node foo = session1.getNode("/foo");
-            foo.addNode("added");
+            Node added = foo.addNode("added");
+            assertTrue(added.isNew());
 
             session2.getNode("/foo").addNode("bar");
             session2.save();
 
             session1.refresh(true);
             assertTrue(foo.hasNode("added"));
+            assertTrue(foo.getNode("added").isNew());
             assertTrue(foo.hasNode("bar"));
         } finally {
             session1.logout();



Mime
View raw message