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/02/13 17:06:28 UTC

svn commit: r1445702 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: api/Type.java plugins/segment/NodeTemplate.java plugins/segment/PropertyTemplate.java

Author: jukka
Date: Wed Feb 13 16:06:27 2013
New Revision: 1445702

URL: http://svn.apache.org/r1445702
Log:
OAK-593: Segment-based MK

Include jcr:primaryType and jcr:mixinTypes values (if present) in the node template

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Type.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/NodeTemplate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Type.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Type.java?rev=1445702&r1=1445701&r2=1445702&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Type.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Type.java Wed Feb 13 16:06:27 2013
@@ -23,6 +23,7 @@ import java.math.BigDecimal;
 import javax.jcr.PropertyType;
 
 import com.google.common.base.Objects;
+import com.google.common.collect.ComparisonChain;
 
 import static com.google.common.base.Preconditions.checkState;
 
@@ -32,7 +33,7 @@ import static com.google.common.base.Pre
  * the return type of that method.
  * @param <T>
  */
-public final class Type<T> {
+public final class Type<T> implements Comparable<Type<?>> {
 
     /** Map {@code String} to {@link PropertyType#STRING} */
     public static final Type<String> STRING = create(PropertyType.STRING, false);
@@ -179,6 +180,18 @@ public final class Type<T> {
         return fromTag(tag, true);
     }
 
+    //--------------------------------------------------------< Comparable >--
+
+    @Override
+    public int compareTo(Type<?> that) {
+        return ComparisonChain.start()
+                .compare(tag, that.tag)
+                .compareFalseFirst(array, that.array)
+                .result();
+    }
+
+    //------------------------------------------------------------< Object >--
+
     @Override
     public String toString() {
         return isArray()

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/NodeTemplate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/NodeTemplate.java?rev=1445702&r1=1445701&r2=1445702&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/NodeTemplate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/NodeTemplate.java Wed Feb 13 16:06:27 2013
@@ -16,13 +16,20 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
+import javax.annotation.CheckForNull;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 
 class NodeTemplate {
 
@@ -30,30 +37,75 @@ class NodeTemplate {
 
     private final String MANY_CHILD_NODES = "";
 
-    private final Map<String, PropertyTemplate> properties;
-
+    /**
+     * The {@code jcr:primaryType} property, if present as a single-valued
+     * {@code NAME} property. Otherwise {@code null}.
+     */
+    @CheckForNull
+    private final PropertyState primaryType;
+
+    /**
+     * The {@code jcr:mixinTypes} property, if present as a multi-valued
+     * {@code NAME} property. Otherwise {@code null}.
+     */
+    @CheckForNull
+    private final PropertyState mixinTypes;
+
+    /**
+     * Templates of all the properties of a node, excluding the
+     * above-mentioned {@code NAME}-valued type properties, if any.
+     */
+    private final PropertyTemplate[] properties;
+
+    /**
+     * Name of the single child node, if the node contains just one child.
+     * Otherwise {@link #ZERO_CHILD_NODES} (i.e. {@code null}) if there are
+     * no children, or {@link #MANY_CHILD_NODES} if there are more than one.
+     */
     private final String nodeName;
 
     NodeTemplate(NodeState state) {
-        ImmutableMap.Builder<String, PropertyTemplate> builder =
-                ImmutableMap.builder();
+        PropertyState primary = null;
+        PropertyState mixins = null;
+        List<PropertyTemplate> templates = Lists.newArrayList();
+
         for (PropertyState property : state.getProperties()) {
-            builder.put(property.getName(), new PropertyTemplate(property));
+            String name = property.getName();
+            Type<?> type = property.getType();
+            if ("jcr:primaryType".equals(name) && type == Type.NAME) {
+                primary = property;
+            } else if ("jcr:mixinTypes".equals(name) && type == Type.NAMES) {
+                mixins = property;
+            } else {
+                templates.add(new PropertyTemplate(property));
+            }
         }
-        properties = builder.build();
+
+        this.primaryType = primary;
+        this.mixinTypes = mixins;
+        this.properties =
+                templates.toArray(new PropertyTemplate[templates.size()]);
+        Arrays.sort(properties);
 
         long count = state.getChildNodeCount();
         if (count == 0) {
             nodeName = ZERO_CHILD_NODES;
         } else if (count == 1) {
             nodeName = state.getChildNodeNames().iterator().next();
+            checkState(nodeName != null && !nodeName.equals(MANY_CHILD_NODES));
         } else {
             nodeName = MANY_CHILD_NODES;
         }
     }
 
     public int getPropertyCount() {
-        return properties.size();
+        if (primaryType != null && mixinTypes != null) {
+            return properties.length + 2;
+        } else if (primaryType != null || mixinTypes != null) {
+            return properties.length + 1;
+        } else {
+            return properties.length;
+        }
     }
 
     //------------------------------------------------------------< Object >--
@@ -64,7 +116,9 @@ class NodeTemplate {
             return true;
         } else if (object instanceof NodeTemplate) {
             NodeTemplate that = (NodeTemplate) object;
-            return properties.equals(that.properties)
+            return Objects.equal(primaryType, that.primaryType)
+                    && Objects.equal(mixinTypes, that.mixinTypes)
+                    && Arrays.equals(properties, that.properties)
                     && Objects.equal(nodeName, that.nodeName);
         } else {
             return false;
@@ -73,12 +127,7 @@ class NodeTemplate {
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(properties, nodeName);
-    }
-
-    @Override
-    public String toString() {
-        return properties.values() + " : " + nodeName;
+        return Objects.hashCode(primaryType, mixinTypes, properties, nodeName);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java?rev=1445702&r1=1445701&r2=1445702&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java Wed Feb 13 16:06:27 2013
@@ -21,6 +21,8 @@ import static com.google.common.base.Pre
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 
+import com.google.common.collect.ComparisonChain;
+
 class PropertyTemplate implements Comparable<PropertyTemplate> {
 
     private final String name;
@@ -45,7 +47,11 @@ class PropertyTemplate implements Compar
 
     @Override
     public int compareTo(PropertyTemplate template) {
-        return name.compareTo(checkNotNull(template).name);
+        checkNotNull(template);
+        return ComparisonChain.start()
+                .compare(name, template.name)
+                .compare(type, template.type)
+                .result();
     }
 
     //------------------------------------------------------------< Object >--