jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1412613 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property: PropertyIndexDiff.java PropertyIndexHookProvider.java PropertyIndexLookup.java PropertyIndexProvider.java PropertyIndexUpdate.java
Date Thu, 22 Nov 2012 16:38:21 GMT
Author: thomasm
Date: Thu Nov 22 16:38:20 2012
New Revision: 1412613

URL: http://svn.apache.org/viewvc?rev=1412613&view=rev
Log:
JCR-3462 Documentation for the PropertyIndex

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHookProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java?rev=1412613&r1=1412612&r2=1412613&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java
Thu Nov 22 16:38:20 2012
@@ -41,7 +41,10 @@ import org.apache.jackrabbit.oak.spi.sta
 
 /**
  * {@link IndexHook} implementation that is responsible for keeping the
- * {@link PropertyIndex} up to date
+ * {@link PropertyIndex} up to date.
+ * <p>
+ * There is a tree of PropertyIndexDiff objects, each object represents the
+ * changes at a given node.
  * 
  * @see PropertyIndex
  * @see PropertyIndexLookup
@@ -49,14 +52,30 @@ import org.apache.jackrabbit.oak.spi.sta
  */
 class PropertyIndexDiff implements IndexHook {
 
+    /**
+     * The parent (null if this is the root node).
+     */
     private final PropertyIndexDiff parent;
 
+    /**
+     * The node (never null).
+     */
     private final NodeBuilder node;
 
+    /**
+     * The node name (the path element). Null for the root node.
+     */
     private final String name;
 
+    /**
+     * The path of the changed node (built lazily).
+     */
     private String path;
 
+    /**
+     * 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<PropertyIndexUpdate>> updates;
 
     private PropertyIndexDiff(
@@ -98,13 +117,21 @@ class PropertyIndexDiff implements Index
         }
     }
 
+    @Override
     public String getPath() {
-        if (path == null) { // => parent != null
+        // build the path lazily
+        if (path == null) {
             path = concat(parent.getPath(), name);
         }
         return path;
     }
 
+    /**
+     * Get all the indexes for the given property name.
+     * 
+     * @param name the property name
+     * @return the indexes
+     */
     private Iterable<PropertyIndexUpdate> getIndexes(String name) {
         List<PropertyIndexUpdate> indexes = updates.get(name);
         if (indexes != null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHookProvider.java?rev=1412613&r1=1412612&r2=1412613&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexHookProvider.java
Thu Nov 22 16:38:20 2012
@@ -29,7 +29,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import com.google.common.collect.ImmutableList;
 
 /**
- * Service that provides PropertyIndex based IndexHooks
+ * Service that provides PropertyIndex based IndexHooks.
  * 
  * @see PropertyIndexDiff
  * @see IndexHookProvider

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java?rev=1412613&r1=1412612&r2=1412613&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
Thu Nov 22 16:38:20 2012
@@ -58,17 +58,20 @@ public class PropertyIndexLookup {
     }
 
     /**
-     * Checks whether the named properties are indexed somewhere
-     * along the given path.
-     *
+     * Checks whether the named property is indexed somewhere along the given
+     * path. Lookup starts at the current path (at the root of this object) and
+     * traverses down the path.
+     * 
      * @param name property name
      * @param path lookup path
+     * @return true if the property is indexed
      */
     public boolean isIndexed(String name, String path) {
         if (getIndexDefinitionNode(name) != null) {
             return true;
         }
 
+        // TODO use PathUtils
         if (path.startsWith("/")) {
             path = path.substring(1);
         }
@@ -85,12 +88,11 @@ public class PropertyIndexLookup {
     /**
      * Searches for a given <code>String<code> value within this index.
      * 
-     * <p><b>Note</b> if the property you are looking for is not of type
<code>String<code>, the converted key value might not match the index key, and
there will be no hits on the index.</p>
+     * <p><b>Note</b> if the property you are looking for is not of type
<code>String<code>, 
+     * the converted key value might not match the index key, and there will be no hits on
the index.</p>
      * 
-     * @param name
-     *            the property name
-     * @param value
-     *            the property value
+     * @param name the property name
+     * @param value the property value
      * @return the set of matched paths
      */
     public Set<String> find(String name, String value) {
@@ -175,6 +177,13 @@ public class PropertyIndexLookup {
         return cost;
     }
 
+    /**
+     * Get the node with the index definition node for the given property.
+     * 
+     * @param name the property name
+     * @return the node where the index definition is stored, or null if no
+     *         index definition node was found
+     */
     @Nullable
     private NodeState getIndexDefinitionNode(String name) {
         NodeState state = root.getChildNode(INDEX_DEFINITIONS_NAME);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexProvider.java?rev=1412613&r1=1412612&r2=1412613&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexProvider.java
Thu Nov 22 16:38:20 2012
@@ -28,6 +28,9 @@ import com.google.common.collect.Immutab
 
 /**
  * A provider for property indexes.
+ * <p>
+ * Even if there are multiple index definitions, there is only actually one
+ * PropertyIndex instance, which is used for all indexes.
  * 
  * @see PropertyIndex
  * 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java?rev=1412613&r1=1412612&r2=1412613&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java
Thu Nov 22 16:38:20 2012
@@ -37,16 +37,34 @@ import org.apache.jackrabbit.oak.spi.sta
 
 /**
  * Takes care of applying the updates to the index content.
- * 
+ * <p>
+ * The changes are temporarily added to an in-memory structure, and then applied
+ * to the node.
  */
 class PropertyIndexUpdate {
 
+    /**
+     * The path of the index definition (where the index data is stored).
+     */
     private final String path;
 
+    /**
+     * The node where the index definition is stored.
+     */
     private final NodeBuilder node;
 
+    /**
+     * The set of added values / paths. The key of the map is the property value
+     * (encoded as a string), the value of the map is a set of paths that where
+     * added.
+     */
     private final Map<String, Set<String>> insert;
 
+    /**
+     * The set of removed values / paths. The key of the map is the property
+     * value (encoded as a string), the value of the map is a set of paths that
+     * were removed.
+     */
     private final Map<String, Set<String>> remove;
 
     public PropertyIndexUpdate(String path, NodeBuilder node) {
@@ -60,11 +78,23 @@ class PropertyIndexUpdate {
         return path;
     }
 
+    /**
+     * A property value was added at the given path.
+     * 
+     * @param path the path
+     * @param value the value
+     */
     public void insert(String path, PropertyState value) {
         Preconditions.checkArgument(path.startsWith(this.path));
         putValues(insert, path.substring(this.path.length()), value);
     }
 
+    /**
+     * A property value was removed at the given path.
+     * 
+     * @param path the path
+     * @param value the value
+     */
     public void remove(String path, PropertyState value) {
         Preconditions.checkArgument(path.startsWith(this.path));
         putValues(remove, path.substring(this.path.length()), value);
@@ -93,6 +123,11 @@ class PropertyIndexUpdate {
         return reindex;
     }
 
+    /**
+     * Try to apply the changes to the index content (to the ":index" node.
+     * 
+     * @throws CommitFailedException if a unique index was violated
+     */
     public void apply() throws CommitFailedException {
         boolean unique = node.getProperty("unique") != null
                 && node.getProperty("unique").getValue(Type.BOOLEAN);



Mime
View raw message