jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1368485 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: core/ContentRepositoryImpl.java kernel/KernelNodeStoreBranch.java plugins/type/DefaultTypeEditor.java
Date Thu, 02 Aug 2012 14:26:55 GMT
Author: jukka
Date: Thu Aug  2 14:26:54 2012
New Revision: 1368485

URL: http://svn.apache.org/viewvc?rev=1368485&view=rev
Log:
OAK-66: JCR Node Type Management

Add a CommitEditor that automatically adds jcr:primaryType to all nodes without it

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefaultTypeEditor.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1368485&r1=1368484&r2=1368485&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Thu Aug  2 14:26:54 2012
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.oak.kernel.
 import org.apache.jackrabbit.oak.plugins.lucene.LuceneEditor;
 import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.type.DefaultTypeEditor;
 import org.apache.jackrabbit.oak.plugins.type.TypeValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.value.ConflictValidatorProvider;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
@@ -97,6 +98,7 @@ public class ContentRepositoryImpl imple
         nodeStore = new KernelNodeStore(microKernel);
  
         List<CommitEditor> editors = new ArrayList<CommitEditor>();
+        editors.add(new DefaultTypeEditor());
         editors.add(new ValidatingEditor(validatorProvider));
         editors.add(new LuceneEditor());
         nodeStore.setEditor(new CompositeEditor(editors));

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1368485&r1=1368484&r2=1368485&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Thu Aug  2 14:26:54 2012
@@ -125,7 +125,7 @@ class KernelNodeStoreBranch implements N
         MicroKernel kernel = store.getKernel();
         CommitEditor editor = store.getEditor();
 
-        NodeState oldRoot = store.getRoot();
+        NodeState oldRoot = base;
         NodeState toCommit = editor.editCommit(store, oldRoot, currentRoot);
         setRoot(toCommit);
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefaultTypeEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefaultTypeEditor.java?rev=1368485&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefaultTypeEditor.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefaultTypeEditor.java
Thu Aug  2 14:26:54 2012
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.type;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+/**
+ * This class updates a Lucene index when node content is changed.
+ */
+public class DefaultTypeEditor implements CommitEditor {
+
+    @Override
+    public NodeState editCommit(
+            NodeStore store, NodeState before, NodeState after)
+            throws CommitFailedException {
+        // TODO: Calculate default type from the node definition
+        CoreValue defaultType = store.getValueFactory().createValue(
+                "nt:unstructured", PropertyType.NAME);
+        NodeBuilder builder = store.getBuilder(after);
+        after.compareAgainstBaseState(
+                before, new DefaultTypeDiff(builder, defaultType));
+        return builder.getNodeState();
+    }
+
+    private static class DefaultTypeDiff extends DefaultNodeStateDiff {
+
+        private final NodeBuilder builder;
+
+        private final CoreValue defaultType;
+
+        public DefaultTypeDiff(NodeBuilder builder, CoreValue defaultType) {
+            this.builder = builder;
+            this.defaultType = defaultType;
+        }
+
+        @Override
+        public void childNodeAdded(String name, NodeState after) {
+            if (!NodeStateUtils.isHidden(name)) {
+                NodeBuilder childBuilder = builder.getChildBuilder(name);
+                if (after.getProperty("jcr:primaryType") == null) {
+                    childBuilder.setProperty("jcr:primaryType", defaultType);
+                }
+                DefaultTypeDiff childDiff =
+                        new DefaultTypeDiff(childBuilder, defaultType);
+                for (ChildNodeEntry entry : after.getChildNodeEntries()) {
+                    childDiff.childNodeAdded(
+                            entry.getName(), entry.getNodeState());
+                }
+            }
+        }
+
+        @Override
+        public void childNodeChanged(
+                String name, NodeState before, NodeState after) {
+            if (!NodeStateUtils.isHidden(name)) {
+                NodeBuilder childBuilder = builder.getChildBuilder(name);
+                DefaultTypeDiff childDiff =
+                        new DefaultTypeDiff(childBuilder, defaultType);
+                after.compareAgainstBaseState(before, childDiff);
+            }
+        }
+
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/DefaultTypeEditor.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message