jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1092657 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: MicroKernelImpl.java api/MicroKernel.java store/Commit.java store/MutableCommit.java store/MutableNode.java store/Node.java store/ObjectStore.java
Date Fri, 15 Apr 2011 10:34:42 GMT
Author: stefan
Date: Fri Apr 15 10:34:41 2011
New Revision: 1092657

URL: http://svn.apache.org/viewvc?rev=1092657&view=rev
Log:
MicroKernel prototype (WIP)

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableCommit.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Commit.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Node.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1092657&r1=1092656&r2=1092657&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Fri Apr 15 10:34:41 2011
@@ -68,20 +68,20 @@ public class MicroKernelImpl implements 
         return null;
     }
 
-    public boolean nodeExists(String idOrPath, String revisionId) throws MicroKernelException
{
+    public boolean nodeExists(String path, String revisionId) throws MicroKernelException
{
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
 
         try {
-            rep.getNode(idOrPath, revisionId);
+            rep.getNode(path, revisionId);
             return true;
         } catch (Exception e) {
             return false;
         }
     }
 
-    public String getNodes(String idOrPath, int depth, String revisionId) throws MicroKernelException
{
+    public String getNodes(String path, int depth, String revisionId) throws MicroKernelException
{
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
@@ -91,7 +91,7 @@ public class MicroKernelImpl implements 
         return null;
     }
 
-    public String getChildNodes(String idOrPath, long offset, long count, int depth, String
revisionId) throws MicroKernelException {
+    public String getChildNodes(String path, long offset, long count, int depth, String revisionId)
throws MicroKernelException {
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
@@ -101,19 +101,19 @@ public class MicroKernelImpl implements 
         return null;
     }
 
-    public long getChildNodeCount(String idOrPath, String revisionId) throws MicroKernelException
{
+    public long getChildNodeCount(String path, String revisionId) throws MicroKernelException
{
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
 
         try {
-            return rep.getNode(idOrPath, revisionId).getChildNodeEntries().size();
+            return rep.getNode(path, revisionId).getChildNodeEntries().size();
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }
     }
 
-    public String commit(String idOrPath, String jsonDiff, String revisionId) throws MicroKernelException
{
+    public String commit(String path, String jsonDiff, String revisionId) throws MicroKernelException
{
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1092657&r1=1092656&r2=1092657&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Fri Apr 15 10:34:41 2011
@@ -145,12 +145,12 @@ public interface MicroKernel {
     /**
      * Determines whether the specified node exists.
      *
-     * @param idOrPath identifier or path denoting node
+     * @param path path denoting node
      * @param revisionId revision
      * @return <code>true</code> if the specified node exists, otherwise <code>false</code>
      * @throws MicroKernelException if an error occurs
      */
-    boolean nodeExists(String idOrPath, String revisionId) throws MicroKernelException;
+    boolean nodeExists(String path, String revisionId) throws MicroKernelException;
 
     /**
      * Returns the node tree rooted at the specified parent node. The depth of
@@ -182,7 +182,8 @@ public interface MicroKernel {
      * although they might not be included in the tree.</li>
      * <li><code>:childNodeCount > lengthOf(:childNodes)</code> indicates
that the
      * node does have more child nodes than those included in the tree. Large number
-     * of child nodes can be retrieved in chunks using the {@link #getChildNodes} method</li>
+     * of child nodes can be retrieved in chunks using the
+     * {@link #getChildNodes(String, long, long, int, String)} method</li>
      * </ul>
      *
      * TBD: Simpler and more intuitive format, albeit not strictly JSON compliant
@@ -207,21 +208,21 @@ public interface MicroKernel {
      * }
      * </pre>
      *
-     * @param idOrPath identifier or path denoting root of node tree to be retrieved
+     * @param path path denoting root of node tree to be retrieved
      * @param depth maximum depth of returned tree
      * @param revisionId revision
      * @return node tree in JSON format
      * @throws MicroKernelException if an error occurs
      */
-    String /* jsonTree */ getNodes(String idOrPath, int depth, String revisionId) throws
MicroKernelException;
+    String /* jsonTree */ getNodes(String path, int depth, String revisionId) throws MicroKernelException;
 
     // specialized methods for reading flat hierarchies
 
     /**
-     * Similar to {@link #getNodes}, except that this method returns an array
-     * of child node trees and allows for reading large lists of child nodes
-     * in chunks (by specifying appropriate values for <code>offset</code>
-     * and <code>count</code>).
+     * Similar to {@link #getNodes(String, int, String)}, except that this method
+     * returns an array of child node trees and allows for reading large lists
+     * of child nodes in chunks (by specifying appropriate values for
+     * <code>offset</code> and <code>count</code>).
      * <p/>
      * The depth of the returned trees is governed by the <code>depth</code>
parameter:
      * <table>
@@ -239,7 +240,7 @@ public interface MicroKernel {
      * ]
      * </pre>
      *
-     * @param idOrPath identifier or path denoting parent node
+     * @param path path denoting parent node
      * @param offset start position in child node list
      * @param count maximum number of child nodes to retrieve
      * @param depth maximum depth of returned trees
@@ -247,19 +248,19 @@ public interface MicroKernel {
      * @return array of node tree in JSON format
      * @throws MicroKernelException if an error occurs
      */
-    String /* array of jsonTrees */ getChildNodes(String idOrPath, long offset, long count,
int depth, String revisionId) throws MicroKernelException;
+    String /* array of jsonTrees */ getChildNodes(String path, long offset, long count, int
depth, String revisionId) throws MicroKernelException;
 
     /**
      * Returns the number of child nodes of the specified parent node.
      *
      * @todo if we represent the number of child nodes as a special property on the parent
(":childNodeCount") there's probably no need for a specific api method (TBD)
      *
-     * @param idOrPath identifier or path denoting parent node
+     * @param path path denoting parent node
      * @param revisionId revision
      * @return number of child nodes
      * @throws MicroKernelException if an error occurs
      */
-    long /* count */ getChildNodeCount(String idOrPath, String revisionId)
+    long /* count */ getChildNodeCount(String path, String revisionId)
             throws MicroKernelException;
 
 
@@ -268,13 +269,13 @@ public interface MicroKernel {
     /**
      * Applies the specified changes on the specified target node.
      *
-     * @param idOrPath identifier or path denoting target node
+     * @param path path denoting target node
      * @param jsonDiff changes to be applied in JSON diff format.
      * @param revisionId revision the changes are based on
      * @return id of newly created revision
      * @throws MicroKernelException if an error occurs
      */
-    String /* revisionId */ commit(String idOrPath, String jsonDiff, String revisionId)
+    String /* revisionId */ commit(String path, String jsonDiff, String revisionId)
             throws MicroKernelException;
 
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Commit.java?rev=1092657&r1=1092656&r2=1092657&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Commit.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Commit.java
Fri Apr 15 10:34:41 2011
@@ -16,6 +16,11 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Immutable Commit object...
  */
@@ -27,11 +32,15 @@ public class Commit extends StoredObject
     // id of root node associated with this commit
     final String rootNodeId;
 
-    public Commit(String id, String rootNodeId, String[] parentIds) {
+    // commit timestamp
+    final long commitTS;
+
+    protected Commit(String id, String rootNodeId, long commitTS, List<String> parentIds)
{
         super(id);
 
         this.rootNodeId = rootNodeId;
-        this.parentIds = parentIds;
+        this.parentIds = parentIds.toArray(new String[parentIds.size()]);
+        this.commitTS = commitTS;
     }
 
     public String getRootNodeId() {
@@ -41,4 +50,24 @@ public class Commit extends StoredObject
     public String[] getParentIds() {
         return parentIds;
     }
+
+    public long getCommitTS() {
+        return commitTS;
+    }
+
+    //--------------------------------------------------------< serialization >
+
+    public static Commit fromBytes(String id, byte[] data) throws Exception {
+        ByteArrayInputStream bais = new ByteArrayInputStream(data);
+        DataInputStream in = new DataInputStream(bais);
+        String rootNodeId = in.readUTF();
+        long commitTS = in.readLong();
+        int count = in.readInt();
+        List<String> parentIds = new ArrayList<String>(count);
+        while (count-- > 0) {
+            parentIds.add(in.readUTF());
+        }
+        in.close();
+        return new Commit(id, rootNodeId, commitTS, parentIds);
+    }
 }

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableCommit.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableCommit.java?rev=1092657&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableCommit.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableCommit.java
Fri Apr 15 10:34:41 2011
@@ -0,0 +1,82 @@
+/*
+ * 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.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public class MutableCommit {
+
+    // id of root node associated with this commit
+    String rootNodeId;
+
+    // commit timestamp
+    long commitTS;
+
+    // id's of parent commits
+    final List<String> parentIds;
+
+    public MutableCommit() {
+        parentIds = new ArrayList<String>();
+    }
+
+    public List<String> getParentIds() {
+        return parentIds;
+    }
+
+
+    public String getRootNodeId() {
+        return rootNodeId;
+    }
+
+    public void setRootNodeId(String rootNodeId) {
+        this.rootNodeId = rootNodeId;
+    }
+
+    public long getCommitTS() {
+        return commitTS;
+    }
+
+    public void setCommitTS(long commitTS) {
+        this.commitTS = commitTS;
+    }
+
+    //--------------------------------------------------------< serialization >
+
+    public byte[] toBytes() {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream out = new DataOutputStream(baos);
+        try {
+            out.writeUTF(rootNodeId);
+            out.writeLong(commitTS);
+            out.write(parentIds.size());
+            for (String commitId : parentIds) {
+                out.writeUTF(commitId);
+            }
+            out.close();
+        } catch (IOException safeToIgnore) {
+        }
+
+        return baos.toByteArray();
+    }
+}

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java?rev=1092657&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
Fri Apr 15 10:34:41 2011
@@ -0,0 +1,90 @@
+/*
+ * 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.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class MutableNode {
+
+    final String baseRevId;
+
+    final Map<String, String> properties;
+
+    // map keeping insertion order
+    final LinkedHashMap<String, String> childEntries;
+
+
+    public MutableNode(String baseRevId) {
+        this.baseRevId = baseRevId;
+        this.properties = new HashMap<String, String>();
+        this.childEntries = new LinkedHashMap<String, String>();
+    }
+
+    public MutableNode(String baseRevId, Node existing) {
+        this.baseRevId = baseRevId;
+        this.properties = new HashMap<String, String>(existing.getProperties());
+        this.childEntries = new LinkedHashMap<String, String>(existing.getChildNodeEntries());
+    }
+
+    public String getBaseRevId() {
+        return baseRevId;
+    }
+
+    public Map<String, String> getProperties() {
+        return properties;
+    }
+
+    /**
+     * Returns a map of names and id's which keeps insertion order.
+     *
+     * @return
+     */
+    public Map<String, String> getChildEntries() {
+        return childEntries;
+    }
+
+    //--------------------------------------------------------< serialization >
+
+    public byte[] toBytes() {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream out = new DataOutputStream(baos);
+        try {
+            out.write(properties.size());
+            for (Map.Entry<String, String> entry : properties.entrySet()) {
+                out.writeUTF(entry.getKey());
+                out.writeUTF(entry.getValue());
+            }
+            out.write(childEntries.size());
+            for (Map.Entry<String, String> entry : childEntries.entrySet()) {
+                out.writeUTF(entry.getKey());
+                out.writeUTF(entry.getValue());
+            }
+            out.close();
+        } catch (IOException safeToIgnore) {
+        }
+
+        return baos.toByteArray();
+    }
+}

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Node.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Node.java?rev=1092657&r1=1092656&r2=1092657&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Node.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Node.java
Fri Apr 15 10:34:41 2011
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -28,18 +31,15 @@ import java.util.Map;
 public class Node extends StoredObject {
 
     final Map<String, String> properties;
+    // map keeping insertion order
     final LinkedHashMap<String, String> childEntries;
 
-    public Node(String id,
+    protected Node(String id,
                 Map<String, String> properties,
-                List<ChildNodeEntry> children) {
+                LinkedHashMap<String, String> childEntries) {
         super(id);
-        this.properties = new HashMap<String, String>();
-        this.properties.putAll(properties);
-        childEntries = new LinkedHashMap<String, String>(children.size());
-        for (ChildNodeEntry cne : children) {
-            childEntries.put(cne.getName(), cne.getId());
-        }
+        this.properties = properties;
+        this.childEntries = childEntries;
     }
 
     public Map<String, String> getProperties() {
@@ -55,23 +55,26 @@ public class Node extends StoredObject {
         return Collections.unmodifiableMap(childEntries);
     }
 
-    //--------------------------------------------------------< inner classes >
-    public static class ChildNodeEntry {
-
-        final String name;
-        final String id;
+    //--------------------------------------------------------< serialization >
 
-        public ChildNodeEntry(String name, String id) {
-            this.name = name;
-            this.id = id;
+    public static Node fromBytes(String id, byte[] data) throws Exception {
+        ByteArrayInputStream bais = new ByteArrayInputStream(data);
+        DataInputStream in = new DataInputStream(bais);
+        int count = in.readInt();
+        Map<String, String> props = new HashMap<String, String>(count);
+        while (count-- > 0) {
+            String name = in.readUTF();
+            String value = in.readUTF();
+            props.put(name, value);
         }
-
-        public String getName() {
-            return name;
-        }
-
-        public String getId() {
-            return id;
+        count = in.readInt();
+        LinkedHashMap<String, String> childEntries = new LinkedHashMap<String, String>(count);
+        while (count-- > 0) {
+            String name = in.readUTF();
+            String childId = in.readUTF();
+            childEntries.put(name, childId);
         }
+        in.close();
+        return new Node(id, props, childEntries);
     }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java?rev=1092657&r1=1092656&r2=1092657&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
Fri Apr 15 10:34:41 2011
@@ -54,16 +54,20 @@ public class ObjectStore implements Cons
 
     public Node getNode(String id) throws Exception {
         byte[] data = store.get(id, NODE);
-        // todo deserialize Node object
-        Node node = null;
-        return node;
+        return Node.fromBytes(id, data);
+    }
+
+    public String putNode(MutableNode node) throws Exception {
+        return store.put(NODE, node.toBytes());
     }
 
     public Commit getCommit(String id) throws Exception {
         byte[] data = store.get(id, COMMIT);
-        // todo deserialize Commit object
-        Commit commit = null;
-        return commit;
+        return Commit.fromBytes(id, data);
+    }
+
+    public String putCommit(MutableCommit commit) throws Exception {
+        return store.put(COMMIT, commit.toBytes());
     }
 
     public Commit getHeadCommit() throws Exception {



Mime
View raw message