jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1456027 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeImpl.java PropertyImpl.java delegate/NodeDelegate.java delegate/PropertyDelegate.java delegate/VersionHistoryDelegate.java version/VersionImpl.java
Date Wed, 13 Mar 2013 16:25:36 GMT
Author: mduerig
Date: Wed Mar 13 16:25:36 2013
New Revision: 1456027

URL: http://svn.apache.org/r1456027
Log:
OAK-672: Avoid JCR APIs calling other JCR APIs
- Remove Value and ValueFactory dependencies from Delegate implementations

Modified:
    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/PropertyImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java

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=1456027&r1=1456026&r2=1456027&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
Wed Mar 13 16:25:36 2013
@@ -80,6 +80,7 @@ import org.apache.jackrabbit.oak.core.Id
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionOperation;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;
@@ -992,14 +993,15 @@ public class NodeImpl<T extends NodeDele
                 boolean nodeModified = false;
                 if (mixins == null) {
                     nodeModified = true;
-                    dlg.setProperty(JcrConstants.JCR_MIXINTYPES, Collections.singletonList(value));
+                    dlg.setProperty(PropertyStates.createProperty(
+                            JcrConstants.JCR_MIXINTYPES, Collections.singletonList(value)));
                 } else {
-                    PropertyState property = mixins.getMulti();
+                    PropertyState property = mixins.getMultiState();
                     List<Value> values = getValueFactory().createValues(property);
                     if (!values.contains(value)) {
                         values.add(value);
                         nodeModified = true;
-                        dlg.setProperty(JcrConstants.JCR_MIXINTYPES, values);
+                        dlg.setProperty(PropertyStates.createProperty(JcrConstants.JCR_MIXINTYPES,
values));
                     }
                 }
 
@@ -1441,9 +1443,9 @@ public class NodeImpl<T extends NodeDele
         for (PropertyDefinition pd : effective.getAutoCreatePropertyDefinitions()) {
             if (dlg.getProperty(pd.getName()) == null) {
                 if (pd.isMultiple()) {
-                    dlg.setProperty(pd.getName(), getAutoCreatedValues(pd));
+                    dlg.setProperty(PropertyStates.createProperty(pd.getName(), getAutoCreatedValues(pd)));
                 } else {
-                    dlg.setProperty(pd.getName(), getAutoCreatedValue(pd));
+                    dlg.setProperty(PropertyStates.createProperty(pd.getName(), getAutoCreatedValue(pd)));
                 }
             }
         }
@@ -1541,10 +1543,9 @@ public class NodeImpl<T extends NodeDele
 
                 String jcrPrimaryType = getOakPath(Property.JCR_PRIMARY_TYPE);
                 Value value = getValueFactory().createValue(nodeTypeName, PropertyType.NAME);
-                dlg.setProperty(jcrPrimaryType, value);
 
+                dlg.setProperty(PropertyStates.createProperty(jcrPrimaryType, value));
                 dlg.setOrderableChildren(nt.hasOrderableChildNodes());
-
                 return null;
             }
         });
@@ -1592,7 +1593,7 @@ public class NodeImpl<T extends NodeDele
                         targetValue = ValueHelper.convert(value, targetType, getValueFactory());
                     }
 
-                    return new PropertyImpl(dlg.setProperty(oakName, targetValue));
+                    return new PropertyImpl(dlg.setProperty(PropertyStates.createProperty(oakName,
targetValue)));
                 }
             }
         });
@@ -1642,7 +1643,7 @@ public class NodeImpl<T extends NodeDele
                     Iterable<Value> nonNullValues = Iterables.filter(
                             Arrays.asList(targetValues),
                             Predicates.notNull());
