jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1138518 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Wed, 22 Jun 2011 15:52:07 GMT
Author: mduerig
Date: Wed Jun 22 15:52:06 2011
New Revision: 1138518

URL: http://svn.apache.org/viewvc?rev=1138518&view=rev
Log:
spi2microkernel prototype (WIP)
observation (WIP)

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1138518&r1=1138517&r2=1138518&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Wed Jun 22 15:52:06 2011
@@ -43,6 +43,7 @@ import org.apache.jackrabbit.spi.Subscri
 import org.apache.jackrabbit.spi.commons.AbstractRepositoryService;
 import org.apache.jackrabbit.spi.commons.EventFilterImpl;
 import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
+import org.apache.jackrabbit.spi.commons.SessionInfoImpl;
 import org.apache.jackrabbit.spi.commons.batch.ConsolidatingChangeLog;
 import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
 import org.apache.jackrabbit.spi2microkernel.util.NodeTypes;
@@ -420,7 +421,7 @@ public class RepositoryServiceImpl exten
                 }
             }
 
-            microKernel.commit("/", "+\"" + wspName + "\" : {}" , revisionId);
+            microKernel.commit("/", "+\"" + wspName + "\" : {}" , revisionId, "create workspace");
         }
         catch (MicroKernelException e) {
             throw new RepositoryException(e.getMessage(), e);
@@ -438,7 +439,7 @@ public class RepositoryServiceImpl exten
                 throw new NoSuchWorkspaceException("No such workspace: " + name);
             }
 
-            microKernel.commit("/", "-\"" + wspName + '\"', revisionId);
+            microKernel.commit("/", "-\"" + wspName + '\"', revisionId, "delete workspace");
         }
         catch (MicroKernelException e) {
             throw new RepositoryException(e.getMessage(), e);
@@ -531,7 +532,7 @@ public class RepositoryServiceImpl exten
             sessionState(sessionInfo).commitWithLock(new Callable<String>() {
                 public String call() throws RepositoryException {
                     String rev = sessionState(sessionInfo).getHeadRevision();
-                    return microKernel.commit("/", jsop.toString(), rev);
+                    return microKernel.commit("/", jsop.toString(), rev, ((SessionInfoImpl)
sessionInfo).getUserData());  
                 }
             });
         }

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java?rev=1138518&r1=1138517&r2=1138518&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
Wed Jun 22 15:52:06 2011
@@ -32,6 +32,7 @@ import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.Subscription;
 import org.apache.jackrabbit.spi.commons.EventBundleImpl;
 import org.apache.jackrabbit.spi.commons.EventImpl;
