jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1329231 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/test/java/org/apache/jackra...
Date Mon, 23 Apr 2012 13:39:55 GMT
Author: mduerig
Date: Mon Apr 23 13:39:54 2012
New Revision: 1329231

URL: http://svn.apache.org/viewvc?rev=1329231&view=rev
Log:
OAK-18: Define Oak API 
- add getChildStatus(). getPropertyStatus() methods to ContentTree
- implement Item.isModified(), Item.isNew()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ContentTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelContentTree.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.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/api/ContentTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ContentTree.java?rev=1329231&r1=1329230&r2=1329231&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ContentTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ContentTree.java
Mon Apr 23 13:39:54 2012
@@ -42,6 +42,8 @@ import java.util.List;
  *
  */
 public interface ContentTree {
+    enum Status {EXISTING, NEW, MODIFIED, REMOVED}
+
     /**
      * @return  the name of this {@code ContentTree} instance.
      */
@@ -65,6 +67,8 @@ public interface ContentTree {
      */
     PropertyState getProperty(String name);
 
+    Status getPropertyStatus(String name);
+
     /**
      * Determine if a property state exists
      * @param name  name of the property state
@@ -96,6 +100,8 @@ public interface ContentTree {
      */
     ContentTree getChild(String name);
 
+    Status getChildStatus(String name);
+
     /**
      * Determine if a child of this {@code ContentTree} instance exists.
      * @param name  name of the child

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelContentTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelContentTree.java?rev=1329231&r1=1329230&r2=1329231&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelContentTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelContentTree.java
Mon Apr 23 13:39:54 2012
@@ -241,6 +241,27 @@ public class KernelContentTree implement
     }
 
     @Override
+    public Status getPropertyStatus(String name) {
+        if (addedProperties.containsKey(name)) {
+            if (persistentState.getProperty(name) == null) {
+                return Status.NEW;
+            }
+            else {
+                return Status.MODIFIED;
+            }
+        }
+        else if (removedProperties.contains(name)) {
+            return Status.REMOVED;
+        }
+        else if (persistentState.getProperty(name) == null) {
+            return null;
+        }
+        else {
+            return Status.EXISTING;
+        }
+    }
+
+    @Override
     public boolean hasProperty(String name) {
         return getProperty(name) != null;
     }
@@ -269,6 +290,32 @@ public class KernelContentTree implement
     }
 
     @Override
+    public Status getChildStatus(String name) {
+        if (addedTrees.containsKey(name)) {
+            return Status.NEW;
+        }
+        else if (removedTrees.contains(name)) {
+            return Status.REMOVED;
+        }
+        else {
+            KernelContentTree child = getChild(name);
+            if (child == null) {
+                return null;
+            }
+            else if (child.addedTrees.isEmpty() &&
+                    child.removedTrees.isEmpty() &&
+                    child.addedProperties.isEmpty() &&
+                    child.removedProperties.isEmpty()) {
+                    
+                return Status.EXISTING;
+            }
+            else {
+                return Status.MODIFIED;
+            }
+        }
+    }
+
+    @Override
     public boolean hasChild(String name) {
         return getChild(name) != null;
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1329231&r1=1329230&r2=1329231&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Mon Apr 23 13:39:54 2012
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.commons.ite
 import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 import org.apache.jackrabbit.oak.api.Branch;
 import org.apache.jackrabbit.oak.api.ContentTree;
+import org.apache.jackrabbit.oak.api.ContentTree.Status;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.jcr.util.ItemNameMatcher;
 import org.apache.jackrabbit.oak.jcr.util.LogUtil;
@@ -91,7 +92,7 @@ public class NodeImpl extends ItemImpl i
      */
     @Override
     public String getName() throws RepositoryException {
-        return getContentTree().getName();
+        return name();
     }
 
     /**
@@ -144,8 +145,7 @@ public class NodeImpl extends ItemImpl i
      */
     @Override
     public boolean isNew() {
-        // todo implement isNew
-        return false;
+        return getContentTree().getParent().getChildStatus(name()) == Status.NEW;
     }
 
     /**
@@ -153,8 +153,7 @@ public class NodeImpl extends ItemImpl i
      */
     @Override
     public boolean isModified() {
-        // todo implement isModified
-        return false;
+        return getContentTree().getParent().getChildStatus(name()) == Status.MODIFIED;
     }
 
     /**
@@ -855,6 +854,10 @@ public class NodeImpl extends ItemImpl i
 
     //------------------------------------------------------------< package >---
 
+    String name() {
+        return getContentTree().getName();
+    }
+
     String path() {
         return '/' + getContentTree().getPath();
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1329231&r1=1329230&r2=1329231&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Mon Apr 23 13:39:54 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.oak.api.Branch;
 import org.apache.jackrabbit.oak.api.ContentTree;
+import org.apache.jackrabbit.oak.api.ContentTree.Status;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.jcr.util.LogUtil;
 import org.apache.jackrabbit.oak.jcr.util.ValueConverter;
@@ -77,7 +78,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public String getName() throws RepositoryException {
-        return getStateName();
+        return name();
     }
 
     /**
@@ -85,7 +86,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public String getPath() throws RepositoryException {
-        return '/' + getParentContentTree().getPath() + '/' + getStateName();
+        return path();
     }
 
     /**
@@ -121,8 +122,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public boolean isNew() {
-        // todo implement isNew
-        return false;
+        return getParentContentTree().getPropertyStatus(name()) == Status.NEW;
     }
 
     /**
@@ -130,8 +130,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public boolean isModified() {
-        // todo implement isModified
-        return false;
+        return getParentContentTree().getPropertyStatus(name()) == Status.MODIFIED;
     }
 
     /**
@@ -139,7 +138,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public void remove() throws RepositoryException {
-        getParentContentTree().removeProperty(getStateName());
+        getParentContentTree().removeProperty(name());
     }
 
     /**
@@ -567,7 +566,7 @@ public class PropertyImpl extends ItemIm
             remove();
         }
         else {
-            getParentContentTree().setProperty(getStateName(), ValueConverter.toScalar(value));
+            getParentContentTree().setProperty(name(), ValueConverter.toScalar(value));
         }
     }
 
@@ -587,7 +586,7 @@ public class PropertyImpl extends ItemIm
             remove();
         }
         else {
-            getParentContentTree().setProperty(getStateName(), ValueConverter.toScalar(values));
+            getParentContentTree().setProperty(name(), ValueConverter.toScalar(values));
         }
     }
 
@@ -621,10 +620,14 @@ public class PropertyImpl extends ItemIm
         return propertyState;
     }
 
-    private String getStateName() {
+    private String name() {
         return getPropertyState().getName();
     }
 
+    private String path() {
+        return '/' + getParentContentTree().getPath() + '/' + name();
+    }
+
     private synchronized void resolve() {
         parent = getBranch().getContentTree(parent.getPath());
         String path = Paths.concat(parent.getPath(), propertyState.getName());

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=1329231&r1=1329230&r2=1329231&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
Mon Apr 23 13:39:54 2012
@@ -306,12 +306,19 @@ public class RepositoryTest extends Abst
         assertFalse(session.nodeExists(newNode));
 
         Node node = getNode(TEST_PATH);
-        node.addNode("new");
+        Node added = node.addNode("new");
+        assertFalse(node.isNew());
+        assertTrue(node.isModified());
+        assertTrue(added.isNew());
+        assertFalse(added.isModified());
         session.save();
 
         Session session2 = getRepository().login();
         try {
             assertTrue(session2.nodeExists(newNode));
+            added = session2.getNode(newNode);
+            assertFalse(added.isNew());
+            assertFalse(added.isModified());
         }
         finally {
             session2.logout();
@@ -882,6 +889,9 @@ public class RepositoryTest extends Abst
 
         Property property = parentNode.getProperty("string");
         property.setValue("new value");
+        assertTrue(parentNode.isModified());
+        assertTrue(property.isModified());
+        assertFalse(property.isNew());
         property.getSession().save();
 
         Session session2 = getRepository().login();
@@ -996,6 +1006,7 @@ public class RepositoryTest extends Abst
         Session session2 = getRepository().login();
         try {
             session2.getNode(TEST_PATH + "/newNode").remove();
+            assertTrue(session2.getNode(TEST_PATH).isModified());
             session2.save();
         }
         finally {
@@ -1005,6 +1016,7 @@ public class RepositoryTest extends Abst
         Session session3 = getRepository().login();
         try {
             assertFalse(session3.nodeExists(TEST_PATH + "/newNode"));
+            assertFalse(session3.getNode(TEST_PATH).isModified());
         }
         finally {
             session3.logout();
@@ -1630,7 +1642,10 @@ public class RepositoryTest extends Abst
         String propertyPath = parentNode.getPath() + '/' + name;
         assertFalse(getSession().propertyExists(propertyPath));
 
-        parentNode.setProperty(name, value);
+        Property added = parentNode.setProperty(name, value);
+        assertTrue(parentNode.isModified());
+        assertFalse(added.isModified());
+        assertTrue(added.isNew());
         getSession().save();
 
         Session session2 = getRepository().login();



Mime
View raw message