-                    return new PropertyImpl(dlg.setProperty(oakName, nonNullValues));
+                    return new PropertyImpl(dlg.setProperty(PropertyStates.createProperty(oakName,
nonNullValues)));
                 }
             }
         });

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=1456027&r1=1456026&r2=1456027&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
Wed Mar 13 16:25:36 2013
@@ -43,6 +43,7 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionOperation;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -364,7 +365,7 @@ public class PropertyImpl extends ItemIm
 
             @Override
             public Value perform() throws RepositoryException {
-                return getValueFactory().createValue(dlg.getSingle());
+                return getValueFactory().createValue(dlg.getSingleState());
             }
         });
     }
@@ -380,7 +381,7 @@ public class PropertyImpl extends ItemIm
 
             @Override
             public List<Value> perform() throws RepositoryException {
-                return getValueFactory().createValues(dlg.getMulti());
+                return getValueFactory().createValues(dlg.getMultiState());
             }
         }).toArray(NO_VALUES);
     }
@@ -650,7 +651,7 @@ public class PropertyImpl extends ItemIm
             dlg.remove();
         } else {
             Value targetValue = ValueHelper.convert(value, requiredType, getValueFactory());
-            dlg.setValue(targetValue);
+            dlg.setState(PropertyStates.createProperty(dlg.getName(), targetValue));
         }
     }
 
@@ -675,7 +676,7 @@ public class PropertyImpl extends ItemIm
                     Arrays.asList(targetValues),
                     Predicates.notNull());
 
-            dlg.setValues(nonNullValues);
+            dlg.setState(PropertyStates.createProperty(dlg.getName(), nonNullValues));
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1456027&r1=1456026&r2=1456027&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
Wed Mar 13 16:25:36 2013
@@ -24,7 +24,6 @@ import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.RepositoryException;
-import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
 
 import com.google.common.base.Function;
@@ -34,7 +33,6 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 
 /**
  * {@code NodeDelegate} serve as internal representations of {@code Node}s.
@@ -181,36 +179,21 @@ public class NodeDelegate extends ItemDe
     /**
      * Set a property
      *
-     * @param name  oak name
-     * @param value
+     * @param propertyState
      * @return the set property
      */
     @Nonnull
