jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1098632 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store: CommitBuilder.java DiffBuilder.java
Date Mon, 02 May 2011 15:46:09 GMT
Author: stefan
Date: Mon May  2 15:46:09 2011
New Revision: 1098632

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

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java

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=1098632&r1=1098631&r2=1098632&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
Mon May  2 15:46:09 2011
@@ -153,14 +153,14 @@ public class CommitBuilder {
     }
 
     public String /* new revId */ doCommit() throws Exception {
-        // todo acquire revisions lock
+        // todo develop efficient locking strategy providing maximum concurrenncy
         if (rep.getHeadRevision() != baseRevId) {
             // update base revision to new head
             this.baseRevId = rep.getHeadRevision();
             // clear staging area
             staged.clear();
             // replay change log on new base revision
-            // copy log in order to avoid concurent modifications
+            // copy log in order to avoid concurrent modifications
             List<Change> log = new ArrayList<Change>(changeLog);
             for (Change change : log) {
                 change.apply();
@@ -191,6 +191,7 @@ public class CommitBuilder {
         // iterate over staged entries in depth-descending order
         String rootNodeId = null;
         for (String path : orderedPaths) {
+            // persist node
             String id = store.putNode(staged.get(path));
             if (path.equals("/")) {
                 rootNodeId = id;
@@ -202,6 +203,7 @@ public class CommitBuilder {
             throw new Exception("internal error: inconsistent staging area content");
         }
 
+        // todo check for concurrent changes (new head), apply lock and merge changes
         MutableCommit newCommit = new MutableCommit();
         newCommit.setParentId(baseRevId);
         newCommit.setCommitTS(System.currentTimeMillis());
@@ -209,8 +211,6 @@ public class CommitBuilder {
         String newRevId = store.putCommit(newCommit);
         store.setHeadCommit(newRevId);
 
-        // todo release revisions lock
-
         // reset instance in order to be reusable
         staged.clear();
         changeLog.clear();

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java?rev=1098632&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java
Mon May  2 15:46:09 2011
@@ -0,0 +1,100 @@
+/*
+ * 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 java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public class DiffBuilder {
+
+    final Node before;
+    final Node after;
+    final DiffHandler handler;
+
+    public DiffBuilder(Node before, Node after, DiffHandler handler) {
+        this.before = before;
+        this.after = after;
+        this.handler = handler;
+    }
+
+    public void build() {
+
+        // compare properties
+        Map<String, String> oldProps = before.getProperties();
+        Map<String, String> newProps = after.getProperties();
+        if (!oldProps.equals(newProps)) {
+            Set<String> set = new HashSet<String>();
+            set.addAll(oldProps.keySet());
+            set.removeAll(newProps.keySet());
+            for (String name : set) {
+                handler.propDeleted(name);
+            }
+            set.clear();
+            set.addAll(newProps.keySet());
+            set.removeAll(oldProps.keySet());
+            for (String name : set) {
+                handler.propAdded(name, newProps.get(name));
+            }
+            for (Map.Entry<String, String> entry : oldProps.entrySet()) {
+                String val = newProps.get(entry.getKey());
+                if (val != null && !entry.getValue().equals(val)) {
+                    handler.propChanged(entry.getKey(), entry.getValue(), val);
+                }
+            }
+        }
+
+        // compare child node entries
+        Map<String, String> oldEntries = before.getChildNodeEntries();
+        Map<String, String> newEntries = after.getChildNodeEntries();
+        if (!oldEntries.equals(newEntries)) {
+            Set<String> set = new HashSet<String>();
+            set.addAll(oldEntries.keySet());
+            set.removeAll(newEntries.keySet());
+            for (String name : set) {
+                handler.nodeDeleted(name);
+            }
+            set.clear();
+            set.addAll(newEntries.keySet());
+            set.removeAll(oldEntries.keySet());
+            for (String name : set) {
+                handler.nodeAdded(name, newEntries.get(name));
+            }
+            for (Map.Entry<String, String> entry : oldEntries.entrySet()) {
+                String id = newEntries.get(entry.getKey());
+                if (id != null && !entry.getValue().equals(id)) {
+                    handler.nodeChanged(entry.getKey(), entry.getValue(), id);
+                }
+            }
+        }
+
+    }
+
+    public static interface DiffHandler {
+
+        void propAdded(String name, String value);
+        void propChanged(String name, String oldValue, String newValue);
+        void propDeleted(String name);
+
+        void nodeAdded(String name, String id);
+        void nodeChanged(String name, String oldId, String newId);
+        void nodeDeleted(String name);
+    }
+}



Mime
View raw message