jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1095740 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: MicroKernelImpl.java Repository.java store/Commit.java store/CommitBuilder.java store/MutableCommit.java store/MutableNode.java store/ObjectStore.java
Date Thu, 21 Apr 2011 15:04:46 GMT
Author: stefan
Date: Thu Apr 21 15:04:46 2011
New Revision: 1095740

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

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.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/CommitBuilder.java
    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
    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=1095740&r1=1095739&r2=1095740&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
Thu Apr 21 15:04:46 2011
@@ -2,8 +2,11 @@ package org.apache.jackrabbit.mk;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.store.Commit;
 
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  *
@@ -53,9 +56,40 @@ public class MicroKernelImpl implements 
             throw new IllegalStateException("this instance has already been disposed");
         }
 
-        // todo implement
+        List<Commit> history = new ArrayList<Commit>();
+        try {
+            Commit commit = rep.getHeadCommit();
+            while (commit != null
+                    && history.size() < maxEntries
+                    && commit.getCommitTS() >= since) {
+                history.add(commit);
+
+                String commitId = commit.getParentId();
+                if (commitId == null) {
+                    break;
+                }
+                commit = rep.getCommit(commitId);
+            }
+        } catch (Exception e) {
+            throw new MicroKernelException(e);
+        }
 
-        return null;
+        StringBuilder buf = new StringBuilder();
+        buf.append("[");
+        for (Commit commit : history) {
+            if (buf.charAt(buf.length() - 1) != '[') {
+                buf.append(",{");
+            } else {
+                buf.append("{");
+            }
+            buf.append("\"id\":\"");
+            buf.append(commit.getId());
+            buf.append("\",\"ts\":\"");
+            buf.append(commit.getCommitTS());
+            buf.append("\"}");
+        }
+        buf.append("]");
+        return buf.toString();
     }
 
     public String getJournal(String fromRevisionId, String toRevisionId) throws MicroKernelException
{

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1095740&r1=1095739&r2=1095740&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
Thu Apr 21 15:04:46 2011
@@ -75,6 +75,20 @@ public class Repository {
         return store.getHeadCommit().getId();
     }
 
+    public Commit getHeadCommit() throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+        return store.getHeadCommit();
+    }
+
+    public Commit getCommit(String id) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+        return store.getCommit(id);
+    }
+
     public Node getNode(String revId, String path) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");

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=1095740&r1=1095739&r2=1095740&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
Thu Apr 21 15:04:46 2011
@@ -26,8 +26,8 @@ import java.util.List;
  */
 public class Commit extends StoredObject {
 
-    // id's of parent commits
-    final String[] parentIds;
+    // id of parent commit
+    final String parentId;
 
     // id of root node associated with this commit
     final String rootNodeId;
@@ -35,11 +35,11 @@ public class Commit extends StoredObject
     // commit timestamp
     final long commitTS;
 
-    protected Commit(String id, String rootNodeId, long commitTS, List<String> parentIds)
{
+    protected Commit(String id, String rootNodeId, long commitTS, String parentId) {
         super(id);
 
         this.rootNodeId = rootNodeId;
-        this.parentIds = parentIds.toArray(new String[parentIds.size()]);
+        this.parentId = parentId;
         this.commitTS = commitTS;
     }
 
@@ -47,8 +47,8 @@ public class Commit extends StoredObject
         return rootNodeId;
     }
 
-    public String[] getParentIds() {
-        return parentIds;
+    public String getParentId() {
+        return parentId;
     }
 
     public long getCommitTS() {
@@ -65,12 +65,8 @@ public class Commit extends StoredObject
         }
         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());
-        }
+        String parentId = in.readUTF();
         in.close();
-        return new Commit(id, rootNodeId, commitTS, parentIds);
+        return new Commit(id, rootNodeId, commitTS, "".equals(parentId) ? null : parentId);
     }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java?rev=1095740&r1=1095739&r2=1095740&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
