jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1161434 [2/3] - in /jackrabbit/sandbox/microkernel: ./ src/main/java/org/apache/jackrabbit/mk/ src/main/java/org/apache/jackrabbit/mk/api/ src/main/java/org/apache/jackrabbit/mk/blobs/ src/main/java/org/apache/jackrabbit/mk/datastore/ src/...
Date Thu, 25 Aug 2011 08:18:59 GMT
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=1161434&r1=1161433&r2=1161434&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 Thu Aug 25 08:18:57 2011
@@ -16,24 +16,25 @@
  */
 package org.apache.jackrabbit.mk.mem;
 
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.SortedMap;
-import java.util.TreeMap;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
-import org.apache.jackrabbit.mk.datastore.FileStore;
-import org.apache.jackrabbit.mk.datastore.MemoryStore;
-import org.apache.jackrabbit.mk.datastore.Store;
+import org.apache.jackrabbit.mk.blobs.AbstractBlobStore;
+import org.apache.jackrabbit.mk.blobs.FileBlobStore;
+import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.util.CommitGate;
 import org.apache.jackrabbit.mk.util.NonDescendingClock;
 import org.apache.jackrabbit.mk.util.PathUtils;
 
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
 /**
  * An in-memory implementation.
  * Useful for testing.
@@ -42,7 +43,7 @@ public class MemoryKernelImpl implements
 
     private static final HashMap<String, MemoryKernelImpl> INSTANCES = new HashMap<String, MemoryKernelImpl>();
 
-    private Store ds;
+    private AbstractBlobStore ds;
     private long headRevId;
     private TreeMap<Long, Revision> revisions;
     private ArrayList<Revision> revisionList;
@@ -62,11 +63,10 @@ public class MemoryKernelImpl implements
     private MemoryKernelImpl(String name) {
         if (name.startsWith("fs:")) {
             String dir = name.substring("fs:".length());
-            FileStore s = new FileStore();
-            s.setDirectory(dir);
+            FileBlobStore s = new FileBlobStore(dir);
             ds = s;
         } else {
-            ds = new MemoryStore();
+            ds = new MemoryBlobStore();
         }
         init();
     }
@@ -119,121 +119,121 @@ public class MemoryKernelImpl implements
             }
             String path;
             switch (r) {
-            case '+':
-                path = t.readString();
-                w.append("+ ").key(PathUtils.concat(rootPath, path));
-                t.read(':');
-                t.read('{');
-                NodeImpl n = NodeImpl.parse(t, headRevId);
-                headRoot = headRoot.cloneAndAddChildNode(PathUtils.concat(fromRoot, path), false, null, n, headRevId);
-                w.append(n.toString()).appendWhitespace("\n");
-                break;
-            case '-':
-                path = t.readString();
-                w.append("- ").key(PathUtils.concat(rootPath, path));
-                headRoot = headRoot.cloneAndRemoveChildNode(PathUtils.concat(fromRoot, path), headRevId);
-                w.appendWhitespace("\n");
-                break;
-            case '^':
-                path = t.readString();
-                t.read(':');
-                String value;
-                if (t.matches(JsopTokenizer.NULL)) {
-                    value = null;
-                    w.append("^ ").key(PathUtils.concat(rootPath, path));
-                    w.value(null);
-                } else {
-                    value = t.readRawValue().trim();
-                    String nodeName = PathUtils.concat(fromRoot, PathUtils.getParentPath(path));
-                    String propertyName = PathUtils.getName(path);
-                    if (headRoot.getNode(nodeName).hasProperty(propertyName)) {
+                case '+':
+                    path = t.readString();
+                    w.append("+ ").key(PathUtils.concat(rootPath, path));
+                    t.read(':');
+                    t.read('{');
+                    NodeImpl n = NodeImpl.parse(t, headRevId);
+                    headRoot = headRoot.cloneAndAddChildNode(PathUtils.concat(fromRoot, path), false, null, n, headRevId);
+                    w.append(n.toString()).appendWhitespace("\n");
+                    break;
+                case '-':
+                    path = t.readString();
+                    w.append("- ").key(PathUtils.concat(rootPath, path));
+                    headRoot = headRoot.cloneAndRemoveChildNode(PathUtils.concat(fromRoot, path), headRevId);
+                    w.appendWhitespace("\n");
+                    break;
+                case '^':
+                    path = t.readString();
+                    t.read(':');
+                    String value;
+                    if (t.matches(JsopTokenizer.NULL)) {
+                        value = null;
                         w.append("^ ").key(PathUtils.concat(rootPath, path));
+                        w.value(null);
                     } else {
-                        w.append("+ ").key(PathUtils.concat(rootPath, path));
+                        value = t.readRawValue().trim();
+                        String nodeName = PathUtils.concat(fromRoot, PathUtils.getParentPath(path));
+                        String propertyName = PathUtils.getName(path);
+                        if (headRoot.getNode(nodeName).hasProperty(propertyName)) {
+                            w.append("^ ").key(PathUtils.concat(rootPath, path));
+                        } else {
+                            w.append("+ ").key(PathUtils.concat(rootPath, path));
+                        }
+                        w.append(value);
                     }
-                    w.append(value);
-                }
-                headRoot = headRoot.cloneAndSetProperty(PathUtils.concat(fromRoot, path), value, headRevId);
-                w.appendWhitespace("\n");
-                break;
-            case '>':
-                path = t.readString();
-                String from = PathUtils.concat(fromRoot, path);
-                String name = PathUtils.getName(from);
-                w.append("> ").key(PathUtils.concat(rootPath, from));
-                t.read(':');
-                String position, target;
-                boolean rename;
-                String to;
-                if (t.matches('{')) {
-                    rename = false;
-                    position = t.readString();
+                    headRoot = headRoot.cloneAndSetProperty(PathUtils.concat(fromRoot, path), value, headRevId);
+                    w.appendWhitespace("\n");
+                    break;
+                case '>':
+                    path = t.readString();
+                    String from = PathUtils.concat(fromRoot, path);
+                    String name = PathUtils.getName(from);
+                    w.append("> ").key(PathUtils.concat(rootPath, from));
                     t.read(':');
-                    target = t.readString();
-                    t.read('}');
-                    w.object().key(position);
-                    if (PathUtils.isAbsolute(target)) {
-                        w.value(target);
+                    String position, target;
+                    boolean rename;
+                    String to;
+                    if (t.matches('{')) {
+                        rename = false;
+                        position = t.readString();
+                        t.read(':');
+                        target = t.readString();
+                        t.read('}');
+                        w.object().key(position);
+                        if (PathUtils.isAbsolute(target)) {
+                            w.value(target);
+                        } else {
+                            w.value(PathUtils.concat(rootPath, target));
+                        }
+                        w.endObject();
+                    } else {
+                        rename = true;
+                        position = null;
+                        target = t.readString();
+                        if (PathUtils.isAbsolute(target)) {
+                            w.value(target);
+                        } else {
+                            w.value(PathUtils.concat(rootPath, target));
+                        }
+                    }
+                    w.appendWhitespace("\n");
+                    boolean before = false;
+                    if ("last".equals(position)) {
+                        target = PathUtils.concat(target, name);
+                        position = null;
+                    } else if ("first".equals(position)) {
+                        target = PathUtils.concat(target, name);
+                        position = null;
+                        before = true;
+                    } else if ("before".equals(position)) {
+                        position = PathUtils.getName(target);
+                        target = PathUtils.getParentPath(target);
+                        target = PathUtils.concat(target, name);
+                        before = true;
+                    } else if ("after".equals(position)) {
+                        position = PathUtils.getName(target);
+                        target = PathUtils.getParentPath(target);
+                        target = PathUtils.concat(target, name);
+                    } else if (position == null) {
+                        // move
                     } else {
-                        w.value(PathUtils.concat(rootPath, target));
+                        throw new AssertionError("position: " + position);
                     }
-                    w.endObject();
-                } else {
-                    rename = true;
-                    position = null;
-                    target = t.readString();
                     if (PathUtils.isAbsolute(target)) {
-                        w.value(target);
+                        to = PathUtils.relativize("/", target);
                     } else {
-                        w.value(PathUtils.concat(rootPath, target));
+                        to = PathUtils.concat(fromRoot, target);
                     }
-                }
-                w.appendWhitespace("\n");
-                boolean before = false;
-                if ("last".equals(position)) {
-                    target = PathUtils.concat(target, name);
-                    position = null;
-                } else if ("first".equals(position)) {
-                    target = PathUtils.concat(target, name);
-                    position = null;
-                    before = true;
-                } else if ("before".equals(position)) {
-                    position = PathUtils.getName(target);
-                    target = PathUtils.getParentPath(target);
-                    target = PathUtils.concat(target, name);
-                    before = true;
-                } else if ("after".equals(position)) {
-                    position = PathUtils.getName(target);
-                    target = PathUtils.getParentPath(target);
-                    target = PathUtils.concat(target, name);
-                } else if (position == null) {
-                    // move
-                } else {
-                    throw new AssertionError("position: " + position);
-                }
-                if (PathUtils.isAbsolute(target)) {
-                    to = PathUtils.relativize("/", target);
-                } else {
-                    to = PathUtils.concat(fromRoot, target);
-                }
-                boolean inPlaceRename = false;
-                if (rename) {
-                    if (PathUtils.getParentPath(from).equals(PathUtils.getParentPath(to))) {
-                        inPlaceRename = true;
-                        position = PathUtils.getName(from);
+                    boolean inPlaceRename = false;
+                    if (rename) {
+                        if (PathUtils.getParentPath(from).equals(PathUtils.getParentPath(to))) {
+                            inPlaceRename = true;
+                            position = PathUtils.getName(from);
+                        }
                     }
-                }
-                NodeImpl node = headRoot.getNode(from);
-                if (!inPlaceRename) {
-                    headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
-                }
-                headRoot = headRoot.cloneAndAddChildNode(to, before, position, node, headRevId);
-                if (inPlaceRename) {
-                    headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
-                }
-                break;
-            default:
-                throw new AssertionError("token: " + (char) t.getTokenType());
+                    NodeImpl node = headRoot.getNode(from);
+                    if (!inPlaceRename) {
+                        headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
+                    }
+                    headRoot = headRoot.cloneAndAddChildNode(to, before, position, node, headRevId);
+                    if (inPlaceRename) {
+                        headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
+                    }
+                    break;
+                default:
+                    throw new AssertionError("token: " + (char) t.getTokenType());
             }
         }
         return w.toString();
@@ -258,9 +258,9 @@ public class MemoryKernelImpl implements
         for (int i = index; i < revisionList.size(); i++) {
             Revision rev = revisionList.get(i);
             buff.object().
-                key("id").value(Long.toString(rev.getId())).
-                key("ts").value(rev.getTime()).
-            endObject();
+                    key("id").value(Long.toString(rev.getId())).
+                    key("ts").value(rev.getTime()).
+                    endObject();
         }
         return buff.endArray().toString();
     }
@@ -276,11 +276,11 @@ public class MemoryKernelImpl implements
         SortedMap<Long, Revision> map = revisions.subMap(fromRevId, true, toRevId, true);
         for (Revision rev : map.values()) {
             buff.object().
-                key("id").value(Long.toString(rev.getId())).
-                key("ts").value(rev.getTime()).
-                key("msg").value(rev.getMsg()).
-                key("changes").value(rev.getDiff()).
-            endObject().appendWhitespace("\n");
+                    key("id").value(Long.toString(rev.getId())).
+                    key("ts").value(rev.getTime()).
+                    key("msg").value(rev.getMsg()).
+                    key("changes").value(rev.getDiff()).
+                    endObject().appendWhitespace("\n");
         }
         return buff.endArray().toString();
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java Thu Aug 25 08:18:57 2011
@@ -16,16 +16,16 @@
  */
 package org.apache.jackrabbit.mk.mem;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map.Entry;
