jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1126526 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
Date Mon, 23 May 2011 15:04:49 GMT
Author: stefan
Date: Mon May 23 15:04:48 2011
New Revision: 1126526

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

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1126526&r1=1126525&r2=1126526&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Mon May 23 15:04:48 2011
@@ -26,10 +26,10 @@ import org.apache.jackrabbit.mk.store.No
 import org.apache.jackrabbit.mk.store.NodeDiffHandler;
 import org.apache.jackrabbit.mk.store.NodeUtils;
 import org.apache.jackrabbit.mk.util.PathUtil;
-import org.json.simple.JSONObject;
 import org.json.simple.parser.ContainerFactory;
 import org.json.simple.parser.JSONParser;
 
+import java.awt.geom.PathIterator;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -312,11 +312,11 @@ public class MicroKernelImpl implements 
             final JSONParser jsonParser = new JSONParser();
             final ContainerFactory containerFactory = new ContainerFactory() {
                 public List creatArrayContainer() {
-                    return new LinkedList();
+                    return new JSONArray();
                 }
 
                 public Map createObjectContainer() {
-                    return new LinkedHashMap();
+                    return new JSONObject();
                 }
             };
 
@@ -327,17 +327,8 @@ public class MicroKernelImpl implements 
                     if (!(obj instanceof Map)) {
                         throw new Exception("illegal json object format: " + jsonObject);
                     }
-                    Map jsonNode = (Map) obj;
-                    Map<String, String> props = new HashMap<String, String>();
 
-                    for (Iterator it = jsonNode.entrySet().iterator(); it.hasNext(); ) {
-                        Map.Entry entry = (Map.Entry) it.next();
-                        if (! (entry.getValue() instanceof JSONObject)) {
-                            props.put((String) entry.getKey(), entry.getValue().toString());
-                        }
-                    }
-                    cb.addNode(path, nodeName, props);
-                    // todo support nested json objects
+                    MicroKernelImpl.addNode(cb, path, nodeName, (JSONObject) obj);
                 }
 
                 public void setProperty(String propName, String propValue) throws Exception
{
@@ -432,4 +423,27 @@ public class MicroKernelImpl implements 
         }
         buf.append("}");
     }
+
+    static void addNode(CommitBuilder cb, String path, String name, JSONObject jsonNode)
throws Exception {
+        Map<String, String> props = new HashMap<String, String>();
+
+        for (Iterator it = jsonNode.entrySet().iterator(); it.hasNext(); ) {
+            Map.Entry entry = (Map.Entry) it.next();
+            if (! (entry.getValue() instanceof JSONObject)) {
+                props.put((String) entry.getKey(), entry.getValue().toString());
+            }
+        }
+        cb.addNode(path, name, props);
+        // add nested json objects
+        for (Iterator it = jsonNode.entrySet().iterator(); it.hasNext(); ) {
+            Map.Entry entry = (Map.Entry) it.next();
+            if (entry.getValue() instanceof JSONObject) {
+                addNode(cb, PathUtil.concat(path, name), (String) entry.getKey(), (JSONObject)
entry.getValue());
+            }
+        }
+    }
+
+    //--------------------------------------------------------< inner classes >
+    static class JSONObject extends LinkedHashMap<String, Object>{};
+    static class JSONArray extends LinkedList{};
 }

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=1126526&r1=1126525&r2=1126526&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
Mon May 23 15:04:48 2011
@@ -19,11 +19,12 @@ package org.apache.jackrabbit.mk;
 import junit.framework.TestCase;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 
-import java.util.ArrayList;
+import java.util.Random;
 
 public class ConcurrentWriteTest extends TestCase {
 
     private static final int NUM_THREADS = 5;
+    private static final int NUM_CHILDNODES = 1000;
 
     private MicroKernel mk;
 
@@ -88,19 +89,26 @@ public class ConcurrentWriteTest extends
 
     class TestThread extends Thread {
         String revId;
+        Random rand;
 
         TestThread(String revId, String name) {
             super(name);
             this.revId = revId;
+            rand = new Random();
         }
 
         public void run() {
             StringBuilder sb = new StringBuilder();
             sb.append("+\"");
             sb.append(getName());
-            sb.append("\" : {\"jcr:primaryType\":\"nt:unstructured\"\n");
-            for (int i = 0; i < 1000; i++) {
-                sb.append(",\"sub" + i + "\" : {\"jcr:primaryType\":\"nt:unstructured\",
\"prop\":\"" + System.currentTimeMillis() + "\"}\n");
+            sb.append("\" : {\"jcr:primaryType\":\"nt:unstructured\",\n");
+            for (int i = 0; i < NUM_CHILDNODES; i++) {
+                sb.append("\"sub" + i + "\" : {\"jcr:primaryType\":\"nt:unstructured\", \"prop\":\""
+ rand.nextLong() + "\"}");
+                if (i == NUM_CHILDNODES - 1) {
+                    sb.append('\n');
+                } else {
+                    sb.append(",\n");
+                }
             }
             sb.append('}');
             revId = mk.commit("/test", sb.toString(), revId);



Mime
View raw message