jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1206245 - /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
Date Fri, 25 Nov 2011 16:13:24 GMT
Author: stefan
Date: Fri Nov 25 16:13:23 2011
New Revision: 1206245

URL: http://svn.apache.org/viewvc?rev=1206245&view=rev
Log:
non-binary serialization for testing purposes

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java?rev=1206245&r1=1206244&r2=1206245&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
Fri Nov 25 16:13:23 2011
@@ -38,17 +38,22 @@ import org.bson.types.ObjectId;
 import java.io.File;
 import java.io.InputStream;
 import java.security.MessageDigest;
+import java.util.LinkedHashMap;
 
 /**
  *
  */
 public class MongoPersistenceManager extends AbstractPersistenceManager {
 
-    private static String HEAD_COLLECTION = "head";
-    private static String NODES_COLLECTION = "nodes";
-    private static String COMMITS_COLLECTION = "commits";
-    private static String ID_FIELD = "id";
-    private static String DATA_FIELD = "data";
+    private static final boolean BINARY_FORMAT = false;
+
+    private static final String HEAD_COLLECTION = "head";
+    private static final String NODES_COLLECTION = "nodes";
+    private static final String COMMITS_COLLECTION = "commits";
+    private static final String ID_FIELD = ":id";
+    private static final String DATA_FIELD = ":data";
+    private static final String PROPERTIES_OBJECT = ":props";
+    private static final String CHILDREN_OBJECT = ":children";
 
     private Mongo con;
     private DB db;
@@ -107,13 +112,21 @@ public class MongoPersistenceManager ext
     @Override
     protected StoredNode readNode(String id) throws NotFoundException, Exception {
         BasicDBObject key = new BasicDBObject();
-        //key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
-        key.put(ID_FIELD, id);
+        if (BINARY_FORMAT) {
+            key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
+        } else {
+            key.put(ID_FIELD, id);
+        }
         DBObject nodeObject = nodes.findOne(key);
         if (nodeObject != null) {
-            // todo use json serialization format
-            byte[] bytes = (byte[]) nodeObject.get(DATA_FIELD);
-            return Serializer.fromBytes(id, bytes, Node.class);
+            if (BINARY_FORMAT) {
+                byte[] bytes = (byte[]) nodeObject.get(DATA_FIELD);
+                return Serializer.fromBytes(id, bytes, Node.class);
+            } else {
+                return new StoredNode(id,
+                        ((BasicDBObject) nodeObject.get(PROPERTIES_OBJECT)).toMap(),
+                        (LinkedHashMap<String, String>) ((BasicDBObject) nodeObject.get(PROPERTIES_OBJECT)).toMap());
+            }
         } else {
             throw new NotFoundException(id);
         }
@@ -124,9 +137,15 @@ public class MongoPersistenceManager ext
         byte[] bytes = Serializer.toBytes(node);
         byte[] key = MessageDigest.getInstance("SHA-1").digest(bytes);
         String id = StringUtils.convertBytesToHex(key);
-        //BasicDBObject nodeObject = new BasicDBObject(ID_FIELD, key).append(DATA_FIELD,
bytes);
-        // todo use json serialization format
-        BasicDBObject nodeObject = new BasicDBObject(ID_FIELD, id).append(DATA_FIELD, bytes);
+
+        BasicDBObject nodeObject;
+        if (BINARY_FORMAT) {
+            nodeObject = new BasicDBObject(ID_FIELD, key).append(DATA_FIELD, bytes);
+        } else {
+            nodeObject = new BasicDBObject(ID_FIELD, id)
+                    .append(PROPERTIES_OBJECT, new BasicDBObject(node.getProperties()))
+                    .append(CHILDREN_OBJECT, new BasicDBObject(node.getChildNodeEntries()));
+        }
         try {
             nodes.insert(nodeObject);
         } catch (MongoException.DuplicateKey ignore) {
@@ -139,13 +158,23 @@ public class MongoPersistenceManager ext
     @Override
     protected StoredCommit readCommit(String id) throws NotFoundException, Exception {
         BasicDBObject key = new BasicDBObject();
-        //key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
-        key.put(ID_FIELD, id);
+        if (BINARY_FORMAT) {
+            key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
+        } else {
+            key.put(ID_FIELD, id);
+        }
         DBObject commitObject = commits.findOne(key);
         if (commitObject != null) {
-            // todo use json serialization format
-            byte[] bytes = (byte[]) commitObject.get(DATA_FIELD);
-            return Serializer.fromBytes(id, bytes, Commit.class);
+            if (BINARY_FORMAT) {
+                byte[] bytes = (byte[]) commitObject.get(DATA_FIELD);
+                return Serializer.fromBytes(id, bytes, Commit.class);
+            } else {
+                return new StoredCommit(id,
+                        (String) commitObject.get("parentId"),
+                        (Long) commitObject.get("ts"),
+                        (String) commitObject.get("rootNodeId"),
+                        (String) commitObject.get("msg"));
+            }
         } else {
             throw new NotFoundException(id);
         }
@@ -156,9 +185,18 @@ public class MongoPersistenceManager ext
         byte[] bytes = Serializer.toBytes(commit);
         byte[] key = MessageDigest.getInstance("SHA-1").digest(bytes);
         String id = StringUtils.convertBytesToHex(key);
-        //BasicDBObject commitObject = new BasicDBObject(ID_FIELD, key).append(DATA_FIELD,
bytes);
-        // todo use json serialization format
-        BasicDBObject commitObject = new BasicDBObject(ID_FIELD, id).append(DATA_FIELD, bytes);
+
+        BasicDBObject commitObject;
+        if (BINARY_FORMAT) {
+            commitObject = new BasicDBObject(ID_FIELD, key).append(DATA_FIELD, bytes);
+        } else {
+            commitObject = new BasicDBObject(ID_FIELD, id)
+                    .append(ID_FIELD, id)
+                    .append("rootNodeId", commit.getRootNodeId())
+                    .append("ts", commit.getCommitTS())
+                    .append("parentId", commit.getParentId())
+                    .append("msg", commit.getMsg());
+        }
         try {
             commits.insert(commitObject);
         } catch (MongoException.DuplicateKey ignore) {



Mime
View raw message