jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1397035 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-core/src/main/java/org/apache/jackrabbit/oak/util/ oak-core/src/mai...
Date Thu, 11 Oct 2012 13:22:29 GMT
Author: mduerig
Date: Thu Oct 11 13:22:29 2012
New Revision: 1397035

URL: http://svn.apache.org/viewvc?rev=1397035&view=rev
Log:
OAK-350: Unify PropertyState and CoreValue
- Replace CoreValue with Value in NodeDelegate and PropertyDelegate

Removed:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueConverter.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
Thu Oct 11 13:22:29 2012
@@ -26,6 +26,7 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.json.JsopReader;
@@ -74,12 +75,13 @@ public final class PropertyStates {
     }
 
     @Nonnull
-    public static PropertyState createProperty(String name, Value[] values) throws RepositoryException
{
-        if (values.length == 0) {
+    public static PropertyState createProperty(String name, Iterable<Value> values)
throws RepositoryException {
+        Value first = Iterables.getFirst(values, null);
+        if (first == null) {
             return emptyProperty(name, STRINGS);
         }
 
-        int type = values[0].getType();
+        int type = first.getType();
         switch (type) {
             case PropertyType.STRING:
                 List<String> strings = Lists.newArrayList();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
Thu Oct 11 13:22:29 2012
@@ -36,9 +36,9 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.core.ReadOnlyTree;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.memory.CoreValues;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.value.ValueImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -247,29 +247,29 @@ class TypeValidator implements Validator
                 return;
             }
             if (property.isArray()) {
-                checkSetProperty(property.getName(), CoreValues.getValues(property));
+                List<Value> values = ValueFactoryImpl.createValues(property, mapper);
+                checkSetProperty(property.getName(), values);
             }
             else {
-                checkSetProperty(property.getName(), CoreValues.getValue(property));
+                Value value = ValueFactoryImpl.createValue(property, mapper);
+                checkSetProperty(property.getName(), value);
             }
         }
 
-        private void checkSetProperty(final String propertyName, final List<CoreValue>
values)
+        private void checkSetProperty(final String propertyName, List<Value> values)
                 throws ConstraintViolationException {
-            Value[] jcrValues = jcrValues(values);
+            Value[] valueArray = values.toArray(new Value[values.size()]);
             for (NodeType nodeType : allTypes) {
-                if (nodeType.canSetProperty(propertyName, jcrValues)) {
+                if (nodeType.canSetProperty(propertyName, valueArray)) {
                     return;
                 }
             }
             throw new ConstraintViolationException("Cannot set property '" + propertyName
+ "' to '" + values + '\'');
         }
 
-        private void checkSetProperty(final String propertyName, final CoreValue value)
-                throws ConstraintViolationException {
-            Value jcrValue = jcrValue(value);
+        private void checkSetProperty(final String propertyName, Value value) throws ConstraintViolationException
{
             for (NodeType nodeType : allTypes) {
-                if (nodeType.canSetProperty(propertyName, jcrValue)) {
+                if (nodeType.canSetProperty(propertyName, value)) {
                     return;
                 }
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Thu Oct 11 13:22:29 2012
@@ -213,7 +213,7 @@ public class NodeUtil {
 
     public void setValues(String name, Value[] values) {
         try {
-            tree.setProperty(PropertyStates.createProperty(name, values));
+            tree.setProperty(PropertyStates.createProperty(name, Arrays.asList(values)));
         }
         catch (RepositoryException e) {
             log.warn("Unable to convert a default value", e);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
Thu Oct 11 13:22:29 2012
@@ -22,6 +22,8 @@ import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.util.Calendar;
+import java.util.List;
+
 import javax.jcr.Binary;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
@@ -30,10 +32,13 @@ import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.ValueFormatException;
 
+import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+import org.apache.jackrabbit.oak.plugins.memory.CoreValues;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -74,6 +79,19 @@ public class ValueFactoryImpl implements
         return new ValueImpl(coreValue, namePathMapper);
     }
 
+    public static Value createValue(PropertyState property, NamePathMapper namePathMapper)
{
+        return new ValueImpl(CoreValues.getValue(property), namePathMapper);
+    }
+
+    public static List<Value> createValues(PropertyState property, NamePathMapper namePathMapper)
{
+        List<CoreValue> cvs = CoreValues.getValues(property);
+        List<Value> vs = Lists.newArrayList();
+        for (CoreValue cv : cvs) {
+            vs.add(new ValueImpl(cv, namePathMapper));
+        }
+        return vs;
+    }
+
     public CoreValue getCoreValue(Value jcrValue) {
         ValueImpl v;
         if (jcrValue instanceof ValueImpl) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Thu Oct 11 13:22:29 2012
@@ -199,7 +199,7 @@ public class NodeDelegate extends ItemDe
      * @return  the set property
      */
     @Nonnull
-    public PropertyDelegate setProperty(String name, Value[] values) throws RepositoryException
{
+    public PropertyDelegate setProperty(String name, Iterable<Value> values) throws
RepositoryException {
         Tree tree = getTree();
         PropertyState old = tree.getProperty(name);
         if (old != null && ! old.isArray()) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Thu Oct 11 13:22:29 2012
@@ -18,8 +18,9 @@ package org.apache.jackrabbit.oak.jcr;
 
 import java.io.InputStream;
 import java.math.BigDecimal;
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -54,21 +55,19 @@ import javax.jcr.version.VersionHistory;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.ItemNameMatcher;
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.jcr.value.ValueConverter;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
 import org.apache.jackrabbit.oak.util.TODO;
@@ -352,13 +351,11 @@ public class NodeImpl extends ItemImpl<N
                     return p;
                 } else {
                     String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
-                    ArrayList<Value> vs = Lists.newArrayList();
-                    for (Value targetValue : targetValues) {
-                        if (targetValue != null) {
-                            vs.add(targetValue);
-                        }
-                    }
-                    return new PropertyImpl(dlg.setProperty(oakName, vs.toArray(new Value[vs.size()])));
+                    Iterable<Value> nonNullValues = Iterables.filter(
+                            Arrays.asList(targetValues),
+                            Predicates.notNull());
+
+                    return new PropertyImpl(dlg.setProperty(oakName, nonNullValues));
                 }
             }
         });
@@ -936,32 +933,25 @@ public class NodeImpl extends ItemImpl<N
                 // TODO: END
 
                 PropertyDelegate mixins = dlg.getProperty(JcrConstants.JCR_MIXINTYPES);
-                CoreValue cv = ValueConverter.toCoreValue(mixinName, PropertyType.NAME, sessionDelegate);
+                Value value = sessionDelegate.getValueFactory().createValue(mixinName, PropertyType.NAME);
 
                 boolean nodeModified = false;
                 if (mixins == null) {
                     nodeModified = true;
-                    Value name = sessionDelegate.getValueFactory().createValue(mixinName,
PropertyType.NAME);
-                    dlg.setProperty(JcrConstants.JCR_MIXINTYPES, new Value[]{name});
+                    dlg.setProperty(JcrConstants.JCR_MIXINTYPES, Collections.singletonList(value));
                 } else {
-                    List<CoreValue> values = Lists.newArrayList(mixins.getValues());
-                    if (!values.contains(cv)) {
-                        values.add(cv);
+                    List<Value> values = mixins.getValues();
+                    if (!values.contains(value)) {
+                        values.add(value);
                         nodeModified = true;
-                        Value[] jcvValues = new Value[values.size()];
-                        int k = 0;
-                        for (CoreValue v : values) {
-                            jcvValues[k++] = sessionDelegate.getValueFactory().createValue(cv);
-                        }
-
-                        dlg.setProperty(JcrConstants.JCR_MIXINTYPES, jcvValues);
+                        dlg.setProperty(JcrConstants.JCR_MIXINTYPES, values);
                     }
                 }
 
                 // TODO: hack -- make sure we assign a UUID
                 if (nodeModified && nt.isNodeType(JcrConstants.MIX_REFERENCEABLE))
{
-                    Value value = sessionDelegate.getValueFactory().createValue(IdentifierManager.generateUUID());
-                    dlg.setProperty(JcrConstants.JCR_UUID, value);
+                    Value uuid = sessionDelegate.getValueFactory().createValue(IdentifierManager.generateUUID());
+                    dlg.setProperty(JcrConstants.JCR_UUID, uuid);
                 }
                 return null;
             }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
Thu Oct 11 13:22:29 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import java.util.List;
+
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.RepositoryException;
@@ -24,13 +26,12 @@ import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.core.TreeImpl.PropertyLocation;
-import org.apache.jackrabbit.oak.plugins.memory.CoreValues;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.util.TODO;
+import org.apache.jackrabbit.oak.value.ValueFactoryImpl;
 
 /**
  * {@code PropertyDelegate} serve as internal representations of {@code Property}s.
@@ -47,22 +48,21 @@ public class PropertyDelegate extends It
     /**
      * Get the value of the property
      * @return  the value of the property
-     * @throws IllegalStateException  if {@code isMultivalue()} is {@code true}.
-     *
+     * @throws InvalidItemStateException
      */
     @Nonnull
-    public CoreValue getValue() throws InvalidItemStateException {
-        return CoreValues.getValue(getPropertyState());
+    public Value getValue() throws InvalidItemStateException {
+        return ValueFactoryImpl.createValue(getPropertyState(), sessionDelegate.getNamePathMapper());
     }
 
     /**
-     * Get the value of the property
+     * Get the values of the property
      * @return  the values of the property
-     * @throws IllegalStateException  if {@code isMultivalue()} is {@code false}.
+     * @throws InvalidItemStateException
      */
     @Nonnull
-    public Iterable<CoreValue> getValues() throws InvalidItemStateException {
-        return CoreValues.getValues(getPropertyState());
+    public List<Value> getValues() throws InvalidItemStateException {
+        return ValueFactoryImpl.createValues(getPropertyState(), sessionDelegate.getNamePathMapper());
     }
 
     /**
@@ -188,7 +188,7 @@ public class PropertyDelegate extends It
      * Set the values of the property
      * @param values
      */
-    public void setValues(Value[] values) throws RepositoryException {
+    public void setValues(Iterable<Value> values) throws RepositoryException {
         getLocation().set(PropertyStates.createProperty(getName(), values));
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1397035&r1=1397034&r2=1397035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Thu Oct 11 13:22:29 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.jcr;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.List;
 
@@ -37,9 +38,9 @@ import javax.jcr.ValueFormatException;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 
-import com.google.common.collect.Lists;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Tree.Status;
-import org.apache.jackrabbit.oak.jcr.value.ValueConverter;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -355,7 +356,7 @@ public class PropertyImpl extends ItemIm
                     throw new ValueFormatException(this + " is multi-valued.");
                 }
 
-                return ValueConverter.toValue(dlg.getValue(), sessionDelegate);
+                return dlg.getValue();
             }
         });
     }
@@ -372,7 +373,7 @@ public class PropertyImpl extends ItemIm
                     throw new ValueFormatException(this + " is not multi-valued.");
                 }
 
-                return ValueConverter.toValues(dlg.getValues(), sessionDelegate);
+                return Iterables.toArray(dlg.getValues(), Value.class);
             }
         });
     }
@@ -696,14 +697,11 @@ public class PropertyImpl extends ItemIm
             dlg.remove();
         } else {
             Value[] targetValues = ValueHelper.convert(values, requiredType, sessionDelegate.getValueFactory());
-            List<Value> vs = Lists.newArrayList();
-            for (Value value : targetValues) {
-                if (value != null) {
-                    vs.add(value);
-                }
-            }
+            Iterable<Value> nonNullValues = Iterables.filter(
+                    Arrays.asList(targetValues),
+                    Predicates.notNull());
 
-            dlg.setValues(vs.toArray(new Value[vs.size()]));
+            dlg.setValues(nonNullValues);
         }
     }
 



Mime
View raw message