jackrabbit-oak-commits mailing list archives

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

URL: http://svn.apache.org/r1456026
Log:
OAK-672: Avoid JCR APIs calling other JCR APIs
- Simplify value access

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/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=1456026&r1=1456025&r2=1456026&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:05 2013
@@ -75,7 +75,6 @@ import org.apache.jackrabbit.oak.api.Pro
 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.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.IdentifierManager;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
@@ -995,13 +994,7 @@ public class NodeImpl<T extends NodeDele
                     nodeModified = true;
                     dlg.setProperty(JcrConstants.JCR_MIXINTYPES, Collections.singletonList(value));
                 } else {
-                    PropertyState property = mixins.getPropertyState();
-                    if (property == null) {
-                        throw new InvalidItemStateException();
-                    }
-                    if (!property.isArray()) {
-                        throw new ValueFormatException(mixins + " is single-valued.");
-                    }
+                    PropertyState property = mixins.getMulti();
                     List<Value> values = getValueFactory().createValues(property);
                     if (!values.contains(value)) {
                         values.add(value);
@@ -1225,9 +1218,8 @@ public class NodeImpl<T extends NodeDele
         while (parent != null) {
             if (parent.getProperty(lockOwner) != null) {
                 PropertyDelegate isDeep = parent.getProperty(lockIsDeep);
-                if (isDeep != null) {
-                    PropertyState p = isDeep.getPropertyState();
-                    if (p != null && !p.isArray() && p.getValue(Type.BOOLEAN))
{
+                if (isDeep != null && !isDeep.isArray()) {
+                    if (isDeep.getBoolean()) {
                         return true;
                     }
                 }

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=1456026&r1=1456025&r2=1456026&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:05 2013
@@ -26,7 +26,6 @@ import java.util.List;
 import javax.annotation.Nonnull;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Binary;
-import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
@@ -40,7 +39,6 @@ import javax.jcr.nodetype.PropertyDefini
 
 import com.google.common.base.Predicates;
 import com.google.common.collect.Iterables;
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
@@ -355,14 +353,6 @@ public class PropertyImpl extends ItemIm
         }
     }
 
-    private PropertyState getPropertyState() throws InvalidItemStateException {
-        PropertyState property = dlg.getPropertyState();
-        if (property == null) {
-            throw new InvalidItemStateException();
-        }
-        return property;
-    }
-
     @Override
     @Nonnull
     public Value getValue() throws RepositoryException {
@@ -374,11 +364,7 @@ public class PropertyImpl extends ItemIm
 
             @Override
             public Value perform() throws RepositoryException {
-                PropertyState property = getPropertyState();
-                if (property.isArray()) {
-                    throw new ValueFormatException(dlg + " is multi-valued.");
-                }
-                return getValueFactory().createValue(property);
+                return getValueFactory().createValue(dlg.getSingle());
             }
         });
     }
@@ -394,14 +380,7 @@ public class PropertyImpl extends ItemIm
 
             @Override
             public List<Value> perform() throws RepositoryException {
-                PropertyState property = dlg.getPropertyState();
-                if (property == null) {
-                    throw new InvalidItemStateException();
-                }
-                if (!property.isArray()) {
-                    throw new ValueFormatException(dlg + " is single-valued.");
-                }
-                return getValueFactory().createValues(property);
+                return getValueFactory().createValues(dlg.getMulti());
             }
         }).toArray(NO_VALUES);
     }
@@ -614,7 +593,7 @@ public class PropertyImpl extends ItemIm
 
             @Override
             public Boolean perform() throws RepositoryException {
-                return getPropertyState().isArray();
+                return dlg.isArray();
             }
         });
     }

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=1456026&r1=1456025&r2=1456026&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:05 2013
@@ -16,13 +16,15 @@
  */
 package org.apache.jackrabbit.oak.jcr.delegate;
 