+import org.apache.jackrabbit.spi2microkernel.util.Paths;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
@@ -130,8 +131,13 @@ public class SubscriptionImpl implements
 
             try {
                 List<?> jsonArray = jsonArray(new JSONParser().parse(journal));
-                for (Object o : jsonArray) {
-                    JSONObject jsonObject = jsonObject(o);
+                Iterator<?> it = jsonArray.iterator();
+                if (it.hasNext()) {
+                    it.next();  // skip base revision
+                }
+
+                while (it.hasNext()) {
+                    JSONObject jsonObject = jsonObject(it.next());
                     EventBundle eventBundle = createEventBundle(jsonObject);
                     if (eventBundle != null) {
                         eventBundles.add(eventBundle);
@@ -185,7 +191,7 @@ public class SubscriptionImpl implements
             while (jsopTokenizer.read() != JsopTokenizer.END) {
                 int tokenType = jsopTokenizer.getTokenType();
                 switch(tokenType) {
-                    case '+': addNode(jsopTokenizer, eventTemplate, events); break;
+                    case '+': addItem(jsopTokenizer, eventTemplate, events); break;
                     case '-': removeNode(jsopTokenizer, eventTemplate, events); break;
                     case '^': setProperty(jsopTokenizer, eventTemplate, events); break;
                     case '>': moveNode(jsopTokenizer, eventTemplate, events); break;
@@ -198,26 +204,37 @@ public class SubscriptionImpl implements
 
         // Event#NODE_ADDED} Event#NODE_REMOVED} Event#PROPERTY_ADDED} Event#PROPERTY_REMOVED}
         // Event#PROPERTY_CHANGED} Event#NODE_MOVED} Event#PERSIST}
-        private void addNode(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate, Collection<Event>
events) {
+        private void addItem(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate, Collection<Event>
events) {
             EventTemplate addNodeEvent = eventTemplate.copy();
 
+            String path = jsopTokenizer.readString();
+            Path p = Paths.stringToPath(path);
+            jsopTokenizer.read(':');
+            
+            if (jsopTokenizer.read() == '{') {
+                addNodeEvent.setType(Event.NODE_ADDED);
+            }
+            else {
+                addNodeEvent.setType(Event.PROPERTY_ADDED);
+            }
+
+
             // todo implement addNode
-            Path path = null;
+
+            Path qpath = null;
             ItemId itemId = null;
             NodeId parentId = null;
 
+            // todo need more context in journal in case of property mod
             Name primaryNodeTypeName = null;
             Name[] mixinTypeNames = null;
 
-            String userId = null;
-
-            String userData = null;
-
             events.add(addNodeEvent.buildEvent());
         }
 
         private void removeNode(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate,
Collection<Event> events) {
             // todo implement removeNode
+            // todo consider ways to handle deep mods
         }
 
         private void setProperty(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate,
Collection<Event> events) {

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java?rev=1138518&r1=1138517&r2=1138518&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
Wed Jun 22 15:52:06 2011
@@ -50,7 +50,7 @@ public class MicrokernelTest {
                 "\"stringProp\":\"stringVal\"," +
                 "\"intProp\":42," +
                 "\"floatProp\":42.2," +
-                "\"multiIntProp\":[1,2,3]} ", head);
+                "\"multiIntProp\":[1,2,3]} ", head, "");
         }
     }
 
@@ -74,7 +74,7 @@ public class MicrokernelTest {
         MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
-        head = mk.commit("/", "+\"foo\" : {} \n+\"foo/bar\" : {}", head);
+        head = mk.commit("/", "+\"foo\" : {} \n+\"foo/bar\" : {}", head, "");
         assertTrue(mk.nodeExists("/foo", head));
         assertTrue(mk.nodeExists("/foo/bar", head));
     }
@@ -86,7 +86,7 @@ public class MicrokernelTest {
 
         head = mk.commit("/",
                 "+\"fuu\" : {} \n" +
-                "^\"fuu/bar\" : 42", head);
+                "^\"fuu/bar\" : 42", head, "");
         String n = mk.getNodes("/fuu", head);
         assertEquals("{\"bar\":42,\":childNodeCount\":0}", n);
     }
@@ -99,7 +99,7 @@ public class MicrokernelTest {
         long millis = System.currentTimeMillis();
         String node1 = "n1_" + millis;
         String node2 = "n2_" + millis;
-        head = mk.commit("/", "+\"" + node1 + "\" : {} \r+\"" + node2 + "\" : {}\n", head);
+        head = mk.commit("/", "+\"" + node1 + "\" : {} \r+\"" + node2 + "\" : {}\n", head,
"");
         assertTrue(mk.nodeExists('/' + node1, head));
         assertTrue(mk.nodeExists('/' + node2, head));
     }
@@ -119,7 +119,7 @@ public class MicrokernelTest {
                 "^\"" + node + "/prop1\" : 41\r" +
                 "^\"" + node + "/child1/prop2\" : 42\r" +
                 "^\"" + node + "/child1/grandchild11/prop3\" : 43",
-                head);
+                head, "");
 
         String json = mk.getNodes('/' + node, head, 3, 0, -1);
         assertEquals("{\"prop1\":41,\":childNodeCount\":2," +
@@ -134,9 +134,9 @@ public class MicrokernelTest {
         String head = mk.getHeadRevision();
         String node = "removeNode_" + System.currentTimeMillis();
 
-        head = mk.commit("/", "+\"" + node + "\" : {\"child\":{}}", head);
+        head = mk.commit("/", "+\"" + node + "\" : {\"child\":{}}", head, "");
 
-        head = mk.commit('/' + node, "-\"child\"", head);
+        head = mk.commit('/' + node, "-\"child\"", head, "");
         String json = mk.getNodes('/' + node, head);
         assertEquals("{\":childNodeCount\":0}", json);
     }
@@ -148,9 +148,9 @@ public class MicrokernelTest {
         long t = System.currentTimeMillis();
         String node = "removeProperty_" + t;
 
-        head = mk.commit("/", "+\"" + node + "\" : {\"prop\":\"value\"}", head);
+        head = mk.commit("/", "+\"" + node + "\" : {\"prop\":\"value\"}", head, "");
 
-        head = mk.commit("/", "^\"" + node + "/prop\" : null", head);
+        head = mk.commit("/", "^\"" + node + "/prop\" : null", head, "");
         String json = mk.getNodes('/' + node, head);
         assertEquals("{\":childNodeCount\":0}", json);
     }
@@ -209,11 +209,11 @@ public class MicrokernelTest {
 
         String head = mk.commit("/",
                 "+\"{}node\" : {}",
-                init);
+                init, "");
 
         head = mk.commit("/",
                 "-\"{}node\"",
-                head);
+                head, "");
 
         mk.getJournal(init, head); 
     }
@@ -225,7 +225,7 @@ public class MicrokernelTest {
 
         String head = mk.commit("/",
                 "+\"node\" : {}",
-                init);
+                init, "");
 
         String journal = mk.getJournal(head, head);
 
@@ -253,11 +253,11 @@ public class MicrokernelTest {
 
         String head = mk.commit("/",
                 "+\"node\" : {\"prop\":42}",
-                init);
+                init, "");
 
         head = mk.commit("/",
                 "^\"node/prop\":21",
-                head);
+                head, "");
 
         String journal = mk.getJournal(head, head);
 
@@ -281,11 +281,11 @@ public class MicrokernelTest {
 
         String head = mk.commit("/",
                 "+\"node\" : {\"prop\":\"foo\"}",
-                init);
+                init, "");
 
         head = mk.commit("/",
                 "^\"node/prop\":\"bar\"",
-                head);
+                head, "");
 
         String journal = mk.getJournal(head, head);
 

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1138518&r1=1138517&r2=1138518&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Wed Jun 22 15:52:06 2011
@@ -86,11 +86,11 @@ public class RepositoryTest {
                         "\"{}stringProp\":\"stringVal\"," +
                         "\"{}intProp\":42," +
                         "\"{}mvProp\":[1,2,3]}, " +
-                    "\"{}bar\" : {}}", head);
+                    "\"{}bar\" : {}}", head, "");
         }
 
         if (!mk.nodeExists("/default/{}" + testNode, head)) {
-            mk.commit("/default", "+\"{}" + testNode + "\" : {" + ptUnstructured + '}', head);
+            mk.commit("/default", "+\"{}" + testNode + "\" : {" + ptUnstructured + '}', head,
"");
         }
 
         mk.dispose();
