jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1459782 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype: EffectiveNodeType.java ReadOnlyNodeTypeManager.java
Date Fri, 22 Mar 2013 14:01:30 GMT
Author: jukka
Date: Fri Mar 22 14:01:29 2013
New Revision: 1459782

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

Move the static get{Property,Node}Definition methods to EffectiveNodeType, i.e. replacing
static m(o, ...) calls with o.m(...)

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/ReadOnlyNodeTypeManager.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=1459782&r1=1459781&r2=1459782&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
Fri Mar 22 14:01:29 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype;
 
+import static javax.jcr.PropertyType.UNDEFINED;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -332,6 +334,75 @@ public class EffectiveNodeType {
         throw new UnsupportedRepositoryOperationException("Child node ordering is not supported
on this node");
     }
 
+    /**
+     *
+     * @param propertyName The internal oak name of the property.
+     * @param isMultiple
+     * @param type
+     * @param exactTypeMatch
+     * @return
+     * @throws ConstraintViolationException
+     */
+    public PropertyDefinition getPropertyDefinition(
+            String propertyName, boolean isMultiple,
+            int type, boolean exactTypeMatch)
+            throws ConstraintViolationException {
+       // TODO: This may need to be optimized
+       for (PropertyDefinition def : getNamedPropertyDefinitions(propertyName)) {
+           int defType = def.getRequiredType();
+           if (isMultiple == def.isMultiple()
+                   &&(!exactTypeMatch || (type == defType || UNDEFINED == type ||
UNDEFINED == defType))) {
+               return def;
+           }
+       }
+
+       // try if there is a residual definition
+       for (PropertyDefinition def : getResidualPropertyDefinitions()) {
+           int defType = def.getRequiredType();
+           if (isMultiple == def.isMultiple()
+                   && (!exactTypeMatch || (type == defType || UNDEFINED == type ||
UNDEFINED == defType))) {
+               return def;
+           }
+       }
+
+       throw new ConstraintViolationException(
+               "No matching property definition found for " + propertyName);
+   }
+
+    /**
+     *
+     * @param childName The internal oak name of the target node.
+     * @param childEffective
+     * @return
+     * @throws ConstraintViolationException
+     */
+    public NodeDefinition getNodeDefinition(
+            String childName, EffectiveNodeType childEffective)
+            throws ConstraintViolationException {
+       for (NodeDefinition def : getNamedNodeDefinitions(childName)) {
+           boolean match = true;
+           if (childEffective != null && !childEffective.includesNodeTypes(def.getRequiredPrimaryTypeNames()))
{
+               match = false;
+           }
+           if (match) {
+               return def;
+           }
+       }
+
+       for (NodeDefinition def : getResidualNodeDefinitions()) {
+           boolean match = true;
+           if (childEffective != null && !childEffective.includesNodeTypes(def.getRequiredPrimaryTypeNames()))
{
+               match = false;
+           }
+           if (match) {
+               return def;
+           }
+       }
+
+       throw new ConstraintViolationException(
+               "No matching node definition found for " + childName);
+   }
+
     //------------------------------------------------------------< private >---
 
     private PropertyDefinition getDefinition(PropertyState property) throws RepositoryException
{
@@ -339,7 +410,7 @@ public class EffectiveNodeType {
         int propertyType = property.getType().tag();
         boolean isMultiple = property.isArray();
 
-        return ntMgr.getDefinition(nodeTypes, propertyName, isMultiple, propertyType, true);
+        return getPropertyDefinition(propertyName, isMultiple, propertyType, true);
     }
 
     private NodeDefinition getDefinition(String nodeName, NodeType nodeType) throws ConstraintViolationException
{

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1459782&r1=1459781&r2=1459782&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Fri Mar 22 14:01:29 2013
@@ -399,8 +399,8 @@ public abstract class ReadOnlyNodeTypeMa
             throws RepositoryException {
         checkNotNull(parent);
         checkNotNull(nodeName);
-
-        return getNodeDefinition(getEffectiveNodeType(parent), nodeName, null);
+        EffectiveNodeType effective = getEffectiveNodeType(parent);
+        return effective.getNodeDefinition(nodeName, null);
     }
 
     @Override
@@ -411,7 +411,7 @@ public abstract class ReadOnlyNodeTypeMa
 
         String name = targetNode.getName();
         EffectiveNodeType eff = getEffectiveNodeType(parent);
-        return getNodeDefinition(eff, name, getEffectiveNodeType(targetNode));
+        return eff.getNodeDefinition(name, getEffectiveNodeType(targetNode));
     }
 
     @Override
@@ -419,7 +419,7 @@ public abstract class ReadOnlyNodeTypeMa
                                         String nodeName, NodeType nodeType)
             throws ConstraintViolationException {
         EffectiveNodeType eff = getEffectiveNodeType(Queues.newArrayDeque(parentNodeTypes));
-        return getNodeDefinition(eff, nodeName, getEffectiveNodeType(Queues.newArrayDeque(Collections.singleton(nodeType))));
+        return eff.getNodeDefinition(nodeName, getEffectiveNodeType(Queues.newArrayDeque(Collections.singleton(nodeType))));
     }
 
     @Override
@@ -436,7 +436,8 @@ public abstract class ReadOnlyNodeTypeMa
             type = targetProperty.getValue().getType();
         }
 