-import javax.annotation.CheckForNull;
+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;
 
 /**
@@ -37,6 +39,45 @@ public class PropertyDelegate extends It
         super(sessionDelegate, location);
     }
 
+    @Nonnull
+    private PropertyState getPropertyState() throws InvalidItemStateException {
+        PropertyState p = getLocation().getProperty();
+        if (p == null) {
+            throw new InvalidItemStateException();
+        }
+        return p;
+    }
+
+    public boolean isArray() throws InvalidItemStateException {
+        return getPropertyState().isArray();
+    }
+
+    @Nonnull
+    public PropertyState getSingle() throws InvalidItemStateException, ValueFormatException
{
+        PropertyState p = getPropertyState();
+        if (p.isArray()) {
+            throw new ValueFormatException(p + " is multi-valued.");
+        }
+        return p;
+    }
+
+    public boolean getBoolean() throws ValueFormatException, InvalidItemStateException {
+        return getSingle().getValue(Type.BOOLEAN);
+    }
+
+    public String getString() throws ValueFormatException, InvalidItemStateException {
+        return getSingle().getValue(Type.STRING);
+    }
+
+    @Nonnull
+    public PropertyState getMulti() throws InvalidItemStateException, ValueFormatException
{
+        PropertyState p = getPropertyState();
+        if (!p.isArray()) {
+            throw new ValueFormatException(p + " is single-valued.");
+        }
+        return p;
+    }
+
     /**
      * Set the value of the property
      *
@@ -66,9 +107,4 @@ public class PropertyDelegate extends It
         getLocation().remove();
     }
 
-    @CheckForNull
-    public PropertyState getPropertyState() throws InvalidItemStateException {
-        return getLocation().getProperty();
-    }
-
 }

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=1456026&r1=1456025&r2=1456026&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:05 2013
@@ -26,7 +26,6 @@ import java.util.TreeMap;
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
 import javax.jcr.version.VersionException;
 
 import com.google.common.base.Function;
@@ -126,23 +125,12 @@ public class VersionHistoryDelegate exte
         SortedMap<Calendar, String> versions = new TreeMap<Calendar, String>();
         for (Iterator<NodeDelegate> it = getChildren(); it.hasNext(); ) {
             NodeDelegate n = it.next();
-            PropertyState propertyState = n.getProperty(JcrConstants.JCR_PRIMARYTYPE).getPropertyState();
-            if (propertyState == null) {
-                throw new InvalidItemStateException();
-            }
-            String primaryType = propertyState.getValue(Type.STRING);
+            String primaryType = n.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString();
             if (primaryType.equals(VersionConstants.NT_VERSION)) {
                 PropertyDelegate created = n.getProperty(JcrConstants.JCR_CREATED);
                 if (created != null) {
-                    PropertyState property = created.getPropertyState();
-                    if (property == null) {
-                        throw new InvalidItemStateException();
-                    }
-                    if (property.isArray()) {
-                        throw new ValueFormatException(created + " is multi-valued.");
-                    }
                     ValueFactoryImpl f = SessionContextProvider.getValueFactory(sessionDelegate);
-                    versions.put(f.createValue(property).getDate(), n.getName());
+                    versions.put(f.createValue(created.getSingle()).getDate(), 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=1456026&r1=1456025&r2=1456026&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:05 2013
@@ -30,7 +30,6 @@ import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
 import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
@@ -62,14 +61,7 @@ class VersionImpl extends NodeImpl<Versi
     @Override
     public Calendar getCreated() throws RepositoryException {
         PropertyDelegate dlg = getPropertyOrThrow(JcrConstants.JCR_CREATED);
-        PropertyState property = dlg.getPropertyState();
-        if (property == null) {
-            throw new InvalidItemStateException();
-        }
-        if (property.isArray()) {
-            throw new ValueFormatException(dlg + " is multi-valued.");
-        }
-        return getValueFactory().createValue(property).getDate();
+        return getValueFactory().createValue(dlg.getSingle()).getDate();
     }
 
     @Override
@@ -83,14 +75,7 @@ class VersionImpl extends NodeImpl<Versi
     }
 
     private List<Value> getValues(PropertyDelegate p) throws InvalidItemStateException,
ValueFormatException {
-        PropertyState property = p.getPropertyState();
-        if (property == null) {
-            throw new InvalidItemStateException();
-        }
-        if (!property.isArray()) {
-            throw new ValueFormatException(p + " is single-valued.");
-        }
-        return getValueFactory().createValues(property);
+        return getValueFactory().createValues(p.getMulti());
     }
 
     @Override



Mime
View raw message