jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1094590 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store: Commit.java DataStore.java GitStore.java MutableCommit.java MutableNode.java Node.java ObjectStore.java git/GitStore.java
Date Mon, 18 Apr 2011 14:28:06 GMT
Author: stefan
Date: Mon Apr 18 14:28:05 2011
New Revision: 1094590

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

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/GitStore.java
      - copied, changed from r1092760, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
Removed:
    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/store/Commit.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DataStore.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/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/store/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Commit.java?rev=1094590&r1=1094589&r2=1094590&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
Mon Apr 18 14:28:05 2011
@@ -60,6 +60,9 @@ public class Commit extends StoredObject
     public static Commit fromBytes(String id, byte[] data) throws Exception {
         ByteArrayInputStream bais = new ByteArrayInputStream(data);
         DataInputStream in = new DataInputStream(bais);
+        if (in.read() != Constants.COMMIT) {
+            throw new Exception("unknown data format");
+        }
         String rootNodeId = in.readUTF();
         long commitTS = in.readLong();
         int count = in.readInt();

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DataStore.java?rev=1094590&r1=1094589&r2=1094590&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DataStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DataStore.java
Mon Apr 18 14:28:05 2011
@@ -22,7 +22,7 @@ package org.apache.jackrabbit.mk.store;
  */
 public interface DataStore {
 
-    byte[] get(String id, int typeHint) throws Exception;
+    byte[] get(String id) throws Exception;
 
-    String /* id */ put(int type, byte[] data) throws Exception;
+    String /* id */ put(byte[] data) throws Exception;
 }

Copied: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/GitStore.java
(from r1092760, 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/GitStore.java?p2=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/GitStore.java&p1=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java&r1=1092760&r2=1094590&rev=1094590&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/GitStore.java
Mon Apr 18 14:28:05 2011
@@ -14,23 +14,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.store.git;
+package org.apache.jackrabbit.mk.store;
 
-import org.apache.jackrabbit.mk.store.Constants;
 import org.apache.jackrabbit.mk.store.DataStore;
+import org.eclipse.jgit.lib.Constants;
 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 org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.storage.file.FileRepository;
 
 import java.io.File;
 
 /**
  *
  */
-public class GitStore implements DataStore, Constants {
+public class GitStore implements DataStore {
 
-    MicroKernelRepository rep;
+    Repository rep;
     boolean initialized;
 
     public GitStore() {
@@ -43,7 +45,7 @@ public class GitStore implements DataSto
         }
 
         File dir = new File(homeDir, ".git");
-        rep = new MicroKernelRepository(dir);
+        rep = new FileRepository(dir);
         if (! dir.exists()) {
             rep.create(true);
         }
@@ -77,33 +79,27 @@ public class GitStore implements DataSto
         RefUpdate.Result result = refUpd.update();
     }
 
-    public String computeId(int type, byte[] data) {
-        return rep.getObjectDb().newInserter().idFor(type, data).name();
+    public String computeId(byte[] data) {
+        ObjectInserter inserter = rep.getObjectDatabase().newInserter();
+        return inserter.idFor(Constants.OBJ_BLOB, data).name();
     }
 
     //------------------------------------------------------------< DataStore >
     public byte[] get(String id) throws Exception {
-        return get(id, ANY);
-    }
-
-    public byte[] get(String id, int typeHint) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        return rep.getObjectDb().newReader().open(ObjectId.fromString(id), typeHint).getBytes();
+        return rep.getObjectDatabase().newReader().open(ObjectId.fromString(id), Constants.OBJ_BLOB).getBytes();
     }
 
-    public String put(int type, byte[] data) throws Exception {
+    public String put(byte[] data) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        if (type < 0 || type >= TYPE_NAMES.length) {
-            throw new IllegalArgumentException("invalid type");
-        }
-        ObjectInserter inserter = rep.getObjectDb().newInserter();
+        ObjectInserter inserter = rep.getObjectDatabase().newInserter();
         ObjectId id;
         try {
-            id = inserter.insert(type, data);
+            id = inserter.insert(Constants.OBJ_BLOB, data);
             inserter.flush();
         } finally {
             inserter.release();

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=1094590&r1=1094589&r2=1094590&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
Mon Apr 18 14:28:05 2011
@@ -67,9 +67,10 @@ public class MutableCommit {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         DataOutputStream out = new DataOutputStream(baos);
         try {
+            out.write(Constants.COMMIT);
             out.writeUTF(rootNodeId);
             out.writeLong(commitTS);
-            out.write(parentIds.size());
+            out.writeInt(parentIds.size());
             for (String commitId : parentIds) {
                 out.writeUTF(commitId);
             }

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=1094590&r1=1094589&r2=1094590&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
Mon Apr 18 14:28:05 2011
@@ -71,12 +71,13 @@ public class MutableNode {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         DataOutputStream out = new DataOutputStream(baos);
         try {
-            out.write(properties.size());
+            out.write(Constants.NODE);
+            out.writeInt(properties.size());
             for (Map.Entry<String, String> entry : properties.entrySet()) {
                 out.writeUTF(entry.getKey());
                 out.writeUTF(entry.getValue());
             }
-            out.write(childEntries.size());
+            out.writeInt(childEntries.size());
             for (Map.Entry<String, String> entry : childEntries.entrySet()) {
                 out.writeUTF(entry.getKey());
                 out.writeUTF(entry.getValue());

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=1094590&r1=1094589&r2=1094590&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
Mon Apr 18 14:28:05 2011
@@ -60,6 +60,9 @@ public class Node extends StoredObject {
     public static Node fromBytes(String id, byte[] data) throws Exception {
         ByteArrayInputStream bais = new ByteArrayInputStream(data);
         DataInputStream in = new DataInputStream(bais);
+        if (in.read() != Constants.NODE) {
+            throw new Exception("unknown data format");
+        }
         int count = in.readInt();
         Map<String, String> props = new HashMap<String, String>(count);
         while (count-- > 0) {

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=1094590&r1=1094589&r2=1094590&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
Mon Apr 18 14:28:05 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.mk.store;
 
-import org.apache.jackrabbit.mk.store.git.GitStore;
-
 import java.io.File;
 
 /**
@@ -43,11 +41,11 @@ public class ObjectStore implements Cons
         // make sure we've got a HEAD commit
         String head = store.getHeadCommitId();
         if (head == null) {
-            String rootNodeId = store.put(NODE, new MutableNode(null).toBytes());
+            String rootNodeId = store.put(new MutableNode(null).toBytes());
             MutableCommit initialCommit = new MutableCommit();
             initialCommit.setCommitTS(System.currentTimeMillis());
             initialCommit.setRootNodeId(rootNodeId);
-            store.setHeadCommitId(store.put(COMMIT, initialCommit.toBytes()));
+            store.setHeadCommitId(store.put(initialCommit.toBytes()));
         }
 
         initialized = true;
@@ -67,7 +65,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        byte[] data = store.get(id, NODE);
+        byte[] data = store.get(id);
         return Node.fromBytes(id, data);
     }
 
@@ -76,7 +74,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        return store.put(NODE, node.toBytes());
+        return store.put(node.toBytes());
     }
 
     public Commit getCommit(String id) throws Exception {
@@ -84,7 +82,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        byte[] data = store.get(id, COMMIT);
+        byte[] data = store.get(id);
         return Commit.fromBytes(id, data);
     }
 
@@ -93,7 +91,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        return store.put(COMMIT, commit.toBytes());
+        return store.put(commit.toBytes());
     }
 
     public Commit getHeadCommit() throws Exception {
@@ -112,11 +110,11 @@ public class ObjectStore implements Cons
         store.setHeadCommitId(commitId);
     }
 
-    public String computeId(int type, byte[] data) {
+    public String computeId(byte[] data) {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
 
-        return store.computeId(type, data);
+        return store.computeId(data);
     }
 }



Mime
View raw message