-    public PropertyDelegate setProperty(String name, Value value) throws RepositoryException
{
+    public PropertyDelegate setProperty(PropertyState propertyState) throws RepositoryException
{
         Tree tree = getTree();
+        String name = propertyState.getName();
         PropertyState old = tree.getProperty(name);
-        if (old != null && old.isArray()) {
-            throw new ValueFormatException("Attempt to set a single value to multi-valued
property.");
+        if (old != null && old.isArray() && !propertyState.isArray()) {
+            throw new ValueFormatException("Attempt to assign a single value to multi-valued
property.");
         }
-        tree.setProperty(PropertyStates.createProperty(name, value));
-        return new PropertyDelegate(sessionDelegate, tree.getLocation().getChild(name));
-    }
-
-    /**
-     * Set a multi valued property
-     *
-     * @param name   oak name
-     * @param values
-     * @return the set property
-     */
-    @Nonnull
-    public PropertyDelegate setProperty(String name, Iterable<Value> values) throws
RepositoryException {
-        Tree tree = getTree();
-        PropertyState old = tree.getProperty(name);
-        if (old != null && !old.isArray()) {
-            throw new ValueFormatException("Attempt to set multiple values to single valued
property.");
+        if (old != null && !old.isArray() && propertyState.isArray()) {
+            throw new ValueFormatException("Attempt to assign multiple values to single valued
property.");
         }
-        tree.setProperty(PropertyStates.createProperty(name, values));
+        tree.setProperty(propertyState);
         return new PropertyDelegate(sessionDelegate, tree.getLocation().getChild(name));
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java?rev=1456027&r1=1456026&r2=1456027&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
Wed Mar 13 16:25:36 2013
@@ -18,14 +18,11 @@ package org.apache.jackrabbit.oak.jcr.de
 
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 
 /**
  * {@code PropertyDelegate} serve as internal representations of {@code Property}s.
@@ -53,7 +50,7 @@ public class PropertyDelegate extends It
     }
 
     @Nonnull
-    public PropertyState getSingle() throws InvalidItemStateException, ValueFormatException
{
+    public PropertyState getSingleState() throws InvalidItemStateException, ValueFormatException
{
         PropertyState p = getPropertyState();
         if (p.isArray()) {
             throw new ValueFormatException(p + " is multi-valued.");
@@ -62,15 +59,19 @@ public class PropertyDelegate extends It
     }
 
     public boolean getBoolean() throws ValueFormatException, InvalidItemStateException {
-        return getSingle().getValue(Type.BOOLEAN);
+        return getSingleState().getValue(Type.BOOLEAN);
     }
 
     public String getString() throws ValueFormatException, InvalidItemStateException {
-        return getSingle().getValue(Type.STRING);
+        return getSingleState().getValue(Type.STRING);
+    }
+
+    public String getDate() throws ValueFormatException, InvalidItemStateException {
+        return getSingleState().getValue(Type.DATE);
     }
 
     @Nonnull
-    public PropertyState getMulti() throws InvalidItemStateException, ValueFormatException
{
+    public PropertyState getMultiState() throws InvalidItemStateException, ValueFormatException
{
         PropertyState p = getPropertyState();
         if (!p.isArray()) {
             throw new ValueFormatException(p + " is single-valued.");
@@ -78,24 +79,8 @@ public class PropertyDelegate extends It
         return p;
     }
 
-    /**
-     * Set the value of the property
-     *
-     * @param value
-     */
-    public void setValue(Value value) throws RepositoryException {
-        if (!getLocation().set(PropertyStates.createProperty(getName(), value))) {
-            throw new InvalidItemStateException();
-        }
-    }
-
-    /**
-     * Set the values of the property
-     *
-     * @param values
-     */
-    public void setValues(Iterable<Value> values) throws RepositoryException {
-        if (!getLocation().set(PropertyStates.createProperty(getName(), values))) {
+    public void setState(PropertyState propertyState) throws InvalidItemStateException {
+        if (!getLocation().set(propertyState)) {
             throw new InvalidItemStateException();
         }
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java?rev=1456027&r1=1456026&r2=1456027&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
Wed Mar 13 16:25:36 2013
@@ -34,8 +34,7 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
-import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
+import org.apache.jackrabbit.oak.plugins.value.Conversions;
 import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -129,8 +128,8 @@ public class VersionHistoryDelegate exte
             if (primaryType.equals(VersionConstants.NT_VERSION)) {
                 PropertyDelegate created = n.getProperty(JcrConstants.JCR_CREATED);
                 if (created != null) {
-                    ValueFactoryImpl f = SessionContextProvider.getValueFactory(sessionDelegate);
-                    versions.put(f.createValue(created.getSingle()).getDate(), n.getName());
+                    Calendar cal = Conversions.convert(created.getDate()).toCalendar();
+                    versions.put(cal, n.getName());
                 }
             }
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java?rev=1456027&r1=1456026&r2=1456027&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
Wed Mar 13 16:25:36 2013
@@ -61,7 +61,7 @@ class VersionImpl extends NodeImpl<Versi
     @Override
     public Calendar getCreated() throws RepositoryException {
         PropertyDelegate dlg = getPropertyOrThrow(JcrConstants.JCR_CREATED);
-        return getValueFactory().createValue(dlg.getSingle()).getDate();
+        return getValueFactory().createValue(dlg.getSingleState()).getDate();
     }
 
     @Override
@@ -75,7 +75,7 @@ class VersionImpl extends NodeImpl<Versi
     }
 
     private List<Value> getValues(PropertyDelegate p) throws InvalidItemStateException,
ValueFormatException {
-        return getValueFactory().createValues(p.getMulti());
+        return getValueFactory().createValues(p.getMultiState());
     }
 
     @Override



Mime
View raw message