jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1444688 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index: IndexHookManagerDiff.java p2/Property2IndexDiff.java
Date Mon, 11 Feb 2013 09:27:20 GMT
Author: thomasm
Date: Mon Feb 11 09:27:19 2013
New Revision: 1444688

URL: http://svn.apache.org/r1444688
Log:
OAK-590 Value type index implementation (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java?rev=1444688&r1=1444687&r2=1444688&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
Mon Feb 11 09:27:19 2013
@@ -69,9 +69,11 @@ class IndexHookManagerDiff implements No
     private String path;
 
     /**
-     * <type, <path, indexhook>>
+     * The map of known indexes.
+     * 
+     * Key: index type name ("p2"). Value: a map from path to index hook.
      */
-    private final Map<String, Map<String, List<IndexHook>>> updates;
+    private final Map<String, Map<String, List<IndexHook>>> indexMap;
 
     public IndexHookManagerDiff(IndexHookProvider provider, NodeBuilder root,
             Map<String, Map<String, List<IndexHook>>> updates)
@@ -83,7 +85,7 @@ class IndexHookManagerDiff implements No
             IndexHookManagerDiff parent, String name)
             throws CommitFailedException {
         this(provider, parent, getChildNode(parent.node, name), name, null,
-                parent.updates);
+                parent.indexMap);
     }
 
     private IndexHookManagerDiff(IndexHookProvider provider,
@@ -95,7 +97,7 @@ class IndexHookManagerDiff implements No
         this.node = node;
         this.name = name;
         this.path = path;
-        this.updates = updates;
+        this.indexMap = updates;
 
         if (node != null && isIndexNodeType(node.getProperty(JCR_PRIMARYTYPE))) {
             // to prevent double-reindex we only call reindex if:
@@ -153,10 +155,10 @@ class IndexHookManagerDiff implements No
             existingTypes.remove(TYPE_UNKNOWN);
             reindexTypes.remove(TYPE_UNKNOWN);
             for (String type : existingTypes) {
-                Map<String, List<IndexHook>> byType = this.updates.get(type);
+                Map<String, List<IndexHook>> byType = this.indexMap.get(type);
                 if (byType == null) {
                     byType = new TreeMap<String, List<IndexHook>>();
-                    this.updates.put(type, byType);
+                    this.indexMap.put(type, byType);
                 }
                 List<IndexHook> hooks = byType.get(getPath());
                 if (hooks == null) {
@@ -186,7 +188,8 @@ class IndexHookManagerDiff implements No
     }
 
     private String getPath() {
-        if (path == null) { // => parent != null
+        if (path == null) { 
+            // => parent != null
             path = concat(parent.getPath(), name);
         }
         return path;
@@ -198,7 +201,7 @@ class IndexHookManagerDiff implements No
      */
     private Map<String, List<IndexHook>> getIndexes() {
         Map<String, List<IndexHook>> hooks = new HashMap<String, List<IndexHook>>();
-        for (String type : this.updates.keySet()) {
+        for (String type : this.indexMap.keySet()) {
             Map<String, List<IndexHook>> newIndexes = getIndexes(type);
             for (String key : newIndexes.keySet()) {
                 if (hooks.containsKey(key)) {
@@ -217,7 +220,7 @@ class IndexHookManagerDiff implements No
      */
     private Map<String, List<IndexHook>> getIndexes(String type) {
         Map<String, List<IndexHook>> hooks = new HashMap<String, List<IndexHook>>();
-        Map<String, List<IndexHook>> indexes = this.updates.get(type);
+        Map<String, List<IndexHook>> indexes = this.indexMap.get(type);
         if (indexes != null && !indexes.isEmpty()) {
             Iterator<String> iterator = indexes.keySet().iterator();
             String bestMatch = iterator.next();
@@ -243,7 +246,7 @@ class IndexHookManagerDiff implements No
      * Fixes the relative paths on the best matching indexes so updates apply
      * properly
      */
-    private List<IndexHook> getIndexesWithRelativePaths(String path,
+    private static List<IndexHook> getIndexesWithRelativePaths(String path,
             Map<String, List<IndexHook>> bestMatches) {
         List<IndexHook> hooks = new ArrayList<IndexHook>();
         for (String relativePath : bestMatches.keySet()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java?rev=1444688&r1=1444687&r2=1444688&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexDiff.java
Mon Feb 11 09:27:19 2013
@@ -82,10 +82,21 @@ class Property2IndexDiff implements Inde
     private String path;
 
     /**
+     * The map of known indexes.
      * Key: the property name. Value: the list of indexes (it is possible to
      * have multiple indexes for the same property name).
      */
-    private final Map<String, List<Property2IndexUpdate>> updates;
+    private final Map<String, List<Property2IndexUpdate>> indexMap;
+
+    public Property2IndexDiff(NodeBuilder root) {
+        this(null, root, null, "/",
+                new HashMap<String, List<Property2IndexUpdate>>());
+    }
+
+    private Property2IndexDiff(Property2IndexDiff parent, String name) {
+        this(parent, getChildNode(parent.node, name),
+                name, null, parent.indexMap);
+    }
 
     private Property2IndexDiff(
             Property2IndexDiff parent,
@@ -95,29 +106,19 @@ class Property2IndexDiff implements Inde
         this.node = node;
         this.name = name;
         this.path = path;
-        this.updates = updates;
+        this.indexMap = updates;
 
         if (node != null && node.hasChildNode(INDEX_DEFINITIONS_NAME)) {
             NodeBuilder index = node.child(INDEX_DEFINITIONS_NAME);
             for (String indexName : index.getChildNodeNames()) {
                 NodeBuilder child = index.child(indexName);
                 if (isIndexNode(child)) {
-                    update(child, indexName);
+                    addIndexes(child, indexName);
                 }
             }
         }
     }
 
-    private Property2IndexDiff(Property2IndexDiff parent, String name) {
-        this(parent, getChildNode(parent.node, name),
-                name, null, parent.updates);
-    }
-
-    public Property2IndexDiff(NodeBuilder root) {
-        this(null, root, null, "/",
-                new HashMap<String, List<Property2IndexUpdate>>());
-    }
-
     private static NodeBuilder getChildNode(NodeBuilder node, String name) {
         if (node != null && node.hasChildNode(name)) {
             return node.child(name);
@@ -142,7 +143,7 @@ class Property2IndexDiff implements Inde
      * @return the indexes
      */
     private Iterable<Property2IndexUpdate> getIndexes(String name) {
-        List<Property2IndexUpdate> indexes = updates.get(name);
+        List<Property2IndexUpdate> indexes = indexMap.get(name);
         if (indexes == null) {
             return ImmutableList.of();
         }
@@ -168,7 +169,13 @@ class Property2IndexDiff implements Inde
         return filtered;
     }
 
-    private void update(NodeBuilder builder, String indexName) {
+    /**
+     * Add the index definitions to the in-memory set of known index definitions.
+     * 
+     * @param builder the node builder that contains the index definition
+     * @param indexName the name of the index
+     */
+    private void addIndexes(NodeBuilder builder, String indexName) {
         List<String> typeNames = ImmutableList.of();
         PropertyState appliesTo = builder.getProperty(declaringNodeTypes);
         if (appliesTo != null) {
@@ -179,10 +186,10 @@ class Property2IndexDiff implements Inde
         Iterable<String> propertyNames = ps != null ? ps.getValue(Type.STRINGS)
                 : ImmutableList.of(indexName);
         for (String pname : propertyNames) {
-            List<Property2IndexUpdate> list = this.updates.get(pname);
+            List<Property2IndexUpdate> list = this.indexMap.get(pname);
             if (list == null) {
                 list = newArrayList();
-                this.updates.put(pname, list);
+                this.indexMap.put(pname, list);
             }
             boolean exists = false;
             for (Property2IndexUpdate piu : list) {
@@ -256,7 +263,7 @@ class Property2IndexDiff implements Inde
 
     @Override
     public void apply() throws CommitFailedException {
-        for (List<Property2IndexUpdate> updateList : updates.values()) {
+        for (List<Property2IndexUpdate> updateList : indexMap.values()) {
             for (Property2IndexUpdate update : updateList) {
                 update.apply();
             }
@@ -266,7 +273,7 @@ class Property2IndexDiff implements Inde
     @Override
     public void reindex(NodeBuilder state) throws CommitFailedException {
         boolean reindex = false;
-        for (List<Property2IndexUpdate> updateList : updates.values()) {
+        for (List<Property2IndexUpdate> updateList : indexMap.values()) {
             for (Property2IndexUpdate update : updateList) {
                 if (update.getAndResetReindexFlag()) {
                     reindex = true;
@@ -276,7 +283,7 @@ class Property2IndexDiff implements Inde
         if (reindex) {
             state.getNodeState().compareAgainstBaseState(
                     MemoryNodeState.EMPTY_NODE,
-                    new Property2IndexDiff(null, state, null, "/", updates));
+                    new Property2IndexDiff(null, state, null, "/", indexMap));
         }
     }
 
@@ -287,6 +294,6 @@ class Property2IndexDiff implements Inde
 
     @Override
     public void close() throws IOException {
-        updates.clear();
+        indexMap.clear();
     }
 }



Mime
View raw message