You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2013/03/26 16:57:46 UTC

svn commit: r1461195 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/nodetype/ test/java/org/apache/jackrabbit/oak/

Author: jukka
Date: Tue Mar 26 15:57:46 2013
New Revision: 1461195

URL: http://svn.apache.org/r1461195
Log:
OAK-702: Optimize access to node type information

Leverage the pre-compiled property and child node definition information in EffectiveNodeType

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ItemDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java?rev=1461195&r1=1461194&r2=1461195&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java Tue Mar 26 15:57:46 2013
@@ -25,12 +25,10 @@ import java.util.List;
 import java.util.Map;
 
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.ItemDefinition;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
@@ -42,6 +40,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
@@ -68,6 +67,15 @@ public class EffectiveNodeType {
         for (NodeTypeImpl mixin : checkNotNull(mixins)) {
             addNodeType(mixin);
         }
+        if (!nodeTypes.containsKey(NT_BASE)) {
+            try {
+                nodeTypes.put(
+                        NT_BASE,
+                        (NodeTypeImpl) ntMgr.getNodeType(NT_BASE)); // FIXME
+            } catch (RepositoryException e) {
+                // TODO: ignore/warning/error?
+            }
+        }
     }
 
     EffectiveNodeType(NodeTypeImpl primary, ReadOnlyNodeTypeManager ntMgr) {
@@ -79,16 +87,8 @@ public class EffectiveNodeType {
         if (!nodeTypes.containsKey(name)) {
             nodeTypes.put(name, type);
             NodeType[] supertypes = type.getDeclaredSupertypes();
-            if (supertypes.length > 1) {
-                for (NodeType supertype : supertypes) {
-                    addNodeType((NodeTypeImpl) supertype); // FIXME
-                }
-            } else if (!type.isMixin() && !nodeTypes.containsKey(NT_BASE)) {
-                try {
-                    addNodeType((NodeTypeImpl) ntMgr.getNodeType(NT_BASE)); // FIXME
-                } catch (RepositoryException e) {
-                    // TODO: ignore/warning/error?
-                }
+            for (NodeType supertype : supertypes) {
+                addNodeType((NodeTypeImpl) supertype); // FIXME
             }
         }
     }
@@ -101,12 +101,7 @@ public class EffectiveNodeType {
      * @return {@code true} if the given node type is included, otherwise {@code false}.
      */
     public boolean includesNodeType(String nodeTypeName) {
-        for (NodeType type : nodeTypes.values()) {
-            if (type.isNodeType(nodeTypeName)) {
-                return true;
-            }
-        }
-        return false;
+        return nodeTypes.containsKey(nodeTypeName);
     }
 
 
@@ -210,8 +205,16 @@ public class EffectiveNodeType {
      * @return All node definitions that match the given internal oak name.
      */
     @Nonnull
-    public Iterable<NodeDefinition> getNamedNodeDefinitions(String oakName) {
-        return Iterables.filter(getNodeDefinitions(), new DefinitionNamePredicate(oakName));
+    public Iterable<NodeDefinition> getNamedNodeDefinitions(
+            final String oakName) {
+        return Iterables.concat(Iterables.transform(
+                nodeTypes.values(),
+                new Function<NodeTypeImpl, Iterable<NodeDefinition>>() {
+                    @Override
+                    public Iterable<NodeDefinition> apply(NodeTypeImpl input) {
+                        return input.getDeclaredNamedNodeDefinitions(oakName);
+                    }
+                }));
     }
 
     /**
@@ -221,8 +224,16 @@ public class EffectiveNodeType {
      * @return All property definitions that match the given internal oak name.
      */
     @Nonnull
-    public Iterable<PropertyDefinition> getNamedPropertyDefinitions(String oakName) {
-        return Iterables.filter(getPropertyDefinitions(), new DefinitionNamePredicate(oakName));
+    public Iterable<PropertyDefinition> getNamedPropertyDefinitions(
+            final String oakName) {
+        return Iterables.concat(Iterables.transform(
+                nodeTypes.values(),
+                new Function<NodeTypeImpl, Iterable<PropertyDefinition>>() {
+                    @Override
+                    public Iterable<PropertyDefinition> apply(NodeTypeImpl input) {
+                        return input.getDeclaredNamedPropertyDefinitions(oakName);
+                    }
+                }));
     }
 
     /**
@@ -232,12 +243,14 @@ public class EffectiveNodeType {
      */
     @Nonnull
     public Iterable<NodeDefinition> getResidualNodeDefinitions() {
-        return Iterables.filter(getNodeDefinitions(), new Predicate<NodeDefinition>() {
-            @Override
-            public boolean apply(NodeDefinition nodeDefinition) {
-                return NodeTypeConstants.RESIDUAL_NAME.equals(nodeDefinition.getName());
-            }
-        });
+        return Iterables.concat(Iterables.transform(
+                nodeTypes.values(),
+                new Function<NodeTypeImpl, Iterable<NodeDefinition>>() {
+                    @Override
+                    public Iterable<NodeDefinition> apply(NodeTypeImpl input) {
+                        return input.getDeclaredResidualNodeDefinitions();
+                    }
+                }));
     }
 
     /**
@@ -247,12 +260,14 @@ public class EffectiveNodeType {
      */
     @Nonnull
     public Iterable<PropertyDefinition> getResidualPropertyDefinitions() {
-        return Iterables.filter(getPropertyDefinitions(), new Predicate<PropertyDefinition>() {
-            @Override
-            public boolean apply(PropertyDefinition propertyDefinition) {
-                return NodeTypeConstants.RESIDUAL_NAME.equals(propertyDefinition.getName());
-            }
-        });
+        return Iterables.concat(Iterables.transform(
+                nodeTypes.values(),
+                new Function<NodeTypeImpl, Iterable<PropertyDefinition>>() {
+                    @Override
+                    public Iterable<PropertyDefinition> apply(NodeTypeImpl input) {
+                        return input.getDeclaredResidualPropertyDefinitions();
+                    }
+                }));
     }
 
     public void checkSetProperty(PropertyState property) throws RepositoryException {
@@ -399,17 +414,4 @@ public class EffectiveNodeType {
         return getPropertyDefinition(propertyName, isMultiple, propertyType, true);
     }
 
-    private static class DefinitionNamePredicate implements Predicate<ItemDefinition> {
-
-        private final String oakName;
-
-        DefinitionNamePredicate(String oakName) {
-            this.oakName = oakName;
-        }
-        @Override
-        public boolean apply(@Nullable ItemDefinition definition) {
-            return definition instanceof ItemDefinitionImpl && ((ItemDefinitionImpl) definition).getOakName().equals(oakName);
-        }
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ItemDefinitionImpl.java?rev=1461195&r1=1461194&r2=1461195&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ItemDefinitionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ItemDefinitionImpl.java Tue Mar 26 15:57:46 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import javax.jcr.nodetype.ItemDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.version.OnParentVersionAction;
@@ -39,8 +41,12 @@ import org.apache.jackrabbit.oak.namepat
 class ItemDefinitionImpl extends AbstractTypeDefinition
         implements ItemDefinition {
 
-    protected ItemDefinitionImpl(Tree definition, NamePathMapper mapper) {
+    private final NodeType type;
+
+    protected ItemDefinitionImpl(
+            Tree definition, NodeType type, NamePathMapper mapper) {
         super(definition, mapper);
+        this.type = checkNotNull(type);
     }
 
     String getOakName() {
@@ -55,7 +61,7 @@ class ItemDefinitionImpl extends Abstrac
 
     @Override
     public NodeType getDeclaringNodeType() {
-        return new NodeTypeImpl(definition.getParent(), mapper);
+        return type;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java?rev=1461195&r1=1461194&r2=1461195&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java Tue Mar 26 15:57:46 2013
@@ -36,8 +36,8 @@ import org.apache.jackrabbit.oak.namepat
  */
 class NodeDefinitionImpl extends ItemDefinitionImpl implements NodeDefinition {
 
-    NodeDefinitionImpl(Tree definition, NamePathMapper mapper) {
-        super(definition, mapper);
+    NodeDefinitionImpl(Tree definition, NodeType type, NamePathMapper mapper) {
+        super(definition, type, mapper);
     }
 
     //-----------------------------------------------------< NodeDefinition >---

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java?rev=1461195&r1=1461194&r2=1461195&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java Tue Mar 26 15:57:46 2013
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -48,6 +49,8 @@ import org.apache.jackrabbit.oak.plugins
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
@@ -56,10 +59,13 @@ import static com.google.common.base.Pre
 import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION;
 import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES;
 import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
+import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.JcrConstants.JCR_NODETYPENAME;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYITEMNAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.JCR_PROPERTYDEFINITION;
 import static org.apache.jackrabbit.JcrConstants.JCR_SUPERTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_ABSTRACT;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_QUERYABLE;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.RESIDUAL_NAME;
@@ -164,7 +170,7 @@ class NodeTypeImpl extends AbstractTypeD
         List<PropertyDefinition> definitions = Lists.newArrayList();
         for (Tree child : definition.getChildren()) {
             if (child.getName().startsWith(JCR_PROPERTYDEFINITION)) {
-                definitions.add(new PropertyDefinitionImpl(child, mapper));
+                definitions.add(new PropertyDefinitionImpl(child, this, mapper));
             }
         }
         return definitions.toArray(NO_PROPERTY_DEFINITIONS);
@@ -175,7 +181,7 @@ class NodeTypeImpl extends AbstractTypeD
         List<NodeDefinition> definitions = Lists.newArrayList();
         for (Tree child : definition.getChildren()) {
             if (child.getName().startsWith(JCR_CHILDNODEDEFINITION)) {
-                definitions.add(new NodeDefinitionImpl(child, mapper));
+                definitions.add(new NodeDefinitionImpl(child, this, mapper));
             }
         }
         return definitions.toArray(NO_NODE_DEFINITIONS);
@@ -464,6 +470,86 @@ class NodeTypeImpl extends AbstractTypeD
         return definitions;
     }
 
+    Iterable<PropertyDefinition> getDeclaredNamedPropertyDefinitions(String oakName) {
+        Tree named = definition.getChild("oak:namedPropertyDefinitions");
+        if (named != null) {
+            String escapedName;
+            if (JCR_PRIMARYTYPE.equals(oakName)) {
+                escapedName = "oak:primaryType";
+            } else if (JCR_MIXINTYPES.equals(oakName)) {
+                escapedName = "oak:mixinTypes";
+            } else if (JCR_UUID.equals(oakName)) {
+                escapedName = "oak:uuid";
+            } else {
+                escapedName = oakName;
+            }
+            Tree definitions = named.getChild(escapedName);
+            if (definitions != null) {
+                return Iterables.transform(
+                        definitions.getChildren(),
+                        new Function<Tree, PropertyDefinition>() {
+                            @Override
+                            public PropertyDefinition apply(Tree input) {
+                                return new PropertyDefinitionImpl(
+                                        input, NodeTypeImpl.this, mapper);
+                            }
+                        });
+            }
+        }
+        return Collections.emptyList();
+    }
+
+    Iterable<PropertyDefinition> getDeclaredResidualPropertyDefinitions() {
+        Tree definitions = definition.getChild("oak:residualPropertyDefinitions");
+        if (definitions != null) {
+            return Iterables.transform(
+                    definitions.getChildren(),
+                    new Function<Tree, PropertyDefinition>() {
+                        @Override
+                        public PropertyDefinition apply(Tree input) {
+                            return new PropertyDefinitionImpl(
+                                    input, NodeTypeImpl.this, mapper);
+                        }
+                    });
+        }
+        return Collections.emptyList();
+    }
+
+    Iterable<NodeDefinition> getDeclaredNamedNodeDefinitions(String oakName) {
+        Tree named = definition.getChild("oak:namedChildNodeDefinitions");
+        if (named != null) {
+            Tree definitions = named.getChild(oakName);
+            if (definitions != null) {
+                return Iterables.transform(
+                        definitions.getChildren(),
+                        new Function<Tree, NodeDefinition>() {
+                            @Override
+                            public NodeDefinition apply(Tree input) {
+                                return new NodeDefinitionImpl(
+                                        input, NodeTypeImpl.this, mapper);
+                            }
+                        });
+            }
+        }
+        return Collections.emptyList();
+    }
+
+    Iterable<NodeDefinition> getDeclaredResidualNodeDefinitions() {
+        Tree definitions = definition.getChild("oak:residualChildNodeDefinitions");
+        if (definitions != null) {
+            return Iterables.transform(
+                    definitions.getChildren(),
+                    new Function<Tree, NodeDefinition>() {
+                        @Override
+                        public NodeDefinition apply(Tree input) {
+                            return new NodeDefinitionImpl(
+                                    input, NodeTypeImpl.this, mapper);
+                        }
+                    });
+        }
+        return Collections.emptyList();
+    }
+
     //--------------------------------------------------------------------------
     private static boolean meetsTypeConstraints(Value value, int requiredType) {
         try {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionImpl.java?rev=1461195&r1=1461194&r2=1461195&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionImpl.java Tue Mar 26 15:57:46 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import java.util.List;
 
 import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 
@@ -62,8 +63,8 @@ class PropertyDefinitionImpl extends Ite
 
     private static final Value[] NO_VALUES = new Value[0];
 
-    PropertyDefinitionImpl(Tree definition, NamePathMapper mapper) {
-        super(definition, mapper);
+    PropertyDefinitionImpl(Tree definition, NodeType type, NamePathMapper mapper) {
+        super(definition, type, mapper);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java?rev=1461195&r1=1461194&r2=1461195&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java Tue Mar 26 15:57:46 2013
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexHookProvider;
 import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexProvider;
+import org.apache.jackrabbit.oak.plugins.nodetype.RegistrationEditorProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
@@ -59,6 +60,7 @@ public abstract class AbstractSecurityTe
                 .with(new InitialContent())
                 .with(new Property2IndexHookProvider())
                 .with(new Property2IndexProvider())
+                .with(new RegistrationEditorProvider())
                 .with(getSecurityProvider())
                 .createContentRepository();