@@ -906,6 +906,7 @@ public class RepositoryTest {
         }
     }
 
+    @Ignore  // todo make this into real test
     @Test
     public void observation() throws RepositoryException, InterruptedException {
         ObservationManager obsMgr = getSession().getWorkspace().getObservationManager();
@@ -920,11 +921,45 @@ public class RepositoryTest {
             Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED | Event.PERSIST, "/", true, null,
null, false);
 
         Node n = getNode(testPath);
-        n.addNode("1");
+        Node n1 = n.addNode("1");
+        n1.setProperty("prop1", "val1");
+        n1.setProperty("prop2", "val2");
         n.addNode("2");
         getSession().save();
+
+        n.setProperty("property", 42);
         n.addNode("3");
-        n.addNode("4");
+        n1.setProperty("prop1", "val1 new");
+        n1.getProperty("prop2").remove();
+        n.getNode("2").remove();  
+        getSession().save();
+        Thread.sleep(10000);
+    }
+
+    @Ignore  // todo make this into real test
+    @Test 
+    public void observation2() throws RepositoryException, InterruptedException {
+        Node n = getNode(testPath);
+        Node n1 = n.addNode("1");
+        n1.setProperty("prop1", "val1");
+        n1.setProperty("prop2", "val2");
+        Node n2 = n1.addNode("2");
+        n2.addNode("3");
+        getSession().save();
+
+        ObservationManager obsMgr = getSession().getWorkspace().getObservationManager();
+        obsMgr.addEventListener(new EventListener(){
+                public void onEvent(EventIterator events) {
+                    while (events.hasNext()) {
+                        System.out.println(events.next());
+                    }
+                }
+            },
+            Event.NODE_ADDED | Event.NODE_MOVED | Event.NODE_MOVED | Event.PROPERTY_ADDED
|
+            Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED | Event.PERSIST, "/", true, null,
null, false);
+
+
+        n1.remove();
         getSession().save();
         Thread.sleep(10000);
     }



Mime
View raw message