jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1394833 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/memory/ query/ast/ security/user/
Date Fri, 05 Oct 2012 21:57:42 GMT
Author: mduerig
Date: Fri Oct  5 21:57:41 2012
New Revision: 1394833

URL: http://svn.apache.org/viewvc?rev=1394833&view=rev
Log:
OAK-350: Unify PropertyState and CoreValue
- replace usages of ValueBasedProperty with new PropertyState implementations, remove ValueBased
implementations

Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ValueBasedEmptyPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ValueBasedMultiPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ValueBasedSinglePropertyState.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/memory/SinglePropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ColumnImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.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=1394833&r1=1394832&r2=1394833&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
Fri Oct  5 21:57:41 2012
@@ -38,6 +38,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.api.Type.PATHS;
 import static org.apache.jackrabbit.oak.api.Type.REFERENCE;
 import static org.apache.jackrabbit.oak.api.Type.REFERENCES;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 import static org.apache.jackrabbit.oak.api.Type.URI;
 import static org.apache.jackrabbit.oak.api.Type.URIS;
 import static org.apache.jackrabbit.oak.api.Type.WEAKREFERENCE;
@@ -48,12 +49,85 @@ public final class PropertyStates {
 
     @Nonnull
     public static PropertyState createProperty(String name, CoreValue value) {
-        return new ValueBasedSinglePropertyState(name, value);
+        int type = value.getType();
+        if (PropertyType.BINARY == type) {
+           return binaryProperty(name, new ValueBasedBlob(value));
+        }
+        else {
+            return createProperty(name, value.getString(), value.getType());
+        }
     }
 
     @Nonnull
     public static PropertyState createProperty(String name, List<CoreValue> values)
{
-        return new ValueBasedMultiPropertyState(name, values);
+        if (values.isEmpty()) {
+            return emptyProperty(name, STRINGS);
+        }
+
+        int type = values.get(0).getType();
+        switch (type) {
+            case PropertyType.STRING:
+                List<String> strings = Lists.newArrayList();
+                for (CoreValue cv : values) {
+                    strings.add(cv.getString());
+                }
+                return stringProperty(name, strings);
+            case PropertyType.BINARY:
+                List<Blob> blobs = Lists.newArrayList();
+                for (CoreValue cv : values) {
+                    blobs.add(new ValueBasedBlob(cv));
+                }
+                return binaryPropertyFromBlob(name, blobs);
+            case PropertyType.LONG:
+                List<Long> longs = Lists.newArrayList();
+                for (CoreValue cv : values) {
+                    longs.add(cv.getLong());
+                }
+                return longProperty(name, longs);
+            case PropertyType.DOUBLE:
+                List<Double> doubles = Lists.newArrayList();
+                for (CoreValue cv : values) {
+                    doubles.add(cv.getDouble());
+                }
+                return doubleProperty(name, doubles);
+            case PropertyType.BOOLEAN:
+                List<Boolean> booleans = Lists.newArrayList();
+                for (CoreValue cv : values) {
+                    booleans.add(cv.getBoolean());
+                }
+                return booleanProperty(name, booleans);
+            case PropertyType.DECIMAL:
+                List<BigDecimal> decimals = Lists.newArrayList();
+                for (CoreValue cv : values) {
+                    decimals.add(cv.getDecimal());
+                }
+                return decimalProperty(name, decimals);
+            default:
+                List<String> vals = Lists.newArrayList();
+                for (CoreValue cv : values) {
+                    vals.add(cv.getString());
+                }
+                return new GenericsPropertyState(name, vals, Type.fromTag(type, true));
+        }
+    }
+
+    public static PropertyState createProperty(String name, String value, int type) {
+        switch (type) {
+            case PropertyType.STRING:
+                return new StringPropertyState(name, value);
+            case PropertyType.BINARY:
+                return new BinaryPropertyState(name, new StringBasedBlob(value));
+            case PropertyType.LONG:
+                return new LongPropertyState(name, SinglePropertyState.getLong(value));
+            case PropertyType.DOUBLE:
+                return new DoublePropertyState(name, StringPropertyState.getDouble(value));
+            case PropertyType.BOOLEAN:
+                return new BooleanPropertyState(name, StringPropertyState.getBoolean(value));
+            case PropertyType.DECIMAL:
+                return new DecimalPropertyState(name, StringPropertyState.getDecimal(value));
+            default:
+                return new GenericPropertyState(name, value, Type.fromTag(type, false));
+        }
     }
 
     @SuppressWarnings("unchecked")
@@ -132,6 +206,9 @@ public final class PropertyStates {
     }
 
     public static PropertyState emptyProperty(String name, final Type<?> type) {
+        if (!type.isArray()) {
+            throw new IllegalArgumentException("Not an array type:" + type);
+        }
         return new EmptyPropertyState(name) {
             @Override
             public Type<?> getType() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
Fri Oct  5 21:57:41 2012
@@ -30,6 +30,18 @@ import static java.util.Collections.sing
 
 abstract class SinglePropertyState extends EmptyPropertyState {
 
+    public static long getLong(String value) {
+        return Long.parseLong(value);
+    }
+
+    public static double getDouble(String value) {
+        return Double.parseDouble(value);
+    }
+
+    public static BigDecimal getDecimal(String value) {
+        return new BigDecimal(value);
+    }
+
     protected SinglePropertyState(String name) {
         super(name);
     }
@@ -41,11 +53,11 @@ abstract class SinglePropertyState exten
     }
 
     protected long getLong() {
-        return Long.parseLong(getString());
+        return getLong(getString());
     }
 
     protected double getDouble() {
-        return Double.parseDouble(getString());
+        return getDouble(getString());
     }
 
     protected boolean getBoolean() {
@@ -53,7 +65,7 @@ abstract class SinglePropertyState exten
     }
 
     protected BigDecimal getDecimal() {
-        return new BigDecimal(getString());
+        return getDecimal(getString());
     }
 
     @Override
@@ -130,5 +142,4 @@ abstract class SinglePropertyState exten
     public int count() {
         return 1;
     }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
Fri Oct  5 21:57:41 2012
@@ -30,6 +30,10 @@ public class StringPropertyState extends
         this.value = value;
     }
 
+    public static boolean getBoolean(String value) {
+        return Boolean.parseBoolean(value);
+    }
+
     @Override
     protected String getString() {
         return value;
@@ -37,7 +41,7 @@ public class StringPropertyState extends
 
     @Override
     protected boolean getBoolean() {
-        return Boolean.parseBoolean(value);
+        return getBoolean(value);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ColumnImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ColumnImpl.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ColumnImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ColumnImpl.java
Fri Oct  5 21:57:41 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.query.Query;
@@ -63,8 +62,7 @@ public class ColumnImpl extends AstEleme
             if (p == null) {
                 return null;
             }
-            CoreValue v = query.getValueFactory().createValue(p);
-            return PropertyStates.createProperty(Query.JCR_PATH, v);
+            return PropertyStates.stringProperty(Query.JCR_PATH, p);
         }
         return selector.currentProperty(propertyName);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
Fri Oct  5 21:57:41 2012
@@ -51,8 +51,7 @@ public class FullTextSearchScoreImpl ext
         PropertyState p = selector.currentProperty(Query.JCR_SCORE);
         if (p == null) {
             // TODO if score() is not supported by the index, use the value 0.0?
-            CoreValue v = query.getValueFactory().createValue(0.0);
-            p = PropertyStates.createProperty(Query.JCR_SCORE, v);
+            return PropertyStates.doubleProperty(Query.JCR_SCORE, 0.0);
         }
         return p;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
Fri Oct  5 21:57:41 2012
@@ -58,8 +58,7 @@ public class LengthImpl extends DynamicO
         }
         if (!p.isArray()) {
             long length = p.size();
-            CoreValue v = query.getValueFactory().createValue(length);
-            return PropertyStates.createProperty("LENGTH", v);
+            return PropertyStates.longProperty("LENGTH", length);
         }
         // TODO what is the expected result for LENGTH(multiValueProperty)?
         throw new IllegalArgumentException("LENGTH(x) on multi-valued property is not supported");

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
Fri Oct  5 21:57:41 2012
@@ -59,8 +59,7 @@ public class NodeLocalNameImpl extends D
         int colon = name.indexOf(':');
         // TODO LOCALNAME: evaluation of local name might not be correct
         String localName = colon < 0 ? name : name.substring(colon + 1);
-        CoreValue v = query.getValueFactory().createValue(localName);
-        return PropertyStates.createProperty("LOCALNAME", v);
+        return PropertyStates.stringProperty("LOCALNAME", localName);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
Fri Oct  5 21:57:41 2012
@@ -63,8 +63,7 @@ public class NodeNameImpl extends Dynami
         String path = selector.currentPath();
         // Name escaping (convert space to _x0020_)
         String name = ISO9075.encode(PathUtils.getName(path));
-        CoreValue v2 = query.getValueFactory().createValue(name, PropertyType.NAME);
-        return PropertyStates.createProperty("NAME", v2);
+        return PropertyStates.nameProperty("NAME", name);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
Fri Oct  5 21:57:41 2012
@@ -27,7 +27,6 @@ import javax.jcr.nodetype.NodeTypeIterat
 import javax.jcr.nodetype.NodeTypeManager;
 
 import com.google.common.collect.ImmutableSet;
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
@@ -228,8 +227,7 @@ public class SelectorImpl extends Source
                 // not a local path
                 return null;
             }
-            CoreValue v = query.getValueFactory().createValue(local);
-            return PropertyStates.createProperty(Query.JCR_PATH, v);
+            return PropertyStates.stringProperty(Query.JCR_PATH, local);
         }
         if (cursor == null) {
             return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java?rev=1394833&r1=1394832&r2=1394833&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
Fri Oct  5 21:57:41 2012
@@ -303,8 +303,7 @@ class UserProviderImpl extends Authoriza
         if (value == null) {
             authorizableTree.removeProperty(propertyName);
         } else {
-            CoreValue cv = valueFactory.createValue(value, propertyType);
-            authorizableTree.setProperty(PropertyStates.createProperty(propertyName, cv));
+            authorizableTree.setProperty(PropertyStates.createProperty(propertyName, value,
propertyType));
         }
     }
 



Mime
View raw message