jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1452203 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: PropertyDelegate.java PropertyImpl.java
Date Mon, 04 Mar 2013 08:03:37 GMT
Author: jukka
Date: Mon Mar  4 08:03:37 2013
New Revision: 1452203

URL: http://svn.apache.org/r1452203
Log:
OAK-663: oak-jcr performance optimization

Push the isMultiple() checks on PropertyImpl.getValue() to avoid an extra round of status
checks

Modified:
    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-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=1452203&r1=1452202&r2=1452203&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
Mon Mar  4 08:03:37 2013
@@ -22,6 +22,7 @@ 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;
@@ -45,10 +46,15 @@ public class PropertyDelegate extends It
      *
      * @return the value of the property
      * @throws InvalidItemStateException
+     * @throws ValueFormatException if this property is multi-valued
      */
     @Nonnull
-    public Value getValue() throws InvalidItemStateException {
-        return ValueFactoryImpl.createValue(getPropertyState(), sessionDelegate.getNamePathMapper());
+    public Value getValue() throws InvalidItemStateException, ValueFormatException {
+        PropertyState property = getPropertyState();
+        if (property.isArray()) {
+            throw new ValueFormatException(this + " is multi-valued.");
+        }
+        return ValueFactoryImpl.createValue(property, sessionDelegate.getNamePathMapper());
     }
 
     /**
@@ -56,10 +62,15 @@ public class PropertyDelegate extends It
      *
      * @return the values of the property
      * @throws InvalidItemStateException
+     * @throws ValueFormatException if this property is single-valued
      */
     @Nonnull
-    public List<Value> getValues() throws InvalidItemStateException {
-        return ValueFactoryImpl.createValues(getPropertyState(), sessionDelegate.getNamePathMapper());
+    public List<Value> getValues() throws InvalidItemStateException, ValueFormatException
{
+        PropertyState property = getPropertyState();
+        if (!property.isArray()) {
+            throw new ValueFormatException(this + " is single-valued.");
+        }
+        return ValueFactoryImpl.createValues(property, sessionDelegate.getNamePathMapper());
     }
 
     /**

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=1452203&r1=1452202&r2=1452203&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
Mon Mar  4 08:03:37 2013
@@ -56,6 +56,8 @@ public class PropertyImpl extends ItemIm
      */
     private static final Logger log = LoggerFactory.getLogger(PropertyImpl.class);
 
+    private static final Value[] NO_VALUES = new Value[0];
+
     PropertyImpl(PropertyDelegate dlg) {
         super(dlg);
     }
@@ -351,10 +353,6 @@ public class PropertyImpl extends ItemIm
         return perform(new SessionOperation<Value>() {
             @Override
             public Value perform() throws RepositoryException {
-                if (isMultiple()) {
-                    throw new ValueFormatException(this + " is multi-valued.");
-                }
-
                 return dlg.getValue();
             }
         });
@@ -365,16 +363,12 @@ public class PropertyImpl extends ItemIm
     public Value[] getValues() throws RepositoryException {
         checkStatus();
 
-        return perform(new SessionOperation<Value[]>() {
+        return perform(new SessionOperation<List<Value>>() {
             @Override
-            public Value[] perform() throws RepositoryException {
-                if (!isMultiple()) {
-                    throw new ValueFormatException(this + " is not multi-valued.");
-                }
-
-                return Iterables.toArray(dlg.getValues(), Value.class);
+            public List<Value> perform() throws RepositoryException {
+                return dlg.getValues();
             }
-        });
+        }).toArray(NO_VALUES);
     }
 
     /**



Mime
View raw message