jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1163653 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem: MemoryKernelImpl.java NodeMap.java Revision.java
Date Wed, 31 Aug 2011 14:55:14 GMT
Author: thomasm
Date: Wed Aug 31 14:55:13 2011
New Revision: 1163653

URL: http://svn.apache.org/viewvc?rev=1163653&view=rev
Log:
Revision parsing and formatting

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1163653&r1=1163652&r2=1163653&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Wed Aug 31 14:55:13 2011
@@ -62,7 +62,6 @@ public class MemoryKernelImpl implements
 
     private AbstractBlobStore ds;
     private long headRevId;
-    private long rootId;
     private NodeMap nodeMap;
     private NonDescendingClock clock = new NonDescendingClock(System.currentTimeMillis());
     private final CommitGate gate = new CommitGate();
@@ -75,9 +74,10 @@ public class MemoryKernelImpl implements
         } else {
             ds = new MemoryBlobStore();
         }
-        rootId = nodeMap.getRootId();
-        if (rootId == 0) {
+        if (nodeMap.getRootId() == 0) {
             clear();
+        } else {
+            headRevId = Revision.parseId(getRoot().getNode("head").getProperty("rev"));
         }
     }
 
@@ -92,7 +92,6 @@ public class MemoryKernelImpl implements
 
     public void clear() {
         headRevId = 0;
-        rootId = 0;
         ds.clear();
         nodeMap.clear();
         NodeImpl head = new NodeImpl(nodeMap, 0);
@@ -100,7 +99,7 @@ public class MemoryKernelImpl implements
         NodeImpl root = new NodeImpl(nodeMap, 0);
         root.addChildNode("head", head);
         root.addChildNode("old", new NodeImpl(nodeMap, 0));
-        rootId = nodeMap.addNode(root);
+        nodeMap.commit(root);
     }
 
     public synchronized String commit(String rootPath, String jsonDiff, String revisionId,
String message) {
@@ -113,7 +112,7 @@ public class MemoryKernelImpl implements
         // TODO metadata in storage (version)
         // TODO optional read / write version in json 'api' (as comments?)
         long oldRevision = headRevId++;
-        NodeImpl root = nodeMap.getNode(rootId);
+        NodeImpl root = nodeMap.getNode(nodeMap.getRootId());
         NodeImpl head = root.getNode("head");
         NodeImpl oldHead = head;
         NodeImpl data = head.getNode("data");
@@ -247,7 +246,7 @@ public class MemoryKernelImpl implements
             }
         }
         head = head.setChild("data", data, headRevId);
-        head = head.cloneAndSetProperty("rev", "" + headRevId, headRevId);
+        head = head.cloneAndSetProperty("rev", Revision.formatId(headRevId), headRevId);
         head = head.cloneAndSetProperty("time", "" + clock.time(), headRevId);
         String diff = w.toString();
         NodeImpl commit = new NodeImpl(nodeMap, headRevId);
@@ -260,22 +259,24 @@ public class MemoryKernelImpl implements
             NodeImpl newOld = new NodeImpl(nodeMap, headRevId);
             old = newOld.setChild("old", old, headRevId);
         }
-        old = old.setChild("" + oldRevision, oldHead, headRevId);
+        old = old.setChild(Revision.formatId(oldRevision), oldHead, headRevId);
         root = root.setChild("old", old, headRevId);
-        nodeMap.addNode(root);
-        nodeMap.commit();
-        rootId = root.getId();
+        nodeMap.commit(root);
         String headRev = getHeadRevision();
         gate.commit(headRev);
         return headRev;
     }
 