-
 import org.apache.jackrabbit.mk.Constants;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.util.PathUtils;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
 public class NodeImpl {
 
     private final long revId;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Blob.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Blob.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Blob.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Blob.java Thu Aug 25 08:18:57 2011
@@ -21,7 +21,7 @@ package org.apache.jackrabbit.mk.store;
  */
 public class Blob extends StoredObject {
 
-     public Blob(String id) {
+    public Blob(String id) {
         super(id);
     }
 }

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=1161434&r1=1161433&r2=1161434&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 Aug 25 08:18:57 2011
@@ -16,9 +16,10 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.util.IOUtils;
+
 import java.io.DataInputStream;
 import java.io.InputStream;
-import org.apache.jackrabbit.mk.util.IOUtils;
 
 /**
  * Immutable Commit object...

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=1161434&r1=1161433&r2=1161434&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 Aug 25 08:18:57 2011
@@ -36,7 +36,7 @@ public class CommitBuilder {
     final String msg;
 
     final Repository rep;
-    final ObjectStore store;
+    final PersistenceManager store;
 
     final Map<String, MutableNode> staged;
     // change log
@@ -46,7 +46,7 @@ public class CommitBuilder {
         this.baseRevId = baseRevId;
         this.msg = msg;
         this.rep = rep;
-        store = rep.getStore();
+        store = rep.getPersistenceManager();
         staged = new HashMap<String, MutableNode>();
         changeLog = new ArrayList<Change>();
     }
@@ -190,7 +190,7 @@ public class CommitBuilder {
             if (!currentHead.equals(baseRevId)) {
                 Node baseRoot = rep.getNode(baseRevId, "/");
                 Node theirRoot = rep.getNode(currentHead, "/");
-                Node ourRoot = rep.getStore().getNode(rootNodeId);
+                Node ourRoot = rep.getPersistenceManager().getNode(rootNodeId);
 
                 rootNodeId = mergeTree(baseRoot, ourRoot, theirRoot);
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Constants.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Constants.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Constants.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Constants.java Thu Aug 25 08:18:57 2011
@@ -21,7 +21,7 @@ package org.apache.jackrabbit.mk.store;
  */
 public interface Constants {
 
-    static String[] TYPE_NAMES = { "node", "nodetree", "fatnode", "fatnodepart", "commit", "blob" };
+    static String[] TYPE_NAMES = {"node", "nodetree", "fatnode", "fatnodepart", "commit", "blob"};
 
     static int ANY = -1;
     static int NODE = 0;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java Thu Aug 25 08:18:57 2011
@@ -16,6 +16,11 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mk.blobs.DbBlobStore;
+import org.apache.jackrabbit.mk.util.StringUtils;
+import org.h2.jdbcx.JdbcConnectionPool;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -27,17 +32,14 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
-import org.apache.jackrabbit.mk.datastore.DbStore;
-import org.apache.jackrabbit.mk.util.StringUtils;
-import org.h2.jdbcx.JdbcConnectionPool;
 
 /**
  *
  */
-public class H2RevisionStore extends SimpleRevisionStore {
+public class H2RevisionStore extends SimpleRevisionStore implements BlobStore {
 
     private JdbcConnectionPool cp;
-    private DbStore blobStore;
+    private DbBlobStore blobStore;
 
     public H2RevisionStore() throws Exception {
         initialized = false;
@@ -66,7 +68,7 @@ public class H2RevisionStore extends Sim
             stmt.execute("create table if not exists REVS (ID binary primary key, DATA binary)");
             stmt.execute("create table if not exists head(id varchar) as select ''");
             stmt.execute("create sequence if not exists datastore_id");
-            blobStore = new DbStore();
+            blobStore = new DbBlobStore();
             blobStore.setConnectionPool(cp);
         } finally {
             con.close();
@@ -84,7 +86,7 @@ public class H2RevisionStore extends Sim
         initialized = false;
     }
 
-    public String getHeadRevision() throws Exception {
+    public String getHeadId() throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
@@ -102,7 +104,7 @@ public class H2RevisionStore extends Sim
         }
     }
 
-    public void setHeadRevision(String revId) throws Exception {
+    public void setHeadId(String revId) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
@@ -169,7 +171,7 @@ public class H2RevisionStore extends Sim
         try {
             PreparedStatement stmt = con
                     .prepareStatement(
-                    "insert into REVS (ID, DATA) select ?, ? where not exists (select 1 from revs where ID = ?)");
+                            "insert into REVS (ID, DATA) select ?, ? where not exists (select 1 from revs where ID = ?)");
             try {
                 stmt.setBytes(1, rawId);
                 stmt.setBytes(2, baos.toByteArray());
@@ -184,17 +186,16 @@ public class H2RevisionStore extends Sim
         return id;
     }
 
-    @Override
+    //------------------------------------------------------------< BlobStore >
+
     public String writeBlob(InputStream in) throws Exception {
         return blobStore.writeBlob(in);
     }
 
-    @Override
     public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws Exception {
         return blobStore.readBlob(blobId, pos, buff, off, length);
     }
 
-    @Override
     public long getBlobLength(String blobId) throws IOException {
         return blobStore.getBlobLength(blobId);
     }

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=1161434&r1=1161433&r2=1161434&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 Aug 25 08:18:57 2011
@@ -16,12 +16,13 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.util.IOUtils;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import org.apache.jackrabbit.mk.util.IOUtils;
 
 /**
  *

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=1161434&r1=1161433&r2=1161434&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 Aug 25 08:18:57 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.util.IOUtils;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -23,7 +25,6 @@ import java.io.InputStream;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import org.apache.jackrabbit.mk.util.IOUtils;
 
 /**
  *

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=1161434&r1=1161433&r2=1161434&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 Thu Aug 25 08:18:57 2011
@@ -16,13 +16,14 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.util.IOUtils;
+
 import java.io.DataInputStream;
 import java.io.InputStream;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import org.apache.jackrabbit.mk.util.IOUtils;
 
 /**
  * Immutable Node object...
@@ -34,8 +35,8 @@ public class Node extends StoredObject {
     final LinkedHashMap<String, String> childEntries;
 
     protected Node(String id,
-                Map<String, String> properties,
-                LinkedHashMap<String, String> childEntries) {
+                   Map<String, String> properties,
+                   LinkedHashMap<String, String> childEntries) {
         super(id);
         this.properties = properties;
         this.childEntries = childEntries;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java Thu Aug 25 08:18:57 2011
@@ -197,27 +197,26 @@ public class NodeDelta implements NodeDi
 
     //--------------------------------------------------------< inner classes >
 
-   public static class Conflict {
+    public static class Conflict {
 
-       final ConflictType type;
-       final String name;
+        final ConflictType type;
+        final String name;
 
-       /**
-        *
-        * @param type conflict type
-        * @param name name of conflicting property or child node
-        */
-       Conflict(ConflictType type, String name) {
-           this.type = type;
-           this.name = name;
-       }
-
-       public ConflictType getType() {
-           return type;
-       }
-
-       public String getName() {
-           return name;
-       }
-   }
+        /**
+         * @param type conflict type
+         * @param name name of conflicting property or child node
+         */
+        Conflict(ConflictType type, String name) {
+            this.type = type;
+            this.name = name;
+        }
+
+        public ConflictType getType() {
+            return type;
+        }
+
+        public String getName() {
+            return name;
+        }
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeUtils.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeUtils.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeUtils.java Thu Aug 25 08:18:57 2011
@@ -45,7 +45,7 @@ public class NodeUtils {
     }
 
     public static void diff(String path, Node node1, Node node2,
-                            boolean deep, ObjectStore store,
+                            boolean deep, PersistenceManager store,
                             NodeDiffHandler handler) throws Exception {
 
         // compare properties

Copied: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java (from r1159622, 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/PersistenceManager.java?p2=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java&p1=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java&r1=1159622&r2=1161434&rev=1161434&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/PersistenceManager.java Thu Aug 25 08:18:57 2011
@@ -16,36 +16,37 @@
  */
 package org.apache.jackrabbit.mk.store;
 
-import java.io.File;
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+
 import java.io.InputStream;
 import java.util.concurrent.locks.ReentrantLock;
 
 /**
  *
  */
-public class ObjectStore implements Constants {
+public class PersistenceManager implements Constants {
 
     boolean initialized;
     ReentrantLock headLock = new ReentrantLock();
-    RevisionStore store;
+    RevisionStore revStore;
+    BlobStore blobStore;
 
-    public void initialize(File homeDir) throws Exception {
+    public void initialize(RevisionStore revs, BlobStore blobs) throws Exception {
         if (initialized) {
             throw new IllegalStateException("already initialized");
         }
 
-        //store = new SimpleRevisionStore();
-        store = new H2RevisionStore();
-        store.initialize(homeDir);
+        revStore = revs;
+        blobStore = blobs;
 
         // make sure we've got a HEAD commit
-        String head = store.getHeadRevision();
+        String head = revStore.getHeadId();
         if (head == null || head.length() == 0) {
-            String rootNodeId = store.put(new MutableNode().toBytes());
+            String rootNodeId = revStore.put(new MutableNode().toBytes());
             MutableCommit initialCommit = new MutableCommit();
             initialCommit.setCommitTS(System.currentTimeMillis());
             initialCommit.setRootNodeId(rootNodeId);
-            store.setHeadRevision(store.put(initialCommit.toBytes()));
+            revStore.setHeadId(revStore.put(initialCommit.toBytes()));
         }
 
         initialized = true;
@@ -55,8 +56,8 @@ public class ObjectStore implements Cons
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
-        store.close();
-        store = null;
+        revStore.close();
+        revStore = null;
         initialized = false;
     }
 
@@ -65,7 +66,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        return Node.fromBytes(id, store.get(id));
+        return Node.fromBytes(id, revStore.get(id));
     }
 
     public String putNode(MutableNode node) throws Exception {
@@ -73,7 +74,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        return store.put(node.toBytes());
+        return revStore.put(node.toBytes());
     }
 
     public Commit getCommit(String id) throws Exception {
@@ -81,7 +82,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        return Commit.fromBytes(id, store.get(id));
+        return Commit.fromBytes(id, revStore.get(id));
     }
 
     public String putCommit(MutableCommit commit) throws Exception {
@@ -89,7 +90,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        return store.put(commit.toBytes());
+        return revStore.put(commit.toBytes());
     }
 
     public Commit getHeadCommit() throws Exception {
@@ -97,7 +98,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        return getCommit(store.getHeadRevision());
+        return getCommit(revStore.getHeadId());
     }
 
     public void setHeadCommitId(String commitId) throws Exception {
@@ -105,7 +106,7 @@ public class ObjectStore implements Cons
             throw new IllegalStateException("not initialized");
         }
 
-        store.setHeadRevision(commitId);
+        revStore.setHeadId(commitId);
     }
 
     public void lockHead() {
@@ -117,15 +118,15 @@ public class ObjectStore implements Cons
     }
 
     public String writeBlob(InputStream in) throws Exception {
-        return store.writeBlob(in);
+        return blobStore.writeBlob(in);
     }
 
     public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws Exception {
-        return store.readBlob(blobId, pos, buff, off, length);
+        return blobStore.readBlob(blobId, pos, buff, off, length);
     }
 
     public long getBlobLength(String blobId) throws Exception {
-        return store.getBlobLength(blobId);
+        return blobStore.getBlobLength(blobId);
     }
 
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java Thu Aug 25 08:18:57 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.util.IOUtils;
+
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
@@ -23,7 +25,6 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.jackrabbit.mk.util.IOUtils;
 
 /**
  *

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionStore.java Thu Aug 25 08:18:57 2011
@@ -16,21 +16,26 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import java.io.File;
 import java.io.InputStream;
 
 /**
- *
+ * <code>RevisionStore</code> represents a simple, <i>content-addressable</i>
+ * loose object store.
  */
-public interface RevisionStore extends DataStore {
+public interface RevisionStore {
 
-    String /* id */ getHeadRevision() throws Exception;
+    void initialize(File homeDir) throws Exception;
 
-    void setHeadRevision(String revId) throws Exception;
+    void close();
 
-    String writeBlob(InputStream in) throws Exception;
+    InputStream get(String id) throws Exception;
 
-    int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws Exception;
+    String /* id */ put(InputStream in) throws Exception;
 
-    long getBlobLength(String blobId) throws Exception;
+    String computeId(InputStream in) throws Exception;
 
+    String /* id */ getHeadId() throws Exception;
+
+    void setHeadId(String revId) throws Exception;
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java Thu Aug 25 08:18:57 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.util.StringUtils;
+
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -24,7 +26,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.security.DigestOutputStream;
 import java.security.MessageDigest;
-import org.apache.jackrabbit.mk.util.StringUtils;
 
 /**
  *
@@ -45,12 +46,12 @@ public class SimpleRevisionStore impleme
         }
 
         homeDir = new File(homeDir, ".mk");
-        if (! homeDir.exists()) {
+        if (!homeDir.exists()) {
             homeDir.mkdirs();
         }
         headRev = new PersistentId(new File(homeDir, "HEAD"));
         dataDir = new File(homeDir, "data");
-        if (! dataDir.exists()) {
+        if (!dataDir.exists()) {
             dataDir.mkdir();
         }
 
@@ -65,7 +66,7 @@ public class SimpleRevisionStore impleme
         initialized = false;
     }
 
-    public String getHeadRevision() throws Exception {
+    public String getHeadId() throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
@@ -73,7 +74,7 @@ public class SimpleRevisionStore impleme
         return headRev.get();
     }
 
-    public void setHeadRevision(String revId) throws Exception {
+    public void setHeadId(String revId) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
         }
@@ -163,17 +164,4 @@ public class SimpleRevisionStore impleme
         buf.append(id.substring(2));
         return new File(dataDir, buf.toString());
     }
-
-    public String writeBlob(InputStream in) throws Exception {
-        throw new UnsupportedOperationException();
-    }
-
-    public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws Exception {
-        throw new UnsupportedOperationException();
-    }
-
-    public long getBlobLength(String blobId) throws Exception {
-        throw new UnsupportedOperationException();
-    }
-
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/CommitGate.java Thu Aug 25 08:18:57 2011
@@ -33,7 +33,7 @@ public class CommitGate {
      * with the old head before the requested timeout.
      *
      * @param lastHead the last head
-     * @param millis the maximum number of milliseconds to wait (0 means don't wait)
+     * @param millis   the maximum number of milliseconds to wait (0 means don't wait)
      * @return the new head (or old head, if no new commit occurred)
      * @throws InterruptedException if the thread was interrupted
      */

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java Thu Aug 25 08:18:57 2011
@@ -31,10 +31,10 @@ public class IOUtils {
      * until the maximum number of bytes have been read or until the end of
      * file.
      *
-     * @param in the input stream
+     * @param in     the input stream
      * @param buffer the output buffer
-     * @param off the offset in the buffer
-     * @param max the number of bytes to read at most
+     * @param off    the offset in the buffer
+     * @param max    the number of bytes to read at most
      * @return the number of bytes read, 0 meaning EOF
      */
     public static int readFully(InputStream in, byte[] buffer, int off, int max) throws IOException {
@@ -55,11 +55,11 @@ public class IOUtils {
     /**
      * Skip a number of bytes in an input stream.
      *
-     * @param in the input stream
+     * @param in   the input stream
      * @param skip the number of bytes to skip
      * @throws EOFException if the end of file has been reached before all bytes
-     *             could be skipped
-     * @throws IOException if an IO exception occurred while skipping
+     *                      could be skipped
+     * @throws IOException  if an IO exception occurred while skipping
      */
     public static void skipFully(InputStream in, long skip) throws IOException {
         while (skip > 0) {
@@ -76,7 +76,7 @@ public class IOUtils {
      * UTF-8 encoded string.
      *
      * @param out the data output stream
-     * @param s the string (maximum length about 2 GB)
+     * @param s   the string (maximum length about 2 GB)
      */
     public static void writeString(OutputStream out, String s) throws IOException {
         byte[] data = s.getBytes("UTF-8");
@@ -94,7 +94,7 @@ public class IOUtils {
     public static String readString(InputStream in) throws IOException {
         int len = readVarInt(in);
         byte[] data = new byte[len];
-        for (int pos = 0; pos < len;) {
+        for (int pos = 0; pos < len; ) {
             int l = in.read(data, pos, data.length - pos);
             if (l < 0) {
                 throw new EOFException();
@@ -109,7 +109,7 @@ public class IOUtils {
      * Negative values need 5 bytes.
      *
      * @param out the output stream
-     * @param x the value
+     * @param x   the value
      */
     public static void writeVarInt(OutputStream out, int x) throws IOException {
         while ((x & ~0x7f) != 0) {
@@ -131,7 +131,7 @@ public class IOUtils {
             return x;
         }
         x &= 0x7f;
-        for (int s = 7;; s += 7) {
+        for (int s = 7; ; s += 7) {
             int b = (byte) in.read();
             x |= (b & 0x7f) << s;
             if (b >= 0) {
@@ -145,7 +145,7 @@ public class IOUtils {
      * Negative values need 10 bytes.
      *
      * @param out the output stream
-     * @param x the value
+     * @param x   the value
      */
     public static void writeVarLong(OutputStream out, long x) throws IOException {
         while ((x & ~0x7f) != 0) {
@@ -167,7 +167,7 @@ public class IOUtils {
             return x;
         }
         x &= 0x7f;
-        for (int s = 7;; s += 7) {
+        for (int s = 7; ; s += 7) {
             long b = (byte) in.read();
             x |= (b & 0x7f) << s;
             if (b >= 0) {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/MicroKernelInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/MicroKernelInputStream.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/MicroKernelInputStream.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/MicroKernelInputStream.java Thu Aug 25 08:18:57 2011
@@ -16,13 +16,14 @@
  */
 package org.apache.jackrabbit.mk.util;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
 import java.io.IOException;
 import java.io.InputStream;
-import org.apache.jackrabbit.mk.api.MicroKernel;
 
 /**
  * An input stream to simplify reading a blob from the micro kernel.
- * See also StoreInputStream.
+ * See also BlobStoreInputStream.
  */
 public class MicroKernelInputStream extends InputStream {
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java Thu Aug 25 08:18:57 2011
@@ -20,7 +20,7 @@ import java.util.ArrayList;
 
 /**
  * Utility methods to parse a JCR path.
- * <p>
+ * <p/>
  * Each method validates the input, except if the system property
  * {packageName}.SKIP_VALIDATION is set, in which case only minimal validation
  * takes place within this function, so when the parameter is an illegal path,
@@ -159,7 +159,7 @@ public class PathUtils {
             path = path.substring(1);
         }
         ArrayList<String> list = new ArrayList<String>();
-        while(true) {
+        while (true) {
             int index = path.indexOf('/');
             if (index < 0) {
                 list.add(path);
@@ -177,7 +177,7 @@ public class PathUtils {
     /**
      * Concatenate path elements.
      *
-     * @param parentPath the parent path
+     * @param parentPath    the parent path
      * @param relativePaths the relative path elements to add
      * @return the concatenated path
      */
@@ -188,7 +188,7 @@ public class PathUtils {
         StringBuilder buff = new StringBuilder(parentLen + size * 5);
         buff.append(parentPath);
         boolean needSlash = parentLen > 0 && !denotesRootPath(parentPath);
-        for (int i=0; i < size; i++) {
+        for (int i = 0; i < size; i++) {
             String s = relativePaths[i];
             assertValid(s);
             if (isAbsolutePath(s)) {
@@ -208,7 +208,7 @@ public class PathUtils {
     /**
      * Concatenate path elements.
      *
-     * @param parentPath the parent path
+     * @param parentPath   the parent path
      * @param relativePath the relative path to add
      * @return the concatenated path
      */
@@ -237,7 +237,7 @@ public class PathUtils {
      * holds.
      *
      * @param parentPath parent pth
-     * @param path path to relativize
+     * @param path       path to relativize
      * @return relativized path
      */
     public static String relativize(String parentPath, String path) {
@@ -249,8 +249,8 @@ public class PathUtils {
         }
 
         String prefix = denotesRootPath(parentPath)
-            ? parentPath
-            : parentPath + '/';
+                ? parentPath
+                : parentPath + '/';
 
         if (path.startsWith(prefix)) {
             return path.substring(prefix.length());
@@ -261,7 +261,7 @@ public class PathUtils {
     /**
      * Get the index of the next slash.
      *
-     * @param path the path
+     * @param path  the path
      * @param index the starting index
      * @return the index of the next slash (possibly the starting index), or
      *         -1 if not found

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java Thu Aug 25 08:18:57 2011
@@ -38,8 +38,8 @@ public class SmallLRUCache<K, V> extends
     /**
      * Create a new object with all elements of the given collection.
      *
-     * @param <K> the key type
-     * @param <V> the value type
+     * @param <K>  the key type
+     * @param <V>  the value type
      * @param size the number of elements
      * @return the object
      */

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java (original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/StringUtils.java Thu Aug 25 08:18:57 2011
@@ -27,7 +27,6 @@ public class StringUtils {
      * Convert a byte array to a hex encoded string.
      *
      * @param value the byte array
-     * @param len the number of bytes to encode
      * @return the hex encoded string
      */
     public static String convertBytesToHex(byte[] value) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java Thu Aug 25 08:18:57 2011
@@ -16,25 +16,30 @@
  */
 package org.apache.jackrabbit.mk;
 
-import java.util.Random;
 import junit.framework.TestCase;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 
+import java.util.Random;
+
 public class ConcurrentWriteTest extends TestCase {
 
-    // private static final String URL = "fs:{homeDir};clean";
-    private static final String URL = "mem:";
+    private static final String URL = "fs:{homeDir}/target;clean";
+    //private static final String URL = "mem:";
 
-    private static final int NUM_THREADS = 10;
+    private static final int NUM_THREADS = 20;
     private static final int NUM_CHILDNODES = 1000;
 
     private MicroKernel mk;
 
+    private static String TEST_PATH = "/" + ConcurrentWriteTest.class.getName();
+
     public void setUp() throws Exception {
         mk = MicroKernelFactory.getInstance(URL);
+        mk.commit("/", "+ \"" + TEST_PATH.substring(1) + "\": {\"jcr:primaryType\":\"nt:unstructured\"}", mk.getHeadRevision(), null);
     }
 
     public void tearDown() throws InterruptedException {
+        mk.commit("/", "- \"" + TEST_PATH.substring(1) + "\"", mk.getHeadRevision(), null);
         mk.dispose();
     }
 
@@ -46,22 +51,15 @@ public class ConcurrentWriteTest extends
         Profiler prof = new Profiler();
         prof.depth = 8;
         prof.interval = 1;
-	// prof.startCollecting();
+        // prof.startCollecting();
 
-        String head = mk.getHeadRevision();
-        if (mk.nodeExists("/test", head)) {
-            head = mk.commit("/", "-\"test\"", head, null);
-        }
-        head = mk.commit("/", "+\"test\" : {\"jcr:primaryType\":\"nt:unstructured\"}", head, null);
-
-        String oldHead = head;
-        System.out.println("new HEAD: " + oldHead);
+        String oldHead = mk.getHeadRevision();
 
         long t0 = System.currentTimeMillis();
 
         TestThread[] threads = new TestThread[NUM_THREADS];
         for (int i = 0; i < threads.length; i++) {
-            TestThread thread = new TestThread(head, "t" + i);
+            TestThread thread = new TestThread(oldHead, "t" + i);
             thread.start();
             threads[i] = thread;
         }
@@ -76,7 +74,7 @@ public class ConcurrentWriteTest extends
 
         System.out.println("duration: " + (t1 - t0) + "ms");
 
-        head = mk.getHeadRevision();
+        String head = mk.getHeadRevision();
         String json = mk.getNodes("/", head, Integer.MAX_VALUE, 0, -1);
         System.out.println("new HEAD: " + head);
         //System.out.println(json);
@@ -120,7 +118,7 @@ public class ConcurrentWriteTest extends
                 }
             }
             sb.append('}');
-            revId = mk.commit("/test", sb.toString(), revId, null);
+            revId = mk.commit(TEST_PATH, sb.toString(), revId, null);
         }
     }
 }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/HelloWorld.java Thu Aug 25 08:18:57 2011
@@ -16,21 +16,22 @@
  */
 package org.apache.jackrabbit.mk;
 
-import java.util.ArrayList;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
+import java.util.ArrayList;
+
 /**
  * A simple hello world app.
  */
 public class HelloWorld {
 
     public static void main(String... args) throws ParseException {
-       // test("mem:");
-       test("fs:{homeDir};clean");
+        // test("mem:");
+        test("fs:{homeDir};clean");
     }
 
     private static void test(String url) throws ParseException {
@@ -57,7 +58,7 @@ public class HelloWorld {
         ArrayList<String> revList = new ArrayList<String>();
         JSONParser p = new JSONParser();
         JSONArray a = (JSONArray) p.parse(revs);
-        for (int i=0; i<a.size(); i++) {
+        for (int i = 0; i < a.size(); i++) {
             JSONObject o = (JSONObject) a.get(i);
             revList.add(o.get("id").toString());
         }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/LargeObjectTest.java Thu Aug 25 08:18:57 2011
@@ -29,27 +29,31 @@ public class LargeObjectTest extends Tes
 
     private MicroKernel mk;
 
+    private static String TEST_PATH = "/" + LargeObjectTest.class.getName();
+
     public void setUp() throws Exception {
         mk = MicroKernelFactory.getInstance(URL);
+        mk.commit("/", "+ \"" + TEST_PATH.substring(1) + "\": {}", mk.getHeadRevision(), null);
     }
 
     public void tearDown() throws InterruptedException {
+        mk.commit("/", "- \"" + TEST_PATH.substring(1) + "\"", mk.getHeadRevision(), null);
         mk.dispose();
     }
 
     public void test() {
 
         String head = mk.getHeadRevision();
-        head = mk.commit("/", "+ \"test\": { \"data\": \"Hello World\" }", head, null);
+        head = mk.commit(TEST_PATH, "+ \"test\": { \"data\": \"Hello World\" }", head, null);
 
         String large = new String(new char[100000]).replace((char) 0, 'x');
-        head = mk.commit("/", "^ \"test/data\": \"" + large + "\"", head, null);
+        head = mk.commit(TEST_PATH, "^ \"test/data\": \"" + large + "\"", head, null);
 
-        head = mk.commit("/", "+ \"test2\": { \"" + large + "\": \"Hello World\" }", head, null);
-        head = mk.commit("/", "^ \"test2/" + large + "\": \"" + large + "\"", head, null);
+        head = mk.commit(TEST_PATH, "+ \"test2\": { \"" + large + "\": \"Hello World\" }", head, null);
+        head = mk.commit(TEST_PATH, "^ \"test2/" + large + "\": \"" + large + "\"", head, null);
 
-        head = mk.commit("/", "+ \"" + large + "\": { \"" + large + "\": \"Hello World\" }", head, null);
-        head = mk.commit("/", "^ \"" + large + "/" + large + "\": \"" + large + "\"", head, null);
+        head = mk.commit(TEST_PATH, "+ \"" + large + "\": { \"" + large + "\": \"Hello World\" }", head, null);
+        head = mk.commit(TEST_PATH, "^ \"" + large + "/" + large + "\": \"" + large + "\"", head, null);
 
     }
 

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/Profiler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/Profiler.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/Profiler.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/Profiler.java Thu Aug 25 08:18:57 2011
@@ -38,17 +38,17 @@ public class Profiler implements Runnabl
     String[] ignorePackages = arraySplit("java.", ',', true);
     String[] ignoreThreads = arraySplit(
             "java.lang.Thread.dumpThreads," +
-            "java.lang.Thread.getThreads," +
-            "java.net.PlainSocketImpl.socketAccept," +
-            "java.net.SocketInputStream.socketRead0," +
-            "java.net.SocketOutputStream.socketWrite0," +
-            "java.lang.UNIXProcess.waitForProcessExit," +
-            "java.lang.Object.wait," +
-            "java.lang.Thread.sleep," +
-            "sun.awt.windows.WToolkit.eventLoop," +
-            "sun.misc.Unsafe.park," +
-            "dalvik.system.VMStack.getThreadStackTrace," +
-            "dalvik.system.NativeStart.run"
+                    "java.lang.Thread.getThreads," +
+                    "java.net.PlainSocketImpl.socketAccept," +
+                    "java.net.SocketInputStream.socketRead0," +
+                    "java.net.SocketOutputStream.socketWrite0," +
+                    "java.lang.UNIXProcess.waitForProcessExit," +
+                    "java.lang.Object.wait," +
+                    "java.lang.Thread.sleep," +
+                    "sun.awt.windows.WToolkit.eventLoop," +
+                    "sun.misc.Unsafe.park," +
+                    "dalvik.system.VMStack.getThreadStackTrace," +
+                    "dalvik.system.NativeStart.run"
             , ',', true);
     volatile boolean stop;
     private HashMap<String, Integer> counts = new HashMap<String, Integer>();
@@ -179,7 +179,7 @@ public class Profiler implements Runnabl
             map.put(trace, oldCount + 1);
         }
         while (map.size() > MAX_ELEMENTS) {
-            for (Iterator<Map.Entry<String, Integer>> ei = map.entrySet().iterator(); ei.hasNext();) {
+            for (Iterator<Map.Entry<String, Integer>> ei = map.entrySet().iterator(); ei.hasNext(); ) {
                 Map.Entry<String, Integer> e = ei.next();
                 if (e.getValue() <= minCount) {
                     ei.remove();
@@ -202,10 +202,10 @@ public class Profiler implements Runnabl
         stopCollecting();
         StringBuilder buff = new StringBuilder();
         buff.append("Profiler Results").
-            append(LINE_SEPARATOR).
-            append(LINE_SEPARATOR).
-            append("Package summary:").
-            append(LINE_SEPARATOR);
+                append(LINE_SEPARATOR).
+                append(LINE_SEPARATOR).
+                append("Package summary:").
+                append(LINE_SEPARATOR);
         for (String k : new TreeSet<String>(packages.keySet())) {
             int percent = 100 * packages.get(k) / Math.max(total, 1);
             if (percent >= 5) {
@@ -213,12 +213,12 @@ public class Profiler implements Runnabl
                     buff.append('0');
                 }
                 buff.append(percent).append("%: ").append(k).
-                    append(LINE_SEPARATOR);
+                        append(LINE_SEPARATOR);
             }
         }
         buff.append(LINE_SEPARATOR).
-            append("Top ").append(count).append(" stack trace(s) of ").append(time).
-            append(" ms ").append(LINE_SEPARATOR);
+                append("Top ").append(count).append(" stack trace(s) of ").append(time).
+                append(" ms ").append(LINE_SEPARATOR);
         if (counts.size() == 0) {
             buff.append("(none)");
         }
@@ -228,7 +228,7 @@ public class Profiler implements Runnabl
     }
 
     private static void appendTop(StringBuilder buff, HashMap<String, Integer> map, int count, int total) {
-        for (int x = 0, min = 0;;) {
+        for (int x = 0, min = 0; ; ) {
             int highest = 0;
             Map.Entry<String, Integer> best = null;
             for (Map.Entry<String, Integer> el : map.entrySet()) {
@@ -250,10 +250,10 @@ public class Profiler implements Runnabl
             int c = best.getValue();
             int percent = 100 * c / Math.max(total, 1);
             buff.append(c).append('/').append(total).append(" (").
-                append(percent).
-                append("%):").append(LINE_SEPARATOR).
-                append(best.getKey()).
-                append(LINE_SEPARATOR);
+                    append(percent).
+                    append("%):").append(LINE_SEPARATOR).
+                    append(best.getKey()).
+                    append(LINE_SEPARATOR);
         }
     }
 
@@ -262,9 +262,9 @@ public class Profiler implements Runnabl
      * string will result in a null array, and an empty string in a zero element
      * array.
      *
-     * @param s the string to split
+     * @param s             the string to split
      * @param separatorChar the separator character
-     * @param trim whether each element should be trimmed
+     * @param trim          whether each element should be trimmed
      * @return the array list
      */
     public static String[] arraySplit(String s, char separatorChar, boolean trim) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java?rev=1161434&r1=1159622&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java Thu Aug 25 08:18:57 2011
@@ -14,17 +14,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk.datastore;
+package org.apache.jackrabbit.mk.blobs;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.mk.MicroKernelFactory;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Random;
-import junit.framework.TestCase;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
 
 /**
  * Test the data store using the MicroKernel API.
@@ -60,7 +61,7 @@ public class DataStoreTest extends TestC
     private void doTest(int maxLength, int count) throws IOException {
         String[] s = new String[count * 2];
         Random r = new Random(0);
-        for (int i = 0; i < s.length;) {
+        for (int i = 0; i < s.length; ) {
             int len = count == 1 ? maxLength : r.nextInt(maxLength);
             byte[] data = new byte[len];
             r.nextBytes(data);
@@ -68,7 +69,7 @@ public class DataStoreTest extends TestC
             s[i++] = mk.write(new ByteArrayInputStream(data));
         }
         r.setSeed(0);
-        for (int i = 0; i < s.length;) {
+        for (int i = 0; i < s.length; ) {
             int len = count == 1 ? maxLength : r.nextInt(maxLength);
             byte[] expectedData = new byte[len];
             r.nextBytes(expectedData);

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java?rev=1161434&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java (added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java Thu Aug 25 08:18:57 2011
@@ -0,0 +1,212 @@
+/*
+ * 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.blobs;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.apache.jackrabbit.mk.util.IOUtilsTest;
+import org.h2.jdbcx.JdbcConnectionPool;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Random;
+
+/**
+ * Tests the DbBlobStore implementation.
+ */
+public class DbBlobStoreTest extends TestCase {
+
+    protected AbstractBlobStore store;
+    private Connection sentinel;
+
+    public void setUp() throws Exception {
+        Class.forName("org.h2.Driver");
+        JdbcConnectionPool cp = JdbcConnectionPool.create("jdbc:h2:mem:", "", "");
+        sentinel = cp.getConnection();
+        DbBlobStore blobStore = new DbBlobStore();
+        blobStore.setConnectionPool(cp);
+        blobStore.setBlockSize(128);
+        blobStore.setBlockSizeMin(32);
+        this.store = blobStore;
+    }
+
+    public void tearDown() throws Exception {
+        if (sentinel != null) {
+            sentinel.close();
+        }
+    }
+
+    public void testCombinedIdentifier() throws Exception {
+        String id = store.writeBlob(new ByteArrayInputStream(new byte[2]));
+        assertEquals(2, store.getBlobLength(id));
+        String combinedId = id + id;
+        assertEquals(4, store.getBlobLength(combinedId));
+        doTestRead(new byte[4], 4, combinedId);
+    }
+
+    public void testEmptyIdentifier() throws Exception {
+        byte[] data = new byte[1];
+        assertEquals(-1, store.readBlob("", 0, data, 0, 1));
+        assertEquals(0, store.getBlobLength(""));
+    }
+
+    public void testIllegalIdentifier() throws Exception {
+        byte[] data = new byte[1];
+        try {
+            store.readBlob("ff", 0, data, 0, 1);
+            fail();
+        } catch (IOException e) {
+            // expected
+        }
+        try {
+            store.getBlobLength("ff");
+            fail();
+        } catch (IOException e) {
+            // expected
+        }
+    }
+
+    public void testSmall() throws Exception {
+        doTest(10, 1000);
+    }
+
+    public void testMedium() throws Exception {
+        doTest(100, 100);
+    }
+
+    public void testLarge() throws Exception {
+        doTest(1000, 10);
+    }
+
+    private void doTest(int maxLength, int count) throws Exception {
+        String[] s = new String[count * 2];
+        Random r = new Random(0);
+        for (int i = 0; i < s.length; ) {
+            byte[] data = new byte[r.nextInt(maxLength)];
+            r.nextBytes(data);
+            s[i++] = store.writeBlob(new ByteArrayInputStream(data));
+            s[i++] = store.writeBlob(new ByteArrayInputStream(data));
+        }
+        r.setSeed(0);
+        for (int i = 0; i < s.length; ) {
+            int expectedLen = r.nextInt(maxLength);
+            byte[] expectedData = new byte[expectedLen];
+            r.nextBytes(expectedData);
+            assertEquals(expectedLen, store.getBlobLength(s[i++]));
+
+            String id = s[i++];
+            doTestRead(expectedData, expectedLen, id);
+        }
+    }
+
+    private void doTestRead(byte[] expectedData, int expectedLen, String id) throws Exception {
+        byte[] got = readFully(id);
+        assertEquals(expectedLen, got.length);
+        IOUtilsTest.assertEquals(expectedData, got);
+    }
+
+    public byte[] readFully(String id) throws Exception {
+        int len = (int) store.getBlobLength(id);
+        byte[] data;
+        if (len < 100) {
+            data = new byte[len];
+            for (int i = 0; i < len; i++) {
+                store.readBlob(id, i, data, i, 1);
+            }
+        } else {
+            data = BlobStoreInputStream.readFully(store, id);
+        }
+        assertEquals(len, data.length);
+        return data;
+    }
+
+    public static void main(String... args) throws Exception {
+        FileBlobStore store = new FileBlobStore("target/temp");
+
+//        DbBlobStore store = new DbBlobStore();
+//        store.setConnectionPool(JdbcConnectionPool.create("jdbc:h2:target/test;log=0;undo_log=0", "", ""));
+
+        String id = addFiles(store, "/Users/thomasm/Desktop/cq54/crx-quickstart");
+        extractFiles(store, id, "target/test");
+    }
+
+    public static void extractFiles(AbstractBlobStore store, String listingId, String target) throws IOException {
+        String listing = new String(BlobStoreInputStream.readFully(store, listingId), "UTF-8");
+        JsopTokenizer t = new JsopTokenizer(listing);
+        File targetDir = new File(target);
+        targetDir.mkdirs();
+        t.read('{');
+        if (!t.matches('}')) {
+            do {
+                String file = t.readString();
+                t.read(':');
+                String id = t.readString();
+                byte[] data = BlobStoreInputStream.readFully(store, id);
+                File outFile = new File(targetDir, file);
+                outFile.getParentFile().mkdirs();
+                FileOutputStream out = new FileOutputStream(outFile);
+                try {
+                    out.write(data);
+                } finally {
+                    out.close();
+                }
+            } while (t.matches(','));
+        }
+        t.read('}');
+    }
+
+    public static String addFiles(AbstractBlobStore store, String dir) throws Exception {
+        ArrayList<String> list = new ArrayList<String>();
+        String root = new File(dir).getAbsolutePath();
+        String parent = new File(dir).getParentFile().getAbsolutePath();
+        addFiles(list, new File(root));
+        JsopBuilder listing = new JsopBuilder();
+        listing.object();
+        for (String f : list) {
+            FileInputStream in = new FileInputStream(f);
+            String id = store.writeBlob(in);
+            in.close();
+            String name = f.substring(parent.length());
+            listing.key(name).value(id);
+            listing.appendWhitespace("\n");
+        }
+        listing.endObject();
+        String l = listing.toString();
+        String id = store.writeBlob(new ByteArrayInputStream(l.getBytes("UTF-8")));
+        return id;
+    }
+
+    private static void addFiles(ArrayList<String> list, File file) {
+        if (file.isDirectory()) {
+            for (File f : file.listFiles()) {
+                addFiles(list, f);
+            }
+            return;
+        }
+        if (!file.isFile()) {
+            return;
+        }
+        list.add(file.getAbsolutePath());
+    }
+
+}

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java?rev=1161434&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java (added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/FileBlobStoreTest.java Thu Aug 25 08:18:57 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.blobs;
+
+/**
+ * Tests the FileBlobStore implementation.
+ */
+public class FileBlobStoreTest extends DbBlobStoreTest {
+
+    public void setUp() throws Exception {
+        FileBlobStore store = new FileBlobStore("target/temp");
+        store.setBlockSize(128);
+        store.setBlockSizeMin(32);
+        this.store = store;
+    }
+
+    public void tearDown() throws Exception {
+        // nothing to do
+    }
+
+}

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java?rev=1161434&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java (added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStoreTest.java Thu Aug 25 08:18:57 2011
@@ -0,0 +1,33 @@
+/*
+ * 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.blobs;
+
+/**
+ * Tests the MemoryBlobStore implementation.
+ */
+public class MemoryBlobStoreTest extends DbBlobStoreTest {
+
+    public void setUp() throws Exception {
+        MemoryBlobStore store = new MemoryBlobStore();
+        this.store = store;
+    }
+
+    public void tearDown() throws Exception {
+        // nothing to do
+    }
+
+}

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsonBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsonBuilderTest.java?rev=1161434&r1=1161433&r2=1161434&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsonBuilderTest.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsonBuilderTest.java Thu Aug 25 08:18:57 2011
@@ -49,24 +49,24 @@ public class JsonBuilderTest {
                 .value("int", 3)
                 .value("float", 3f)
                 .object("obj")
-                    .value("boolean", true)
-                    .nil("nil")
-                    .array("arr")
-                        .value(1)
-                        .value(2.0f)
-                        .value(2.0d)
-                        .value("42")
-                    .build()
+                .value("boolean", true)
+                .nil("nil")
+                .array("arr")
+                .value(1)
+                .value(2.0f)
+                .value(2.0d)
+                .value("42")
                 .build()
-                .array("string array", new String[]{"","1","foo"})
-                .array("int array", new int[]{1,2,3})
-                .array("long array", new long[]{1,2,3})
-                .array("float array", new float[]{1,2,3})
-                .array("double array", new double[]{1,2,3})
+                .build()
+                .array("string array", new String[]{"", "1", "foo"})
+                .array("int array", new int[]{1, 2, 3})
+                .array("long array", new long[]{1, 2, 3})
+                .array("float array", new float[]{1, 2, 3})
+                .array("double array", new double[]{1, 2, 3})
                 .array("boolean array", new boolean[]{true, false})
                 .array("number array", new BigDecimal[]{new BigDecimal(21), new BigDecimal(42)})
                 .value("some", "more")
-            .build();
+                .build();
 
         String json = sw.toString();
         assertEquals("{\"foo\":\"bar\",\"int\":3,\"float\":3.0,\"obj\":{\"boolean\":true,\"nil\":null," +
@@ -81,7 +81,7 @@ public class JsonBuilderTest {
         JsonBuilder.create(sw)
                 .value("back\\slash", "\\")
                 .value("back\\\\slash", "\\\\")
-            .build();
+                .build();
 
         String json = sw.toString();
         assertEquals("{\"back\\\\slash\":\"\\\\\",\"back\\\\\\\\slash\":\"\\\\\\\\\"}", json);
@@ -124,6 +124,7 @@ public class JsonBuilderTest {
         public void startJSON() throws ParseException, IOException {
             // ignore
         }
+
         public void endJSON() throws ParseException, IOException {
             // ignore
         }
@@ -162,54 +163,39 @@ public class JsonBuilderTest {
 
         public boolean primitive(Object value) throws ParseException, IOException {
             if (arrayBuilder == null) {
-                if(value == null){
+                if (value == null) {
                     objectBuilder.nil(currentKey);
-                }
-                else if(value instanceof String) {
-                    objectBuilder.value(currentKey, (String)value);
-                }
-                else if(value instanceof Integer) {
+                } else if (value instanceof String) {
+                    objectBuilder.value(currentKey, (String) value);
+                } else if (value instanceof Integer) {
                     objectBuilder.value(currentKey, ((Integer) value).intValue());
-                }
-                else if(value instanceof Long) {
+                } else if (value instanceof Long) {
                     objectBuilder.value(currentKey, ((Long) value).longValue());
-                }
-                else if(value instanceof Double) {
+                } else if (value instanceof Double) {
                     objectBuilder.value(currentKey, ((Double) value).doubleValue());
-                }
-                else if(value instanceof Float) {
+                } else if (value instanceof Float) {
                     objectBuilder.value(currentKey, ((Float) value).floatValue());
-                }
-                else if(value instanceof Boolean) {
+                } else if (value instanceof Boolean) {
                     objectBuilder.value(currentKey, (Boolean) value);
-                }
-                else {
+                } else {
                     Assert.fail();
                 }
-            }
-            else {
-                if(value == null){
+            } else {
+                if (value == null) {
                     arrayBuilder.nil();
-                }
-                else if(value instanceof String) {
+                } else if (value instanceof String) {
                     arrayBuilder.value((String) value);
-                }
-                else if(value instanceof Integer) {
+                } else if (value instanceof Integer) {
                     arrayBuilder.value(((Integer) value).intValue());
-                }
-                else if(value instanceof Long) {
+                } else if (value instanceof Long) {
                     arrayBuilder.value(((Long) value).longValue());
-                }
-                else if(value instanceof Double) {
+                } else if (value instanceof Double) {
                     arrayBuilder.value(((Double) value).doubleValue());
-                }
-                else if(value instanceof Float) {
+                } else if (value instanceof Float) {
                     arrayBuilder.value(((Float) value).floatValue());
-                }
-                else if(value instanceof Boolean) {
+                } else if (value instanceof Boolean) {
                     arrayBuilder.value((Boolean) value);
-                }
-                else {
+                } else {
                     Assert.fail();
                 }
             }



Mime
View raw message