Author: chetanm
Date: Mon Sep  4 08:08:56 2017
New Revision: 1807194

URL: http://svn.apache.org/viewvc?rev=1807194&view=rev
Log:
OAK-6612 - Refactor encoding logic in property index to utility class

Added:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUtil.java
   (with props)
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/PropertyIndexEditor.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/PropertyIndexPlan.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=1807194&r1=1807193&r2=1807194&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
 Mon Sep  4 08:08:56 2017
@@ -93,14 +93,6 @@ class PropertyIndex implements QueryInde
 
     private static final String PROPERTY = "property";
 
-    // TODO the max string length should be removed, or made configurable
-    private static final int MAX_STRING_LENGTH = 100;
-
-    /**
-     * name used when the indexed value is an empty string
-     */
-    private static final String EMPTY_TOKEN = ":";
-
     private static final Logger LOG = 
LoggerFactory.getLogger(PropertyIndex.class);
 
     private final MountInfoProvider mountInfoProvider;
@@ -113,33 +105,6 @@ class PropertyIndex implements QueryInde
     PropertyIndex(MountInfoProvider mountInfoProvider) {
         this.mountInfoProvider = mountInfoProvider;
     }
-    
-    static Set<String> encode(PropertyValue value, ValuePattern pattern) {
-        return encode(ValuePatternUtil.read(value, pattern));
-    }
-
-    static Set<String> encode(Set<String> set) {
-        if (set == null || set.isEmpty()) {
-            return set;
-        }
-        try {
-            Set<String> values = new HashSet<String>();
-            for(String v : set) {
-                if (v.length() > MAX_STRING_LENGTH) {
-                    v = v.substring(0, MAX_STRING_LENGTH);
-                }
-                if (v.isEmpty()) {
-                    v = EMPTY_TOKEN;
-                } else {
-                    v = URLEncoder.encode(v, Charsets.UTF_8.name());
-                }
-                values.add(v);
-            }
-            return values;
-        } catch (UnsupportedEncodingException e) {
-            throw new IllegalStateException("UTF-8 is unsupported", e);
-        }
-    }
 
     private PropertyIndexPlan getPlan(NodeState root, Filter filter) {
         // Reuse cached plan if the filter is the same (which should always be 
the case). The filter is compared as a

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java?rev=1807194&r1=1807193&r2=1807194&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
 Mon Sep  4 08:08:56 2017
@@ -28,7 +28,7 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.PROPERTY_NAMES;
-import static 
org.apache.jackrabbit.oak.plugins.index.property.PropertyIndex.encode;
+import static 
org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexUtil.encode;
 
 import java.util.Collections;
 import java.util.Set;

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=1807194&r1=1807193&r2=1807194&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
 Mon Sep  4 08:08:56 2017
@@ -23,7 +23,7 @@ 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 static 
org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexUtil.encode;
 
 import java.util.Collections;
 import java.util.List;

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java?rev=1807194&r1=1807193&r2=1807194&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexPlan.java
 Mon Sep  4 08:08:56 2017
@@ -159,7 +159,7 @@ public class PropertyIndexPlan {
                             continue;
                         }
                     }
-                    values = PropertyIndex.encode(values);
+                    values = PropertyIndexUtil.encode(values);
                     double cost = strategies.isEmpty() ? MAX_COST : 0;
                     for (IndexStoreStrategy strategy : strategies) {
                         cost += strategy.count(filter, root, definition,

Added: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUtil.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUtil.java?rev=1807194&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUtil.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUtil.java
 Mon Sep  4 08:08:56 2017
@@ -0,0 +1,65 @@
+/*
+ * 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.oak.plugins.index.property;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.HashSet;
+import java.util.Set;
+
+import com.google.common.base.Charsets;
+import org.apache.jackrabbit.oak.api.PropertyValue;
+
+public class PropertyIndexUtil {
+    // TODO the max string length should be removed, or made configurable
+    private static final int MAX_STRING_LENGTH = 100;
+
+    /**
+     * name used when the indexed value is an empty string
+     */
+    private static final String EMPTY_TOKEN = ":";
+
+    public static Set<String> encode(PropertyValue value, ValuePattern 
pattern) {
+        return encode(ValuePatternUtil.read(value, pattern));
+    }
+
+    public static Set<String> encode(Set<String> set) {
+        if (set == null || set.isEmpty()) {
+            return set;
+        }
+        try {
+            Set<String> values = new HashSet<String>();
+            for(String v : set) {
+                if (v.length() > MAX_STRING_LENGTH) {
+                    v = v.substring(0, MAX_STRING_LENGTH);
+                }
+                if (v.isEmpty()) {
+                    v = EMPTY_TOKEN;
+                } else {
+                    v = URLEncoder.encode(v, Charsets.UTF_8.name());
+                }
+                values.add(v);
+            }
+            return values;
+        } catch (UnsupportedEncodingException e) {
+            throw new IllegalStateException("UTF-8 is unsupported", e);
+        }
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to