jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1404738 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/ test/java/org/apache/jackrabbit/oak/jcr/
Date Thu, 01 Nov 2012 20:04:16 GMT
Author: mduerig
Date: Thu Nov  1 20:04:16 2012
New Revision: 1404738

URL: http://svn.apache.org/viewvc?rev=1404738&view=rev
Log:
 OAK-418: Reduce/avoid re-resolving the underlying tree instances on every access in Item/Property/NodeDelegate

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java?rev=1404738&r1=1404737&r2=1404738&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
Thu Nov  1 20:04:16 2012
@@ -85,7 +85,11 @@ public abstract class ItemDelegate {
      */
     @Nonnull
     public Status getStatus() throws InvalidItemStateException {
-        return getLocation().getStatus();  // never null
+        Status status = getLocation().getStatus();
+        if (status == null) {
+            throw new InvalidItemStateException();
+        }
+        return status;
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1404738&r1=1404737&r2=1404738&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Thu Nov  1 20:04:16 2012
@@ -127,8 +127,7 @@ public class NodeDelegate extends ItemDe
      */
     @CheckForNull
     public NodeDelegate getChild(String relPath) throws InvalidItemStateException {
-        TreeLocation childLocation = getChildLocation(relPath);
-        return create(sessionDelegate, childLocation);
+        return create(sessionDelegate, getChildLocation(relPath));
     }
 
     /**
@@ -235,7 +234,7 @@ public class NodeDelegate extends ItemDe
     Tree getTree() throws InvalidItemStateException {
         Tree tree = getLocation().getTree();
         if (tree == null) {
-            throw new InvalidItemStateException("Node is stale");
+            throw new InvalidItemStateException();
         }
         return tree;
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java?rev=1404738&r1=1404737&r2=1404738&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
Thu Nov  1 20:04:16 2012
@@ -74,7 +74,7 @@ public class PropertyDelegate extends It
      * @param value
      */
     public void setValue(Value value) throws RepositoryException {
-        getLocation().set(PropertyStates.createProperty(getName(), value));
+        getPropertyLocation().set(PropertyStates.createProperty(getName(), value));
     }
 
     /**
@@ -82,28 +82,27 @@ public class PropertyDelegate extends It
      * @param values
      */
     public void setValues(Iterable<Value> values) throws RepositoryException {
-        getLocation().set(PropertyStates.createProperty(getName(), values));
+        getPropertyLocation().set(PropertyStates.createProperty(getName(), values));
     }
 
     /**
      * Remove the property
      */
     public void remove() throws InvalidItemStateException {
-        getLocation().remove();
+        getPropertyLocation().remove();
     }
 
     //------------------------------------------------------------< private >---
 
     @Nonnull
     private PropertyState getPropertyState() throws InvalidItemStateException {
-        return getLocation().getProperty();  // Not null
+        return getPropertyLocation().getProperty();  // Not null
     }
 
-    @Override
-    public PropertyLocation getLocation() throws InvalidItemStateException {
-        TreeLocation location = super.getLocation();
-        if (location.getProperty() == null) {
-            throw new InvalidItemStateException("Property is stale");
+    private PropertyLocation getPropertyLocation() throws InvalidItemStateException {
+        TreeLocation location = getLocation();
+        if (!(location instanceof PropertyLocation)) {
+            throw new InvalidItemStateException();
         }
         return (PropertyLocation) location;
     }

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=1404738&r1=1404737&r2=1404738&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
Thu Nov  1 20:04:16 2012
@@ -1049,6 +1049,19 @@ public class RepositoryTest extends Abst
     }
 
     @Test
+    public void accessRemovedProperty() throws RepositoryException {
+        Node foo = getNode("/foo");
+        Property p = foo.setProperty("name", "value");
+        p.remove();
+        try {
+            p.getPath();
+            fail("Expected InvalidItemStateException");
+        }
+        catch (InvalidItemStateException expected) {
+        }
+    }
+
+    @Test
     public void getReferences() throws RepositoryException {
         Session session = getAdminSession();
         Node referee = getNode("/foo");



Mime
View raw message