+    NodeImpl getRoot() {
+        return nodeMap.getNode(nodeMap.getRootId());
+    }
+
     public String getHeadRevision() {
-        return getRevisionId(headRevId);
+        return Revision.formatId(headRevId);
     }
 
     public String getRevisions(long since, int maxEntries) {
-        NodeImpl node = nodeMap.getNode(rootId);
+        NodeImpl node = getRoot();
         ArrayList<Revision> revisions = new ArrayList<Revision>();
         Revision r = new Revision(node.getNode("head"));
         if (since < r.getTime()) {
@@ -306,9 +307,9 @@ public class MemoryKernelImpl implements
     }
 
     public String getJournal(String fromRevisionId, String toRevisionId) {
-        long fromRevId = parseRevisionId(fromRevisionId);
-        long toRevId = parseRevisionId(toRevisionId);
-        NodeImpl node = nodeMap.getNode(rootId);
+        long fromRevId = Revision.parseId(fromRevisionId);
+        long toRevId = Revision.parseId(toRevisionId);
+        NodeImpl node = getRoot();
         ArrayList<Revision> revisions = new ArrayList<Revision>();
         Revision r = new Revision(node.getNode("head"));
         if (r.getId() >= fromRevId) {
@@ -328,7 +329,7 @@ public class MemoryKernelImpl implements
         for (Revision rev : revisions) {
             if (rev.getId() >= fromRevId && rev.getId() <= toRevId) {
                 buff.object().
-                    key("id").value(Long.toString(rev.getId())).
+                    key("id").value(Revision.formatId(rev.getId())).
                     key("ts").value(rev.getTime()).
                     key("msg").value(rev.getMsg()).
                     key("changes").value(rev.getDiff()).
@@ -356,8 +357,8 @@ public class MemoryKernelImpl implements
     }
 
     private NodeImpl getRevision(String revisionId) {
-        long revId = parseRevisionId(revisionId);
-        NodeImpl node = nodeMap.getNode(rootId);
+        long revId = Revision.parseId(revisionId);
+        NodeImpl node = getRoot();
         if (revId == headRevId) {
             node = node.getNode("head");
         } else {
@@ -383,14 +384,6 @@ public class MemoryKernelImpl implements
         return getRevision(revisionId).exists(path.substring(1));
     }
 
-    private static String getRevisionId(long revId) {
-        return Long.toHexString(revId);
-    }
-
-    private static long parseRevisionId(String revisionId) {
-        return Long.parseLong(revisionId, 16);
-    }
-
     public long getLength(String blobId) {
         try {
             return ds.getBlobLength(blobId);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java?rev=1163653&r1=1163652&r2=1163653&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
Wed Aug 31 14:55:13 2011
@@ -26,6 +26,7 @@ public class NodeMap {
 
     private HashMap<Long, NodeImpl> nodes = new HashMap<Long, NodeImpl>();
     private long nextId = 1;
+    private long rootId;
 
     public long addNode(NodeImpl node) {
         long x = node.getId();
@@ -51,10 +52,6 @@ public class NodeMap {
         return 20;
     }
 
-    public void commit() {
-        // ignore
-    }
-
     public void close() {
         // ignore
     }
@@ -72,8 +69,12 @@ public class NodeMap {
         return (IOUtils.readVarInt(in) << 32) | IOUtils.readInt(in);
     }
 
+    public long commit(NodeImpl root) {
+        return rootId = addNode(root);
+    }
+
     public long getRootId() {
-        return 0;
+        return rootId;
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java?rev=1163653&r1=1163652&r2=1163653&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
Wed Aug 31 14:55:13 2011
@@ -32,7 +32,7 @@ public class Revision implements Compara
     Revision(NodeImpl node) {
         this.node = node;
         if (node.hasProperty("rev")) {
-            id = Long.parseLong(node.getProperty("rev"));
+            id = parseId(node.getProperty("rev"));
             time = Long.parseLong(node.getProperty("time"));
         } else {
             id = time = 0;
@@ -82,9 +82,17 @@ public class Revision implements Compara
 
     public String toString() {
         return new JsopBuilder().object().
-            key("id").value(Long.toString(id)).
+            key("id").value(formatId(id)).
             key("ts").value(time).
         endObject().toString();
     }
 
+    static long parseId(String revisionId) {
+        return Long.parseLong(revisionId, 16);
+    }
+
+    static String formatId(long revId) {
+        return Long.toHexString(revId);
+    }
+
 }



Mime
View raw message