jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1297932 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk: MicroKernelImpl.java Repository.java store/CopyingGC.java store/DefaultRevisionStore.java store/RevisionProvider.java store/StoredNodeAsState.java
Date Wed, 07 Mar 2012 11:03:21 GMT
Author: jukka
Date: Wed Mar  7 11:03:21 2012
New Revision: 1297932

URL: http://svn.apache.org/viewvc?rev=1297932&view=rev
Log:
OAK-3: Internal tree model

Apply proposed patch to start integrating the interfaces with existing MK implementation

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/StoredNodeAsState.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1297932&r1=1297931&r2=1297932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Wed Mar  7 11:03:21 2012
@@ -23,7 +23,6 @@ import org.apache.jackrabbit.mk.json.Jso
 import org.apache.jackrabbit.mk.model.ChildNodeEntry;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.CommitBuilder;
-import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
 import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.model.TraversingNodeDiffHandler;
@@ -31,12 +30,13 @@ import org.apache.jackrabbit.mk.store.No
 import org.apache.jackrabbit.mk.util.CommitGate;
 import org.apache.jackrabbit.mk.util.PathUtils;
 import org.apache.jackrabbit.mk.util.SimpleLRUCache;
+import org.apache.jackrabbit.oak.tree.NodeState;
+import org.apache.jackrabbit.oak.tree.PropertyState;
 
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -226,7 +226,8 @@ public class MicroKernelImpl implements 
             if (node1 == null) {
                 if (node2 != null) {
                     buff.tag('+').key(path).object();
-                    toJson(buff, node2, Integer.MAX_VALUE, 0, -1, false);
+                    toJson(buff, rep.getRevisionStore().getNodeState(node2),
+                            Integer.MAX_VALUE, 0, -1, false);
                     return buff.endObject().newline().toString();
                 } else {
                     throw new MicroKernelException("path doesn't exist in the specified revisions:
" + path);
@@ -271,7 +272,7 @@ public class MicroKernelImpl implements 
                     buff.tag('+').
                             key(PathUtils.concat(getCurrentPath(), added.getName())).object();
                     try {
-                        toJson(buff, rep.getRevisionStore().getNode(added.getId()), Integer.MAX_VALUE,
0, -1, false);
+                        toJson(buff, store.getNodeState(store.getNode(added.getId())), Integer.MAX_VALUE,
0, -1, false);
                     } catch (Exception e) {
                         buff.value("ERROR: failed to retrieve node " + added.getId());
                     }
@@ -338,7 +339,7 @@ public class MicroKernelImpl implements 
                         buff.tag('+').
                                 key(PathUtils.concat(getCurrentPath(), added.getName())).object();
                         try {
-                            toJson(buff, rep.getRevisionStore().getNode(added.getId()), Integer.MAX_VALUE,
0, -1, false);
+                            toJson(buff, store.getNodeState(store.getNode(added.getId())),
Integer.MAX_VALUE, 0, -1, false);
                         } catch (Exception e) {
                             buff.value("ERROR: failed to retrieve node " + added.getId());
                         }
@@ -394,7 +395,7 @@ public class MicroKernelImpl implements 
         revisionId = revisionId == null ? getHeadRevision() : revisionId;
 
         try {
-            return rep.getNode(revisionId, path).getChildNodeCount();
+            return rep.getNodeState(revisionId, path).getChildNodeCount();
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }
@@ -415,7 +416,7 @@ public class MicroKernelImpl implements 
 
         try {
             JsopBuilder buf = new JsopBuilder().object();
-            toJson(buf, rep.getNode(revisionId, path), depth, (int) offset, count, true);
+            toJson(buf, rep.getNodeState(revisionId, path), depth, (int) offset, count, true);
             return buf.endObject().toString();
         } catch (Exception e) {
             throw new MicroKernelException(e);
@@ -594,20 +595,21 @@ public class MicroKernelImpl implements 
 
     //-------------------------------------------------------< implementation >
 
-    void toJson(JsopBuilder builder, Node node, int depth, int offset, int count, boolean
inclVirtualProps) throws Exception {
-        for (Map.Entry<String, String> prop : node.getProperties().entrySet()) {
-            builder.key(prop.getKey()).encodedValue(prop.getValue());
+    void toJson(JsopBuilder builder, NodeState node, int depth, int offset, int count, boolean
inclVirtualProps) throws Exception {
+        for (PropertyState property : node.getProperties()) {
+            builder.key(property.getName()).encodedValue(property.getEncodedValue());
         }
         long childCount = node.getChildNodeCount();
         if (inclVirtualProps) {
             builder.key(":childNodeCount").value(childCount);
         }
         if (childCount > 0 && depth >= 0) {
-            for (Iterator<ChildNodeEntry> it = node.getChildNodeEntries(offset, count);
it.hasNext(); ) {
-                ChildNodeEntry cne = it.next();
-                builder.key(cne.getName()).object();
+            // TODO: Use an import once the conflict with .mk.model is resolved
+            for (org.apache.jackrabbit.oak.tree.ChildNodeEntry entry
+                    : node.getChildNodeEntries(offset, count)) {
+                builder.key(entry.getName()).object();
                 if (depth > 0) {
-                    toJson(builder, rep.getRevisionStore().getNode(cne.getId()), depth -
1, 0, -1, inclVirtualProps);
+                    toJson(builder, entry.getNode(), depth - 1, 0, -1, inclVirtualProps);
                 }
                 builder.endObject();
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1297932&r1=1297931&r2=1297932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java Wed
Mar  7 11:03:21 2012
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.mk.store.No
 import org.apache.jackrabbit.mk.store.RevisionStore;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.PathUtils;
+import org.apache.jackrabbit.oak.tree.NodeState;
 
 /**
  *
@@ -110,6 +111,10 @@ public class Repository {
         return rs.getCommit(id);
     }
 
+    public NodeState getNodeState(String revId, String path) throws NotFoundException, Exception
{
+        return rs.getNodeState(getNode(revId, path));
+    }
+
     /**
      *
      * @param revId

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java?rev=1297932&r1=1297931&r2=1297932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/CopyingGC.java
Wed Mar  7 11:03:21 2012
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.mk.model.Mu
 import org.apache.jackrabbit.mk.model.StoredCommit;
 import org.apache.jackrabbit.mk.model.StoredNode;
 import org.apache.jackrabbit.mk.util.IOUtils;
+import org.apache.jackrabbit.oak.tree.NodeState;
 
 /**
  * Revision garbage collector that copies reachable revisions from a "from" revision
@@ -137,6 +138,10 @@ public class CopyingGC implements Revisi
     
     // ---------------------------------------------------------- RevisionStore
 
+    public NodeState getNodeState(StoredNode node) {
+        return new StoredNodeAsState(node, this);
+    }
+
     public StoredNode getNode(String id) throws NotFoundException, Exception {
         if (running) {
             try {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java?rev=1297932&r1=1297931&r2=1297932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/DefaultRevisionStore.java
Wed Mar  7 11:03:21 2012
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.mk.store.pm
 import org.apache.jackrabbit.mk.store.pm.PersistenceManager;
 import org.apache.jackrabbit.mk.util.SimpleLRUCache;
 import org.apache.jackrabbit.mk.util.StringUtils;
+import org.apache.jackrabbit.oak.tree.NodeState;
 
 import java.io.Closeable;
 import java.io.File;
@@ -255,6 +256,10 @@ public class DefaultRevisionStore implem
 
     //-----------------------------------------------------< RevisionProvider >
 
+    public NodeState getNodeState(StoredNode node) {
+        return new StoredNodeAsState(node, this);
+    }
+
     public StoredNode getNode(String id) throws NotFoundException, Exception {
         verifyInitialized();
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java?rev=1297932&r1=1297931&r2=1297932&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/RevisionProvider.java
Wed Mar  7 11:03:21 2012
@@ -19,12 +19,22 @@ package org.apache.jackrabbit.mk.store;
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.StoredCommit;
 import org.apache.jackrabbit.mk.model.StoredNode;
+import org.apache.jackrabbit.oak.tree.NodeState;
 
 /**
  *
  */
 public interface RevisionProvider {
 
+    /**
+     * Adapts the given {@link StoredNode} to a corresponding
+     * {@link NodeState} instance.
+     *
+     * @param node stored node instance
+     * @return node state adapter
+     */
+    NodeState getNodeState(StoredNode node);
+
     StoredNode getNode(String id) throws NotFoundException, Exception;
     StoredCommit getCommit(String id) throws NotFoundException, Exception;
     ChildNodeEntriesMap getCNEMap(String id) throws NotFoundException, Exception;

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/StoredNodeAsState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/StoredNodeAsState.java?rev=1297932&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/StoredNodeAsState.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/StoredNodeAsState.java
Wed Mar  7 11:03:21 2012
@@ -0,0 +1,157 @@
+/*
+ * 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.mk.store;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.jackrabbit.mk.model.StoredNode;
+import org.apache.jackrabbit.oak.tree.ChildNodeEntry;
+import org.apache.jackrabbit.oak.tree.NodeState;
+import org.apache.jackrabbit.oak.tree.PropertyState;
+
+class StoredNodeAsState implements NodeState {
+
+    private final StoredNode node;
+
+    private final RevisionProvider provider;
+
+    public StoredNodeAsState(StoredNode node, RevisionProvider provider) {
+        this.node = node;
+        this.provider = provider;
+    }
+
+    private static class SimplePropertyState implements PropertyState {
+
+        private final String name;
+
+        private final String value;
+
+        public SimplePropertyState(String name, String value) {
+            this.name = name;
+            this.value = value;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getEncodedValue() {
+            return value;
+        }
+
+    }
+
+    public PropertyState getProperty(String name) {
+        String value = node.getProperties().get(name);
+        if (value != null) {
+            return new SimplePropertyState(name, value);
+        } else {
+            return null;
+        }
+    }
+
+    public long getPropertyCount() {
+        return node.getProperties().size();
+    }
+
+    public Iterable<PropertyState> getProperties() {
+        return new Iterable<PropertyState>() {
+            public Iterator<PropertyState> iterator() {
+                final Iterator<Map.Entry<String, String>> iterator =
+                        node.getProperties().entrySet().iterator();
+                return new Iterator<PropertyState>() {
+                    public boolean hasNext() {
+                        return iterator.hasNext();
+                    }
+                    public PropertyState next() {
+                        Map.Entry<String, String> entry = iterator.next();
+                        return new SimplePropertyState(
+                                entry.getKey(), entry.getValue());
+                    }
+                    public void remove() {
+                        throw new UnsupportedOperationException();
+                    }
+                };
+            }
+        };
+    }
+
+    public NodeState getChildNode(String name) {
+        org.apache.jackrabbit.mk.model.ChildNodeEntry entry =
+                node.getChildNodeEntry(name);
+        if (entry != null) {
+            return getChildNodeEntry(entry).getNode();
+        } else {
+            return null;
+        }
+    }
+
+    public long getChildNodeCount() {
+        return node.getChildNodeCount();
+    }
+
+    public Iterable<ChildNodeEntry> getChildNodeEntries(
+            final long offset, final long length) {
+        if (length < -1) {
+            throw new IllegalArgumentException("Illegal length: " + length);
+        } else if (offset > Integer.MAX_VALUE) {
+            return Collections.emptyList();
+        } else {
+            return new Iterable<ChildNodeEntry>() {
+                public Iterator<ChildNodeEntry> iterator() {
+                    int count = -1;
+                    if (length < Integer.MAX_VALUE) {
+                        count = (int) length;
+                    }
+                    final Iterator<org.apache.jackrabbit.mk.model.ChildNodeEntry> iterator
=
+                            node.getChildNodeEntries((int) offset, count);
+                    return new Iterator<ChildNodeEntry>() {
+                        public boolean hasNext() {
+                            return iterator.hasNext();
+                        }
+                        public ChildNodeEntry next() {
+                            return getChildNodeEntry(iterator.next());
+                        }
+                        public void remove() {
+                            throw new UnsupportedOperationException();
+                        }
+                    };
+                }
+            };
+        }
+    }
+
+    private ChildNodeEntry getChildNodeEntry(
+            final org.apache.jackrabbit.mk.model.ChildNodeEntry entry) {
+        return new ChildNodeEntry() {
+            public String getName() {
+                return entry.getName();
+            }
+            public NodeState getNode() {
+                try {
+                    StoredNode child = provider.getNode(entry.getId());
+                    return new StoredNodeAsState(child, provider);
+                } catch (Exception e) {
+                    throw new RuntimeException("Unexpected error", e);
+                }
+            }
+        };
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/store/StoredNodeAsState.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message