-        return getPropertyDefinition(getEffectiveNodeType(parent), name, isMultiple, type,
true);
+        EffectiveNodeType effective = getEffectiveNodeType(parent);
+        return effective.getPropertyDefinition(name, isMultiple, type, true);
     }
 
     @Nonnull
@@ -448,13 +449,15 @@ public abstract class ReadOnlyNodeTypeMa
     @Nonnull
     @Override
     public PropertyDefinition getDefinition(Node parent, String propertyName, boolean isMultiple,
int type, boolean exactTypeMatch) throws RepositoryException {
-        return getPropertyDefinition(getEffectiveNodeType(parent), propertyName, isMultiple,
type, exactTypeMatch);
+        EffectiveNodeType effective = getEffectiveNodeType(parent);
+        return effective.getPropertyDefinition(propertyName, isMultiple, type, exactTypeMatch);
     }
 
     @Nonnull
     @Override
     public PropertyDefinition getDefinition(Tree parent, String propertyName, boolean isMultiple,
int type, boolean exactTypeMatch) throws RepositoryException {
-        return getPropertyDefinition(getEffectiveNodeType(parent), propertyName, isMultiple,
type, exactTypeMatch);
+        EffectiveNodeType effective = getEffectiveNodeType(parent);
+        return effective.getPropertyDefinition(propertyName, isMultiple, type, exactTypeMatch);
     }
 
     @Nonnull
@@ -462,7 +465,8 @@ public abstract class ReadOnlyNodeTypeMa
     public PropertyDefinition getDefinition(Iterable<NodeType> nodeTypes, String propertyName,
boolean isMultiple,
             int type, boolean exactTypeMatch) throws RepositoryException {
         Queue<NodeType> queue = Queues.newArrayDeque(nodeTypes);
-        return getPropertyDefinition(getEffectiveNodeType(queue), propertyName, isMultiple,
type, exactTypeMatch);
+        EffectiveNodeType effective = getEffectiveNodeType(queue);
+        return effective.getPropertyDefinition(propertyName, isMultiple, type, exactTypeMatch);
     }
 
     //-----------------------------------------------------------< internal >---
@@ -493,70 +497,4 @@ public abstract class ReadOnlyNodeTypeMa
         return EffectiveNodeType.create(types.values(), this);
     }
 
-    /**
-     *
-     * @param effectiveNodeType
-     * @param propertyName The internal oak name of the property.
-     * @param isMultiple
-     * @param type
-     * @param exactTypeMatch
-     * @return
-     * @throws ConstraintViolationException
-     */
-    private static PropertyDefinition getPropertyDefinition(EffectiveNodeType effectiveNodeType,
-            String propertyName, boolean isMultiple,
-            int type, boolean exactTypeMatch) throws ConstraintViolationException {
-        // TODO: This may need to be optimized
-        for (PropertyDefinition def : effectiveNodeType.getNamedPropertyDefinitions(propertyName))
{
-            int defType = def.getRequiredType();
-            if (isMultiple == def.isMultiple()
-                    &&(!exactTypeMatch || (type == defType || UNDEFINED == type ||
UNDEFINED == defType))) {
-                return def;
-            }
-        }
-
-        // try if there is a residual definition
-        for (PropertyDefinition def : effectiveNodeType.getResidualPropertyDefinitions())
{
-            int defType = def.getRequiredType();
-            if (isMultiple == def.isMultiple()
-                    && (!exactTypeMatch || (type == defType || UNDEFINED == type
|| UNDEFINED == defType))) {
-                return def;
-            }
-        }
-
-        throw new ConstraintViolationException("No matching property definition found for
" + propertyName);
-    }
-
-    /**
-     *
-     * @param effectiveNodeType
-     * @param childName The internal oak name of the target node.
-     * @param childEffective
-     * @return
-     * @throws ConstraintViolationException
-     */
-    private static NodeDefinition getNodeDefinition(EffectiveNodeType effectiveNodeType,
-                                                    String childName,
-                                                    EffectiveNodeType childEffective) throws
ConstraintViolationException {
-        for (NodeDefinition def : effectiveNodeType.getNamedNodeDefinitions(childName)) {
-            boolean match = true;
-            if (childEffective != null && !childEffective.includesNodeTypes(def.getRequiredPrimaryTypeNames()))
{
-                match = false;
-            }
-            if (match) {
-                return def;
-            }
-        }
-
-        for (NodeDefinition def : effectiveNodeType.getResidualNodeDefinitions()) {
-            boolean match = true;
-            if (childEffective != null && !childEffective.includesNodeTypes(def.getRequiredPrimaryTypeNames()))
{
-                match = false;
-            }
-            if (match) {
-                return def;
-            }
-        }
-        throw new ConstraintViolationException("No matching node definition found for " +
childName);
-    }
 }



Mime
View raw message