jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1485969 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/property/ main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ test/java/org/apache/jackrabbit/oak/plugins/index/property/ t...
Date Fri, 24 May 2013 08:29:57 GMT
Author: alexparvulescu
Date: Fri May 24 08:29:57 2013
New Revision: 1485969

URL: http://svn.apache.org/r1485969
Log:
OAK-841 Indexing empty string fails with "there's already a child node with name ':index'"

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.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/PropertyIndexUpdate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/IndexStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java?rev=1485969&r1=1485968&r2=1485969&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
Fri May 24 08:29:57 2013
@@ -18,8 +18,8 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Type;
@@ -82,17 +82,29 @@ import com.google.common.base.Charsets;
 class PropertyIndex implements QueryIndex {
 
     // TODO the max string length should be removed, or made configurable
-    private static final int MAX_STRING_LENGTH = 100; 
-
-    static List<String> encode(PropertyValue value) {
-        List<String> values = new ArrayList<String>();
+    private static final int MAX_STRING_LENGTH = 100;
 
+    /**
+     * name used when the indexed value is an empty string
+     */
+    private static final String EMPTY_TOKEN = ":";
+
+    static Set<String> encode(PropertyValue value) {
+        if (value == null) {
+            return null;
+        }
+        Set<String> values = new HashSet<String>();
         for (String v : value.getValue(Type.STRINGS)) {
             try {
                 if (v.length() > MAX_STRING_LENGTH) {
                     v = v.substring(0, MAX_STRING_LENGTH);
                 }
-                values.add(URLEncoder.encode(v, Charsets.UTF_8.name()));
+                if (v.isEmpty()) {
+                    v = EMPTY_TOKEN;
+                } else {
+                    v = URLEncoder.encode(v, Charsets.UTF_8.name());
+                }
+                values.add(v);
             } catch (UnsupportedEncodingException e) {
                 throw new IllegalStateException("UTF-8 is unsupported", e);
             }

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=1485969&r1=1485968&r2=1485969&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
Fri May 24 08:29:57 2013
@@ -23,9 +23,9 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider.TYPE;
+import static org.apache.jackrabbit.oak.plugins.index.property.PropertyIndex.encode;
 
 import java.util.Iterator;
-import java.util.List;
 import java.util.Set;
 
 import javax.annotation.Nullable;
@@ -109,8 +109,7 @@ public class PropertyIndexLookup {
         if (state == null) {
             throw new IllegalArgumentException("No index for " + propertyName);
         }
-        List<String> values = value == null ? null : PropertyIndex.encode(value);
-        return store.query(filter, propertyName, state, values);
+        return store.query(filter, propertyName, state, encode(value));
     }
 
     public double getCost(Filter filter, String name, PropertyValue value) {
@@ -123,8 +122,7 @@ public class PropertyIndexLookup {
         if (state == null) {
             return Double.POSITIVE_INFINITY;
         }
-        List<String> it = value == null ? null : PropertyIndex.encode(value);
-        return store.count(state, it, MAX_COST);
+        return store.count(state, encode(value), MAX_COST);
     }
 
     /**

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=1485969&r1=1485968&r2=1485969&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
Fri May 24 08:29:57 2013
@@ -137,7 +137,7 @@ class PropertyIndexUpdate {
         if (unique && !modifiedKeys.isEmpty()) {
             NodeState state = index.getNodeState();
             for (String key : modifiedKeys) {
-                if (store.count(state, Collections.singletonList(key), 2) > 1) {
+                if (store.count(state, Collections.singleton(key), 2) > 1) {
                     throw new CommitFailedException(
                             "Constraint", 30,
                             "Uniqueness constraint violated for key " + key);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java?rev=1485969&r1=1485968&r2=1485969&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategy.java
Fri May 24 08:29:57 2013
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.plugin
 import java.util.Collections;
 import java.util.Deque;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
@@ -168,9 +167,9 @@ public class ContentMirrorStoreStrategy 
             }
         };
     }
-    
+
     @Override
-    public int count(NodeState index, List<String> values, int max) {
+    public int count(NodeState index, Set<String> values, int max) {
         int count = 0;
         if (values == null) {
             CountingNodeVisitor v = new CountingNodeVisitor(max);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/IndexStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/IndexStoreStrategy.java?rev=1485969&r1=1485968&r2=1485969&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/IndexStoreStrategy.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/IndexStoreStrategy.java
Fri May 24 08:29:57 2013
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.property.strategy;
 
-import java.util.List;
+import java.util.Set;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.spi.query.Filter;
@@ -71,6 +71,6 @@ public interface IndexStoreStrategy {
      * @param max the maximum value to return
      * @return the aggregated count of occurrences for each provided value
      */
-    int count(NodeState index, List<String> values, int max);
+    int count(NodeState index, Set<String> values, int max);
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java?rev=1485969&r1=1485968&r2=1485969&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
Fri May 24 08:29:57 2013
@@ -31,7 +31,6 @@ import org.apache.jackrabbit.oak.spi.lif
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -94,7 +93,6 @@ public class MultipleIndicesTest extends
     /**
      * Test for OAK-841
      */
-    @Ignore
     @Test
     public void emptyStringValue() throws CommitFailedException {
         Tree t = root.getTree("/");
@@ -104,5 +102,12 @@ public class MultipleIndicesTest extends
         t = root.getTree("/");
         t.addChild("node-2").setProperty("pid", "");
         root.commit();
+
+        setTravesalFallback(false);
+        assertQuery("select [jcr:path] from [nt:base] where [pid] = 'value'",
+                ImmutableList.of("/node-1"));
+        assertQuery("select [jcr:path] from [nt:base] where [pid] = ''",
+                ImmutableList.of("/node-2"));
+        setTravesalFallback(true);
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java?rev=1485969&r1=1485968&r2=1485969&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java
Fri May 24 08:29:57 2013
@@ -125,7 +125,7 @@ public class ContentMirrorStoreStrategyT
         store.insert(index, "key", Sets.newHashSet("b"));
         Assert.assertTrue(
                 "ContentMirrorStoreStrategy should guarantee uniqueness on insert",
-                store.count(index.getNodeState(), Collections.singletonList("key"), 2) >
1);
+                store.count(index.getNodeState(), Collections.singleton("key"), 2) > 1);
     }
 
 }



Mime
View raw message