jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1163945 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/index/ main/java/org/apache/jackrabbit/mk/mem/ test/java/org/apache/jackrabbit/mk/index/
Date Thu, 01 Sep 2011 08:47:42 GMT
Author: thomasm
Date: Thu Sep  1 08:47:42 2011
New Revision: 1163945

URL: http://svn.apache.org/viewvc?rev=1163945&view=rev
Log:
Index mechanism (WIP)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Index.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Index.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Index.java?rev=1163945&r1=1163944&r2=1163945&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Index.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Index.java
Thu Sep  1 08:47:42 2011
@@ -26,17 +26,22 @@ import org.apache.jackrabbit.mk.mem.Node
 public interface Index {
 
     /**
-     * The given node was added.
+     * The given node was added or removed.
      *
-     * @param add the added node
+     * @param node the node including (old or new) data
+     * @param add true if added, false if removed
      */
-    void add(NodeImpl add);
+    void addOrRemoveNode(NodeImpl node, boolean add);
 
     /**
-     * The given node was removed.
+     * The given property was added or removed.
      *
-     * @param remove the removed node
+     * @param nodePath the path of the node
+     * @param propertyName the property name
+     * @param value the old (when deleting) or new (when adding) value
+     * @param add true if added, false if removed
      */
-    void remove(NodeImpl remove);
+    void addOrRemoveProperty(String nodePath, String propertyName,
+            String value, boolean add);
 
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java?rev=1163945&r1=1163944&r2=1163945&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
Thu Sep  1 08:47:42 2011
@@ -212,7 +212,7 @@ public class Indexer {
                 NodeMap map = new NodeMap();
                 if (t.matches('{')) {
                     NodeImpl n = NodeImpl.parse(map, t, 0, path);
-                    addOrRemoveRecursive(n, true, true);
+                    addOrRemoveRecursive(n, false, true);
                 } else {
                     String value = t.readRawValue().trim();
                     String nodePath = PathUtils.getParentPath(path);
@@ -232,19 +232,12 @@ public class Indexer {
                 path = t.readString();
                 removeProperty(path, lastRevision);
                 t.read(':');
-                String value;
-                NodeMap map = new NodeMap();
-                NodeImpl node = new NodeImpl(map, 0);
                 if (t.matches(JsopTokenizer.NULL)) {
-                    value = null;
+                    // ignore
                 } else {
-                    value = t.readRawValue().trim();
+                    String value = t.readRawValue().trim();
+                    addProperty(path, value);
                 }
-                String nodePath = PathUtils.getParentPath(path);
-                node.setPath(nodePath);
-                String propertyName = PathUtils.getName(path);
-                node.cloneAndSetProperty(propertyName, value, 0);
-                addOrRemoveRecursive(node, true, true);
                 break;
             }
             case '>':
@@ -321,10 +314,10 @@ public class Indexer {
         }
         for (Index index : indexes) {
             if (remove) {
-                index.remove(n);
+                index.addOrRemoveNode(n, false);
             }
             if (add) {
-                index.add(n);
+                index.addOrRemoveNode(n, true);
             }
         }
         for (Iterator<String> it = n.getChildNodeNames(); it.hasNext();) {
@@ -341,20 +334,33 @@ public class Indexer {
             // don't index the index
             return;
         }
-        String nodeName = PathUtils.getParentPath(path);
+        String nodePath = PathUtils.getParentPath(path);
         String property = PathUtils.getName(path);
-        String node = mk.getNodes(nodeName, lastRevision, 0, 0, 0);
+        String node = mk.getNodes(nodePath, lastRevision, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
         JsopTokenizer t = new JsopTokenizer(node);
         NodeMap map = new NodeMap();
         t.read('{');
-        NodeImpl n = NodeImpl.parse(map, t, 0, nodeName);
+        NodeImpl n = NodeImpl.parse(map, t, 0, path);
         if (n.hasProperty(property)) {
+            n.setPath(nodePath);
             for (Index index : indexes) {
-                index.remove(n);
+                index.addOrRemoveProperty(nodePath, property, n.getProperty(property), false);
             }
         }
     }
 
+    private void addProperty(String path, String value) {
+        if (isInIndex(path)) {
+            // don't index the index
+            return;
+        }
+        String nodePath = PathUtils.getParentPath(path);
+        String property = PathUtils.getName(path);
+        for (Index index : indexes) {
+            index.addOrRemoveProperty(nodePath, property, value, true);
+        }
+    }
+
     private void removeNode(String path, String lastRevision) {
         if (isInIndex(path)) {
             // don't index the index

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java?rev=1163945&r1=1163944&r2=1163945&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PrefixIndex.java
Thu Sep  1 08:47:42 2011
@@ -37,51 +37,42 @@ public class PrefixIndex implements Inde
         tree.setMinSize(10);
     }
 
-    public void add(NodeImpl node) {
-        addOrRemove(node, true);
-    }
-
-    public void remove(NodeImpl node) {
-        addOrRemove(node, false);
-    }
-
-    private void addOrRemove(NodeImpl node, boolean add) {
-        String path = null;
+    public void addOrRemoveNode(NodeImpl node, boolean add) {
+        String nodePath = node.getPath();
         for (Entry<String, String> e : node.getProperties()) {
             String propertyName = e.getKey();
             String value = e.getValue();
-            JsopTokenizer t = new JsopTokenizer(value);
-            if (t.matches(JsopTokenizer.STRING)) {
-                String v = t.getToken();
-                if (v.startsWith(prefix)) {
-                    if (path == null) {
-                        path = node.getPath();
-                    }
-                    addOrRemove(path, propertyName, v, add);
-                }
-            } else if (t.matches('[')) {
-                if (path == null) {
-                    path = node.getPath();
-                }
-                if (!t.matches(']')) {
-                    do {
-                        if (t.matches(JsopTokenizer.STRING)) {
-                            String v = t.getToken();
-                            if (v.startsWith(prefix)) {
-                                addOrRemove(path, propertyName, v, add);
-                            }
-                        } else if (t.matches(JsopTokenizer.FALSE)) {
-                            // ignore
-                        } else if (t.matches(JsopTokenizer.TRUE)) {
-                            // ignore
-                        } else if (t.matches(JsopTokenizer.NULL)) {
-                            // ignore
-                        } else if (t.matches(JsopTokenizer.NUMBER)) {
-                            // ignore
+            addOrRemoveProperty(nodePath, propertyName, value, add);
+        }
+    }
+
+    public void addOrRemoveProperty(String nodePath, String propertyName,
+            String value, boolean add) {
+        JsopTokenizer t = new JsopTokenizer(value);
+        if (t.matches(JsopTokenizer.STRING)) {
+            String v = t.getToken();
+            if (v.startsWith(prefix)) {
+                addOrRemove(nodePath, propertyName, v, add);
+            }
+        } else if (t.matches('[')) {
+            if (!t.matches(']')) {
+                do {
+                    if (t.matches(JsopTokenizer.STRING)) {
+                        String v = t.getToken();
+                        if (v.startsWith(prefix)) {
+                            addOrRemove(nodePath, propertyName, v, add);
                         }
-                    } while (t.matches(','));
-                    t.read(']');
-                }
+                    } else if (t.matches(JsopTokenizer.FALSE)) {
+                        // ignore
+                    } else if (t.matches(JsopTokenizer.TRUE)) {
+                        // ignore
+                    } else if (t.matches(JsopTokenizer.NULL)) {
+                        // ignore
+                    } else if (t.matches(JsopTokenizer.NUMBER)) {
+                        // ignore
+                    }
+                } while (t.matches(','));
+                t.read(']');
             }
         }
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java?rev=1163945&r1=1163944&r2=1163945&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
Thu Sep  1 08:47:42 2011
@@ -38,33 +38,33 @@ public class PropertyIndex implements In
         tree.setMinSize(10);
     }
 
-    public void add(NodeImpl node) {
+    public void addOrRemoveNode(NodeImpl node, boolean add) {
         String value = node.getProperty(propertyName);
         if (value != null) {
-            addOrRemoveRaw(value, node.getPath(), true);
+            addOrRemoveRaw(node.getPath(), value, add);
         }
     }
 
-    public void remove(NodeImpl node) {
-        String value = node.getProperty(propertyName);
-        if (value != null) {
-            addOrRemoveRaw(value, node.getPath(), false);
+    public void addOrRemoveProperty(String nodePath, String propertyName,
+            String value, boolean add) {
+        if (this.propertyName.equals(propertyName)) {
+            addOrRemoveRaw(nodePath, value, add);
         }
     }
 
-    private void addOrRemoveRaw(String value, String path, boolean add) {
+    private void addOrRemoveRaw(String nodePath, String value, boolean add) {
         JsopTokenizer t = new JsopTokenizer(value);
         if (t.matches(JsopTokenizer.STRING) || t.matches(JsopTokenizer.NUMBER)) {
             String v = t.getToken();
-            addOrRemove(v, path, add);
+            addOrRemove(nodePath, v, add);
         }
     }
 
-    private void addOrRemove(String value, String path, boolean add) {
+    private void addOrRemove(String nodePath, String value, boolean add) {
         if (add) {
-            tree.add(value, path);
+            tree.add(value, nodePath);
         } else {
-            tree.remove(value, path);
+            tree.remove(value, nodePath);
         }
     }
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1163945&r1=1163944&r2=1163945&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Thu Sep  1 08:47:42 2011
@@ -83,7 +83,7 @@ public class MemoryKernelImpl implements
 
     public static synchronized MemoryKernelImpl get(String name) {
         MemoryKernelImpl instance = INSTANCES.get(name);
-        if (instance == null) {
+        if (instance == null || instance.nodeMap.getRootId() == 0) {
             instance = new MemoryKernelImpl(name);
             INSTANCES.put(name, instance);
         }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java?rev=1163945&r1=1163944&r2=1163945&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
Thu Sep  1 08:47:42 2011
@@ -65,6 +65,11 @@ public class PrefixIndexTest extends Tes
         head = mk.commit("/", "+\"test6\" : {\"data\":[true, false, null, 1, -1]}", head,
null);
         assertEquals("/test2/blob2, /test4/blob4, /test5/blobs", getPathList(index, "d:2",
head));
 
+        head = mk.commit("/", "+\"test7\" : {\"a\":\"d:4\", \"b\":\"d:4\"}", head, null);
+        assertEquals("/test7/a, /test7/b", getPathList(index, "d:4", head));
+        head = mk.commit("/", "^\"test7/a\" : null", head, null);
+        assertEquals("/test7/b", getPathList(index, "d:4", head));
+
         mk.dispose();
     }
 



Mime
View raw message