Thu Apr 21 15:04:46 2011
@@ -52,7 +52,7 @@ public class CommitBuilder {
         if (modParent.getChildNodeEntries().containsKey(nodeName)) {
             throw new Exception("there's already a child node with name '" + nodeName + "'");
         }
-        MutableNode newChild = new MutableNode(baseRevId);
+        MutableNode newChild = new MutableNode();
         newChild.getProperties().putAll(properties);
 
         modParent.getChildNodeEntries().put(nodeName, ""); // value will be computed on commit
@@ -126,7 +126,7 @@ public class CommitBuilder {
         }
 
         MutableCommit newCommit = new MutableCommit();
-        newCommit.getParentIds().add(baseRevId);
+        newCommit.setParentId(baseRevId);
         newCommit.setCommitTS(System.currentTimeMillis());
         newCommit.setRootNodeId(rootNodeId);
         String newRevId = store.putCommit(newCommit);
@@ -141,7 +141,7 @@ public class CommitBuilder {
     MutableNode getOrCreateStagedNode(String nodePath) throws Exception {
         MutableNode node = staged.get(nodePath);
         if (node == null) {
-            node = new MutableNode(baseRevId, rep.getNode(baseRevId, nodePath));
+            node = new MutableNode(rep.getNode(baseRevId, nodePath));
             staged.put(nodePath, node);
             // make sure all direct ancestors are staged as well
             String p1 = nodePath;
@@ -151,7 +151,7 @@ public class CommitBuilder {
                 if (n0 != null) {
                     break;
                 }
-                n0 = new MutableNode(baseRevId, rep.getNode(baseRevId, p0));
+                n0 = new MutableNode(rep.getNode(baseRevId, p0));
                 staged.put(p0, n0);
                 p1 = p0;
             }

Modified: 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=1095740&r1=1095739&r2=1095740&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableCommit.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableCommit.java
Thu Apr 21 15:04:46 2011
@@ -33,17 +33,19 @@ public class MutableCommit {
     // commit timestamp
     long commitTS;
 
-    // id's of parent commits
-    final List<String> parentIds;
+    // id of parent commit
+    String parentId;
 
     public MutableCommit() {
-        parentIds = new ArrayList<String>();
     }
 
-    public List<String> getParentIds() {
-        return parentIds;
+    public String getParentId() {
+        return parentId;
     }
 
+    public void setParentId(String parentId) {
+        this.parentId = parentId;
+    }
 
     public String getRootNodeId() {
         return rootNodeId;
@@ -70,10 +72,7 @@ public class MutableCommit {
             out.write(Constants.COMMIT);
             out.writeUTF(rootNodeId);
             out.writeLong(commitTS);
-            out.writeInt(parentIds.size());
-            for (String commitId : parentIds) {
-                out.writeUTF(commitId);
-            }
+            out.writeUTF(parentId == null ? "" : parentId);
             out.close();
         } catch (IOException safeToIgnore) {
         }

Modified: 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=1095740&r1=1095739&r2=1095740&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MutableNode.java
Thu Apr 21 15:04:46 2011
@@ -28,30 +28,22 @@ 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;
+    public MutableNode() {
         this.properties = new HashMap<String, String>();
         this.childEntries = new LinkedHashMap<String, String>();
     }
 
-    public MutableNode(String baseRevId, Node existing) {
-        this.baseRevId = baseRevId;
+    public MutableNode(Node existing) {
         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;
     }

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=1095740&r1=1095739&r2=1095740&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
Thu Apr 21 15:04:46 2011
@@ -41,7 +41,7 @@ public class ObjectStore implements Cons
         // make sure we've got a HEAD commit
         String head = store.getHeadCommitId();
         if (head == null) {
-            String rootNodeId = store.put(new MutableNode(null).toBytes());
+            String rootNodeId = store.put(new MutableNode().toBytes());
             MutableCommit initialCommit = new MutableCommit();
             initialCommit.setCommitTS(System.currentTimeMillis());
             initialCommit.setRootNodeId(rootNodeId);



Mime
View raw message