jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1400044 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins: index/property/PropertyIndexUpdate.java memory/MemoryPropertyBuilder.java
Date Fri, 19 Oct 2012 11:26:48 GMT
Author: mduerig
Date: Fri Oct 19 11:26:48 2012
New Revision: 1400044

URL: http://svn.apache.org/viewvc?rev=1400044&view=rev
Log:
OAK-389: Simplify code by using PropertyBuilder

Modified:
    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/memory/MemoryPropertyBuilder.java

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=1400044&r1=1400043&r2=1400044&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 Oct 19 11:26:48 2012
@@ -23,15 +23,15 @@ import java.util.Set;
 import javax.jcr.PropertyType;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryPropertyBuilder;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.PropertyBuilder;
 
 /**
  * Takes care of applying the updates to the index content.
@@ -88,16 +88,16 @@ class PropertyIndexUpdate {
             Set<String> paths = entry.getValue();
             PropertyState property = index.getProperty(encoded);
             if (property != null) {
-                List<String> values = Lists.newArrayList();
+                PropertyBuilder<String> builder = MemoryPropertyBuilder.create(Type.STRING).setName(encoded);
                 for (String value : property.getValue(Type.STRINGS)) {
-                    if (!paths.contains(values)) {
-                        values.add(value);
+                    if (!paths.contains(builder)) {
+                        builder.addValue(value);
                     }
                 }
-                if (values.isEmpty()) {
+                if (builder.isEmpty()) {
                     index.removeProperty(encoded);
                 } else {
-                    index.setProperty(PropertyStates.stringProperty(encoded, values));
+                    index.setProperty(builder.getPropertyState(true));
                 }
             }
         }
@@ -105,25 +105,22 @@ class PropertyIndexUpdate {
         for (Map.Entry<String, Set<String>> entry : insert.entrySet()) {
             String encoded = entry.getKey();
             Set<String> paths = entry.getValue();
-            List<String> values = Lists.newArrayList();
             PropertyState property = index.getProperty(encoded);
-            if (property != null) {
-                for (String value : property.getValue(Type.STRINGS)) {
-                    values.add(value);
-                    paths.remove(value);
-                }
-            }
+            PropertyBuilder<String> builder = MemoryPropertyBuilder.create(Type.STRING)
+                    .setName(encoded)
+                    .assignFrom(property);
             for (String path : paths) {
-                values.add(path);
+                if (!builder.hasValue(path)) {
+                    builder.addValue(path);
+                }
             }
-            if (values.isEmpty()) {
+            if (builder.isEmpty()) {
                 index.removeProperty(encoded);
-            } else if (unique && values.size() > 1) {
+            } else if (unique && builder.count() > 1) {
                 throw new CommitFailedException(
                         "Uniqueness constraint violated");
             } else {
-                index.setProperty(PropertyStates
-                        .stringProperty(encoded, values));
+                index.setProperty(builder.getPropertyState(true));
             }
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java?rev=1400044&r1=1400043&r2=1400044&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java
Fri Oct 19 11:26:48 2012
@@ -147,7 +147,7 @@ public class MemoryPropertyBuilder<T> im
     public PropertyState getPropertyState(boolean asArray) {
         checkState(name != null, "Property has no name");
         if (values.isEmpty()) {
-            return PropertyStates.emptyProperty(name, type);
+            return PropertyStates.emptyProperty(name, Type.fromTag(type.tag(), true));
         }
         else if (isArray() || asArray) {
             switch (type.tag()) {



Mime
View raw message