jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1468121 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/kernel/ main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ main/java/org/apache/jackrabbit/oak/plugi...
Date Mon, 15 Apr 2013 15:34:42 GMT
Author: jukka
Date: Mon Apr 15 15:34:42 2013
New Revision: 1468121

URL: http://svn.apache.org/r1468121
Log:
OAK-776: NodeState convenience accessors

Add NodeState.hasProperty(String name)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefaultTypeEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/JcrAllCommitHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
Mon Apr 15 15:34:42 2013
@@ -114,7 +114,7 @@ public class ReadOnlyTree implements Tre
 
     @Override
     public boolean hasProperty(String name) {
-        return state.getProperty(name) != null;
+        return state.hasProperty(name);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Mon Apr 15 15:34:42 2013
@@ -231,6 +231,12 @@ public final class KernelNodeState exten
     }
 
     @Override
+    public boolean hasProperty(String name) {
+        init();
+        return properties.containsKey(name);
+    }
+
+    @Override
     public PropertyState getProperty(String name) {
         init();
         return properties.get(name);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
Mon Apr 15 15:34:42 2013
@@ -374,7 +374,7 @@ public class ContentMirrorStoreStrategy 
 
         @Override
         public void visit(NodeState state) {
-            if (state.getProperty("match") != null) {
+            if (state.hasProperty("match")) {
                 count++;
                 depthTotal += depth;
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
Mon Apr 15 15:34:42 2013
@@ -56,6 +56,11 @@ public final class EmptyNodeState implem
         return 0;
     }
 
+    @Override
+    public boolean hasProperty(String name) {
+        return false;
+    }
+
     @Override @CheckForNull
     public PropertyState getProperty(String name) {
         return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Mon Apr 15 15:34:42 2013
@@ -432,7 +432,7 @@ public class MemoryNodeBuilder implement
     public NodeBuilder removeProperty(String name) {
         write();
 
-        if (writeState.base.getProperty(name) != null) {
+        if (writeState.base.hasProperty(name)) {
             writeState.properties.put(name, null);
         } else {
             writeState.properties.remove(name);
@@ -560,6 +560,11 @@ public class MemoryNodeBuilder implement
         }
 
         @Override
+        public boolean hasProperty(String name) {
+            return withProperties(base, properties).hasProperty(name);
+        }
+
+        @Override
         public PropertyState getProperty(String name) {
             return withProperties(base, properties).getProperty(name);
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeState.java
Mon Apr 15 15:34:42 2013
@@ -64,6 +64,11 @@ class MemoryNodeState extends AbstractNo
     }
 
     @Override
+    public boolean hasProperty(String name) {
+        return properties.containsKey(name);
+    }
+
+    @Override
     public PropertyState getProperty(String name) {
         return properties.get(name);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
Mon Apr 15 15:34:42 2013
@@ -142,7 +142,7 @@ public class ModifiedNodeState extends A
         long count = base.getPropertyCount();
 
         for (Map.Entry<String, ? extends PropertyState> entry : properties.entrySet())
{
-            if (base.getProperty(entry.getKey()) != null) {
+            if (base.hasProperty(entry.getKey())) {
                 count--;
             }
             if (entry.getValue() != null) {
@@ -154,6 +154,18 @@ public class ModifiedNodeState extends A
     }
 
     @Override
+    public boolean hasProperty(String name) {
+        PropertyState property = properties.get(name);
+        if (property != null) {
+            return true;
+        } else if (properties.containsKey(name)) {
+            return false; // removed
+        } else {
+            return base.hasProperty(name);
+        }
+    }
+
+    @Override
     public PropertyState getProperty(String name) {
         PropertyState property = properties.get(name);
         if (property != null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefaultTypeEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefaultTypeEditor.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefaultTypeEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefaultTypeEditor.java
Mon Apr 15 15:34:42 2013
@@ -55,7 +55,7 @@ public class DefaultTypeEditor implement
         public void childNodeAdded(String name, NodeState after) {
             if (!NodeStateUtils.isHidden(name)) {
                 NodeBuilder childBuilder = builder.child(name);
-                if (after.getProperty("jcr:primaryType") == null) {
+                if (!after.hasProperty("jcr:primaryType")) {
                     childBuilder.setProperty("jcr:primaryType", defaultType, Type.NAME);
                 }
                 DefaultTypeDiff childDiff =

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
Mon Apr 15 15:34:42 2013
@@ -54,7 +54,7 @@ class EffectiveType {
             PropertyState properties =
                     type.getProperty("oak:mandatoryProperties");
             for (String name : properties.getValue(NAMES)) {
-                if (node.getProperty(name) == null) {
+                if (!node.hasProperty(name)) {
                     builder.add(name);
                 }
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
Mon Apr 15 15:34:42 2013
@@ -79,6 +79,12 @@ class SegmentNodeState extends AbstractN
         return getTemplate().getPropertyCount();
     }
 
+    @Override
+    public boolean hasProperty(String name) {
+        checkNotNull(name);
+        return getTemplate().hasProperty(name);
+    }
+
     @Override @CheckForNull
     public PropertyState getProperty(String name) {
         checkNotNull(name);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
Mon Apr 15 15:34:42 2013
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Preconditions.checkElementIndex;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
+import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 import static org.apache.jackrabbit.oak.plugins.segment.Segment.RECORD_ID_BYTES;
 
@@ -177,11 +179,34 @@ class Template {
         }
     }
 
+    public boolean hasProperty(String name) {
+        if (JCR_PRIMARYTYPE.equals(name)) {
+            return primaryType != null;
+        } else if (JCR_MIXINTYPES.equals(name)) {
+            return mixinTypes != null;
+        } else {
+            int hash = name.hashCode();
+            int index = 0;
+            while (index < properties.length
+                    && properties[index].getName().hashCode() < hash) {
+                index++;
+            }
+            while (index < properties.length
+                    && properties[index].getName().hashCode() == hash) {
+                if (name.equals(properties[index].getName())) {
+                    return true;
+                }
+                index++;
+            }
+            return false;
+        }
+    }
+
     public PropertyState getProperty(
             String name, SegmentStore store, RecordId recordId) {
-        if ("jcr:primaryType".equals(name) && primaryType != null) {
+        if (JCR_PRIMARYTYPE.equals(name) && primaryType != null) {
             return primaryType;
-        } else if ("jcr:mixinTypes".equals(name) && mixinTypes != null) {
+        } else if (JCR_MIXINTYPES.equals(name) && mixinTypes != null) {
             return mixinTypes;
         } else {
             int hash = name.hashCode();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/JcrAllCommitHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/JcrAllCommitHook.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/JcrAllCommitHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/JcrAllCommitHook.java
Mon Apr 15 15:34:42 2013
@@ -75,7 +75,7 @@ public class JcrAllCommitHook implements
 
                 // update the privilege bits of the jcr:all in case the new
                 // privilege isn't an aggregate
-                if (after.getProperty(REP_AGGREGATES) == null) {
+                if (!after.hasProperty(REP_AGGREGATES)) {
                     PrivilegeBits bits = PrivilegeBits.getInstance(after.getProperty(REP_BITS));
                     PrivilegeBits all = PrivilegeBits.getInstance(jcrAll.getProperty(REP_BITS));
                     jcrAll.setProperty(PrivilegeBits.getInstance(all).add(bits).asPropertyState(REP_BITS));

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
Mon Apr 15 15:34:42 2013
@@ -40,6 +40,11 @@ import org.apache.jackrabbit.oak.api.Pro
 public abstract class AbstractNodeState implements NodeState {
 
     @Override
+    public boolean hasProperty(String name) {
+        return getProperty(name) != null;
+    }
+
+    @Override
     public PropertyState getProperty(String name) {
         for (PropertyState property : getProperties()) {
             if (name.equals(property.getName())) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
Mon Apr 15 15:34:42 2013
@@ -128,6 +128,17 @@ public interface NodeState {
     boolean exists();
 
     /**
+     * Checks whether the named property exists. The implementation is
+     * equivalent to {@code getProperty(name) != null}, but may be optimized
+     * to avoid having to load the property value.
+     *
+     * @param name property name
+     * @return {@code true} if the named property exists,
+     *         {@code false} otherwise
+     */
+    boolean hasProperty(@Nonnull String name);
+
+    /**
      * Returns the named property. The name is an opaque string and
      * is not parsed or otherwise interpreted by this method.
      * <p>

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
Mon Apr 15 15:34:42 2013
@@ -364,20 +364,20 @@ public class TreeImplTest extends OakBas
     public void testSetOrderableChildrenSetsProperty() throws Exception {
         Tree tree = root.getTree("/").addChild("test");
         tree.setOrderableChildren(true);
-        assertNotNull(((TreeImpl) tree).getNodeState().getProperty(TreeImpl.OAK_CHILD_ORDER));
+        assertTrue(((TreeImpl) tree).getNodeState().hasProperty(TreeImpl.OAK_CHILD_ORDER));
 
         tree.setOrderableChildren(false);
-        assertNull(((TreeImpl) tree).getNodeState().getProperty(TreeImpl.OAK_CHILD_ORDER));
+        assertFalse(((TreeImpl) tree).getNodeState().hasProperty(TreeImpl.OAK_CHILD_ORDER));
 
         tree.setOrderableChildren(true);
         root.commit();
 
-        assertNotNull(((TreeImpl) tree).getNodeState().getProperty(TreeImpl.OAK_CHILD_ORDER));
+        assertTrue(((TreeImpl) tree).getNodeState().hasProperty(TreeImpl.OAK_CHILD_ORDER));
 
         tree.setOrderableChildren(false);
         root.commit();
 
-        assertNull(((TreeImpl) tree).getNodeState().getProperty(TreeImpl.OAK_CHILD_ORDER));
+        assertFalse(((TreeImpl) tree).getNodeState().hasProperty(TreeImpl.OAK_CHILD_ORDER));
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java?rev=1468121&r1=1468120&r2=1468121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
Mon Apr 15 15:34:42 2013
@@ -83,6 +83,7 @@ public class KernelNodeStateTest {
         assertEquals("c", state.getProperty("c").getName());
         assertEquals(3, (long) state.getProperty("c").getValue(LONG));
         assertNull(state.getProperty("x"));
+        assertFalse(state.hasProperty("x"));
     }
 
     @Test



Mime
View raw message