jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1205934 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: Repository.java store/InMemPersistenceManager.java
Date Thu, 24 Nov 2011 17:10:49 GMT
Author: stefan
Date: Thu Nov 24 17:10:48 2011
New Revision: 1205934

URL: http://svn.apache.org/viewvc?rev=1205934&view=rev
Log:
simple InMemPersistenceManager for testing purposes

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1205934&r1=1205933&r2=1205934&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
Thu Nov 24 17:10:48 2011
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.mk.store.Ab
 import org.apache.jackrabbit.mk.store.BDbPersistenceManager;
 import org.apache.jackrabbit.mk.store.FSPersistenceManager;
 import org.apache.jackrabbit.mk.store.H2PersistenceManager;
+import org.apache.jackrabbit.mk.store.InMemPersistenceManager;
 import org.apache.jackrabbit.mk.store.MongoPersistenceManager;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 import org.apache.jackrabbit.mk.store.RevisionStore;
@@ -48,8 +49,9 @@ public class Repository {
         }
         this.homeDir = home.getCanonicalPath();
 
-        //pm = new MongoPersistenceManager();
         pm = new H2PersistenceManager();
+        //pm = new InMemPersistenceManager();
+        //pm = new MongoPersistenceManager();
         //pm = new BDbPersistenceManager();
         //pm = new FSPersistenceManager();
 

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java?rev=1205934&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/InMemPersistenceManager.java
Thu Nov 24 17:10:48 2011
@@ -0,0 +1,124 @@
+/*
+ * 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.store;
+
+import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
+import org.apache.jackrabbit.mk.model.Commit;
+import org.apache.jackrabbit.mk.model.Node;
+import org.apache.jackrabbit.mk.model.StoredCommit;
+import org.apache.jackrabbit.mk.model.StoredNode;
+import org.apache.jackrabbit.mk.store.util.Serializer;
+import org.apache.jackrabbit.mk.util.StringUtils;
+
+import java.io.File;
+import java.io.InputStream;
+import java.security.MessageDigest;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class InMemPersistenceManager extends AbstractPersistenceManager {
+
+
+    private final Map<String, StoredNode> nodes = Collections.synchronizedMap(new HashMap<String,
StoredNode>());
+    private final Map<String, StoredCommit> commits = Collections.synchronizedMap(new
HashMap<String, StoredCommit>());
+    private final BlobStore blobs = new MemoryBlobStore();
+
+    private String head;
+
+    @Override
+    protected void doInitialize(File homeDir) throws Exception {
+        head = null;
+    }
+
+    @Override
+    protected void doClose() {
+    }
+
+    @Override
+    protected String readHead() throws Exception {
+        return head;
+    }
+
+    @Override
+    protected void writeHead(String id) throws Exception {
+        head = id;
+    }
+
+    @Override
+    protected StoredNode readNode(String id) throws NotFoundException, Exception {
+        StoredNode node = nodes.get(id);
+        if (node != null) {
+            return node;
+        } else {
+            throw new NotFoundException(id);
+        }
+    }
+
+    @Override
+    protected String writeNode(Node node) throws Exception {
+        byte[] bytes = Serializer.toBytes(node);
+        String id = StringUtils.convertBytesToHex(MessageDigest.getInstance("SHA-1").digest(bytes));
+
+        if (!nodes.containsKey(id)) {
+            nodes.put(id, Serializer.fromBytes(id, bytes, Node.class));
+        }
+
+        return id;
+    }
+
+    @Override
+    protected StoredCommit readCommit(String id) throws NotFoundException, Exception {
+        StoredCommit commit = commits.get(id);
+        if (commit != null) {
+            return commit;
+        } else {
+            throw new NotFoundException(id);
+        }
+    }
+
+    @Override
+    protected String writeCommit(Commit commit) throws Exception {
+        byte[] bytes = Serializer.toBytes(commit);
+        String id = StringUtils.convertBytesToHex(MessageDigest.getInstance("SHA-1").digest(bytes));
+
+        if (!commits.containsKey(id)) {
+            commits.put(id, Serializer.fromBytes(id, bytes, Commit.class));
+        }
+
+        return id;
+    }
+
+    @Override
+    protected String writeBlob(InputStream in) throws Exception {
+        return blobs.writeBlob(in);
+    }
+
+    @Override
+    protected int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws
NotFoundException, Exception {
+        return blobs.readBlob(blobId, pos, buff, off, length);
+    }
+
+    @Override
+    protected long blobLength(String blobId) throws NotFoundException, Exception {
+        return blobs.getBlobLength(blobId);
+    }
+}



Mime
View raw message