jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1092760 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: Repository.java store/FatNode.java store/FatNodePart.java store/ObjectStore.java store/git/GitStore.java
Date Fri, 15 Apr 2011 16:37:54 GMT
Author: stefan
Date: Fri Apr 15 16:37:54 2011
New Revision: 1092760

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

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNode.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNodePart.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java

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=1092760&r1=1092759&r2=1092760&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
Fri Apr 15 16:37:54 2011
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.mk;
 
 import org.apache.jackrabbit.mk.store.Commit;
+import org.apache.jackrabbit.mk.store.MutableCommit;
+import org.apache.jackrabbit.mk.store.MutableNode;
 import org.apache.jackrabbit.mk.store.Node;
 import org.apache.jackrabbit.mk.store.ObjectStore;
 import java.io.File;
@@ -48,7 +50,7 @@ public class Repository {
     }
 
     public void shutDown() throws Exception {
-        if (! initialized) {
+        if (!initialized) {
             return;
         }
 
@@ -58,7 +60,7 @@ public class Repository {
     }
 
     public Node getNode(String revId, String path) throws Exception {
-        if (! initialized) {
+        if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
 
@@ -67,7 +69,7 @@ public class Repository {
     }
 
     public String getHeadRevision() throws Exception {
-        if (! initialized) {
+        if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
         return store.getHeadCommit().getId();

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNode.java?rev=1092760&r1=1092759&r2=1092760&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNode.java
Fri Apr 15 16:37:54 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -28,9 +29,9 @@ public class FatNode extends Node {
 
     public FatNode(String id,
                    Map<String, String> properties,
-                   List<ChildNodeEntry> children,
+                   LinkedHashMap<String, String> childEntries,
                    String nextPartId) {
-        super(id, properties, children);
+        super(id, properties, childEntries);
 
         this.nextPartId = nextPartId;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNodePart.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNodePart.java?rev=1092760&r1=1092759&r2=1092760&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNodePart.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/FatNodePart.java
Fri Apr 15 16:37:54 2011
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.mk.store;
 import org.eclipse.jgit.lib.AnyObjectId;
 import org.eclipse.jgit.lib.ObjectId;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 
 /**
@@ -26,17 +27,21 @@ import java.util.List;
  */
 public class FatNodePart extends StoredObject {
 
-    final ObjectId nextPartId;
+    final String nextPartId;
+    // map keeping insertion order
+    final LinkedHashMap<String, String> childEntries;
+
 
     public FatNodePart(String id,
-                       List<Node.ChildNodeEntry> children,
-                       ObjectId nextPartId) {
+                       LinkedHashMap<String, String> childEntries,
+                       String nextPartId) {
         super(id);
 
+        this.childEntries = childEntries;
         this.nextPartId = nextPartId;
     }
 
-    public ObjectId getNextPartId() {
+    public String getNextPartId() {
         return nextPartId;
     }
 }

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=1092760&r1=1092759&r2=1092760&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 16:37:54 2011
@@ -40,6 +40,16 @@ public class ObjectStore implements Cons
         store = new GitStore();
         store.initialize(homeDir);
 
+        // make sure we've got a HEAD commit
+        String head = store.getHeadCommitId();
+        if (head == null) {
+            String rootNodeId = store.put(NODE, new MutableNode(null).toBytes());
+            MutableCommit initialCommit = new MutableCommit();
+            initialCommit.setCommitTS(System.currentTimeMillis());
+            initialCommit.setRootNodeId(rootNodeId);
+            store.setHeadCommitId(store.put(COMMIT, initialCommit.toBytes()));
+        }
+
         initialized = true;
     }
 
@@ -53,28 +63,60 @@ public class ObjectStore implements Cons
     }
 
     public Node getNode(String id) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
         byte[] data = store.get(id, NODE);
         return Node.fromBytes(id, data);
     }
 
     public String putNode(MutableNode node) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
         return store.put(NODE, node.toBytes());
     }
 
     public Commit getCommit(String id) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
         byte[] data = store.get(id, COMMIT);
         return Commit.fromBytes(id, data);
     }
 
     public String putCommit(MutableCommit commit) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
         return store.put(COMMIT, commit.toBytes());
     }
 
     public Commit getHeadCommit() throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
         return getCommit(store.getHeadCommitId());
     }
 
+    public void setHeadCommit(String commitId) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        store.setHeadCommitId(commitId);
+    }
+
     public String computeId(int type, byte[] data) {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
         return store.computeId(type, data);
     }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java?rev=1092760&r1=1092759&r2=1092760&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
Fri Apr 15 16:37:54 2011
@@ -20,6 +20,7 @@ import org.apache.jackrabbit.mk.store.Co
 import org.apache.jackrabbit.mk.store.DataStore;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.RefUpdate;
 
 import java.io.File;
@@ -63,7 +64,8 @@ public class GitStore implements DataSto
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        return rep.getRefDatabase().getRef("HEAD").getObjectId().name();
+        Ref ref = rep.getRefDatabase().getRef("HEAD");
+        return ref == null || ref.getObjectId() == null ? null : ref.getObjectId().name();
     }
 
     public void setHeadCommitId(String commitId) throws Exception {



Mime
View raw message