jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1397098 [1/2] - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ oak...
Date Thu, 11 Oct 2012 14:58:30 GMT
Author: alexparvulescu
Date: Thu Oct 11 14:58:28 2012
New Revision: 1397098

URL: http://svn.apache.org/viewvc?rev=1397098&view=rev
Log:
OAK-371 Query package refactoring

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyValue.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/PropertyValues.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ResultRow.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ArrayBasedBlob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringBasedBlob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRowImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AstElementFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/BindVariableValueImpl.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/ComparisonImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/EquiJoinConditionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.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/LiteralImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.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/PropertyExistenceImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.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/query/ast/StaticOperandImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/UpperCaseImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/FilterImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/IndexRowImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/MembershipProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/Filter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/IndexRow.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/RowImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ResultRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ResultRow.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ResultRow.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/ResultRow.java Thu Oct 11 14:58:28 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.api;
 
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+
 /**
  * A query result row.
  */
@@ -25,8 +27,8 @@ public interface ResultRow {
 
     String getPath(String selectorName);
 
-    CoreValue getValue(String columnName);
+    PropertyValue getValue(String columnName);
 
-    CoreValue[] getValues();
+    PropertyValue[] getValues();
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java Thu Oct 11 14:58:28 2012
@@ -21,6 +21,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 
 /**
  * The query engine allows to parse and execute queries.
@@ -61,7 +62,7 @@ public interface SessionQueryEngine {
      * @throws IllegalArgumentException if there was an error executing the query
      */
     Result executeQuery(String statement, String language,
-            long limit, long offset, Map<String, ? extends CoreValue> bindings,
+            long limit, long offset, Map<String, ? extends PropertyValue> bindings,
             Root root, NamePathMapper namePathMapper) throws ParseException;
 
     // TODO pass namespace mapping

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java Thu Oct 11 14:58:28 2012
@@ -33,7 +33,6 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
@@ -42,7 +41,9 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.memory.StringValue;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -156,8 +157,8 @@ public class IdentifierManager {
      * such tree exists or isn't accessible to the content session.
      */
     @CheckForNull
-    public String getPath(CoreValue referenceValue) {
-        int type = referenceValue.getType();
+    public String getPath(PropertyState referenceValue) {
+        int type = referenceValue.getType().tag();
         if (type == PropertyType.REFERENCE || type == PropertyType.WEAKREFERENCE) {
             return resolveUUID(referenceValue);
         } else {
@@ -188,7 +189,7 @@ public class IdentifierManager {
                 final String uuid = getIdentifier(tree);
                 String reference = weak ? PropertyType.TYPENAME_WEAKREFERENCE : PropertyType.TYPENAME_REFERENCE;
                 String pName = propertyName == null ? "*" : propertyName;   // TODO: sanitize against injection attacks!?
-                Map<String, ? extends CoreValue> bindings = Collections.singletonMap("uuid", new StringValue(uuid));
+                Map<String, ? extends PropertyValue> bindings = Collections.singletonMap("uuid", PropertyValues.newString(uuid));
 
                 Result result = root.getQueryEngine().executeQuery(
                         "SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference + "') = $uuid",
@@ -283,12 +284,12 @@ public class IdentifierManager {
 
     @CheckForNull
     private String resolveUUID(String uuid) {
-        return resolveUUID(new StringValue(uuid));
+        return resolveUUID(PropertyStates.stringProperty("", uuid));
     }
 
-    private String resolveUUID(CoreValue uuid) {
+    private String resolveUUID(PropertyState uuid) {
         try {
-            Map<String, CoreValue> bindings = Collections.singletonMap("id", uuid);
+            Map<String, PropertyValue> bindings = Collections.singletonMap("id", PropertyValues.create(uuid));
             Result result = root.getQueryEngine().executeQuery(
                     "SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id", Query.JCR_SQL2,
                     Long.MAX_VALUE, 0, bindings, root, new NamePathMapper.Default());

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneEditor.java Thu Oct 11 14:58:28 2012
@@ -26,11 +26,11 @@ import java.io.IOException;
 
 import javax.jcr.PropertyType;
 
+import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.IndexDefinition;
-import org.apache.jackrabbit.oak.plugins.memory.CoreValues;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -220,28 +220,30 @@ class LuceneEditor implements CommitHook
             document.add(newPathField(path));
             for (PropertyState property : state.getProperties()) {
                 String pname = property.getName();
-                for (CoreValue value : CoreValues.getValues(property)) {
-                    document.add(newPropertyField(pname,
-                            parseStringValue(value)));
+                switch (property.getType().tag()) {
+                case PropertyType.BINARY:
+                    for (Blob v : property.getValue(Type.BINARIES)) {
+                        document.add(newPropertyField(pname,
+                                parseStringValue(v)));
+                    }
+                    break;
+                default:
+                    for (String v : property.getValue(Type.STRINGS)) {
+                        document.add(newPropertyField(pname, v));
+                    }
+                    break;
                 }
             }
             return document;
         }
 
-        private static String parseStringValue(CoreValue value) {
-            String string;
-            if (value.getType() != PropertyType.BINARY) {
-                string = value.getString();
-            } else {
-                try {
-                    string = TIKA.parseToString(value.getNewStream());
-                } catch (IOException e) {
-                    string = "";
-                } catch (TikaException e) {
-                    string = "";
-                }
+        private static String parseStringValue(Blob v) {
+            try {
+                return TIKA.parseToString(v.getNewStream());
+            } catch (IOException e) {
+            } catch (TikaException e) {
             }
-            return string;
+            return "";
         }
 
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java Thu Oct 11 14:58:28 2012
@@ -29,6 +29,7 @@ import javax.jcr.nodetype.NodeTypeIterat
 import javax.jcr.nodetype.NodeTypeManager;
 
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.ReadOnlyTree;
 import org.apache.jackrabbit.oak.plugins.index.IndexDefinition;
@@ -200,10 +201,10 @@ public class LuceneIndex implements Quer
             boolean isLike = pr.isLike;
 
             if (pr.first != null) {
-                first = pr.first.getString();
+                first = pr.first.getValue(Type.STRING);
             }
             if (pr.last != null) {
-                last = pr.last.getString();
+                last = pr.last.getValue(Type.STRING);
             }
 
             if (isLike) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PrefixContentIndex.java Thu Oct 11 14:58:28 2012
@@ -22,6 +22,7 @@ import java.util.Iterator;
 
 import javax.jcr.PropertyType;
 
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.kernel.TypeCodes;
 import org.apache.jackrabbit.oak.query.index.IndexRowImpl;
@@ -80,7 +81,7 @@ public class PrefixContentIndex implemen
             throw new IllegalArgumentException("No restriction for *");
         }
         // TODO need to use correct json representation
-        String v = restriction.first.getString();
+        String v = restriction.first.getValue(Type.STRING);
         v = index.getPrefix() + v;
         return "prefixIndex \"" + v + '"';
     }
@@ -92,7 +93,7 @@ public class PrefixContentIndex implemen
             throw new IllegalArgumentException("No restriction for *");
         }
         // TODO need to use correct json representation
-        String v = restriction.first.getString();
+        String v = restriction.first.getValue(Type.STRING);
         v = index.getPrefix() + v;
         // TODO revisit code after the removal of revisionId
         String revisionId = "";

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/old/PropertyContentIndex.java Thu Oct 11 14:58:28 2012
@@ -19,7 +19,9 @@
 package org.apache.jackrabbit.oak.plugins.index.old;
 
 import java.util.Iterator;
-import org.apache.jackrabbit.oak.api.CoreValue;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.query.index.IndexRowImpl;
 import org.apache.jackrabbit.oak.spi.query.Cursor;
 import org.apache.jackrabbit.oak.spi.query.Filter;
@@ -69,8 +71,8 @@ public class PropertyContentIndex implem
         if (restriction == null) {
             throw new IllegalArgumentException("No restriction for " + propertyName);
         }
-        CoreValue first = restriction.first;
-        String f = first == null ? null : first.toString();
+        PropertyState first = restriction.first;
+        String f = first == null ? null : first.getValue(Type.STRING);
         // TODO revisit code after the removal of revisionId
         String revisionId = "";
         Iterator<String> it = index.getPaths(f, revisionId);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndex.java Thu Oct 11 14:58:28 2012
@@ -18,17 +18,20 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.query.index.IndexRowImpl;
 import org.apache.jackrabbit.oak.query.index.TraversingCursor;
 import org.apache.jackrabbit.oak.spi.query.Cursor;
 import org.apache.jackrabbit.oak.spi.query.Filter;
-import org.apache.jackrabbit.oak.spi.query.IndexRow;
 import org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction;
+import org.apache.jackrabbit.oak.spi.query.IndexRow;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -39,16 +42,20 @@ public class PropertyIndex implements Qu
 
     private static final int MAX_STRING_LENGTH = 100; // TODO: configurable
 
-    static String encode(CoreValue value) {
-        try {
-            String string = value.getString();
-            if (string.length() > MAX_STRING_LENGTH) {
-                string.substring(0, MAX_STRING_LENGTH);
+    static List<String> encode(PropertyState value) {
+        List<String> values = new ArrayList<String>();
+
+        for (String v : value.getValue(Type.STRINGS)) {
+            try {
+                if (v.length() > MAX_STRING_LENGTH) {
+                    v = v.substring(0, MAX_STRING_LENGTH);
+                }
+                values.add(URLEncoder.encode(v, Charsets.UTF_8.name()));
+            } catch (UnsupportedEncodingException e) {
+                throw new IllegalStateException("UTF-8 is unsupported", e);
             }
-            return URLEncoder.encode(string, Charsets.UTF_8.name());
-        } catch (UnsupportedEncodingException e) {
-           throw new IllegalStateException("UTF-8 is unsupported", e);
         }
+        return values;
     }
 
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexDiff.java Thu Oct 11 14:58:28 2012
@@ -22,7 +22,6 @@ import java.util.Map;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.plugins.memory.CoreValues;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -109,22 +108,22 @@ class PropertyIndexDiff implements NodeS
     @Override
     public void propertyAdded(PropertyState after) {
         for (PropertyIndexUpdate update : getIndexes(after.getName())) {
-            update.insert(getPath(), CoreValues.getValues(after));
+            update.insert(getPath(), after);
         }
     }
 
     @Override
     public void propertyChanged(PropertyState before, PropertyState after) {
         for (PropertyIndexUpdate update : getIndexes(after.getName())) {
-            update.remove(getPath(), CoreValues.getValues(before));
-            update.insert(getPath(), CoreValues.getValues(after));
+            update.remove(getPath(), before);
+            update.insert(getPath(), after);
         }
     }
 
     @Override
     public void propertyDeleted(PropertyState before) {
         for (PropertyIndexUpdate update : getIndexes(before.getName())) {
-            update.remove(getPath(), CoreValues.getValues(before));
+            update.remove(getPath(), before);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java Thu Oct 11 14:58:28 2012
@@ -18,11 +18,10 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.Set;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.memory.CoreValues;
-import org.apache.jackrabbit.oak.plugins.memory.StringValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -66,10 +65,10 @@ public class PropertyIndexLookup {
     }
 
     public Set<String> find(String name, String value) {
-        return find(name, new StringValue(value));
+        return find(name, PropertyValues.newString(value));
     }
 
-    public Set<String> find(String name, CoreValue value) {
+    public Set<String> find(String name, PropertyValue value) {
         Set<String> paths = Sets.newHashSet();
 
         PropertyState property = null;
@@ -79,7 +78,8 @@ public class PropertyIndexLookup {
             if (state != null) {
                 state = state.getChildNode(":index");
                 if (state != null) {
-                    property = state.getProperty(PropertyIndex.encode(value));
+                    //TODO what happens when I search using an mvp?
+                    property = state.getProperty(PropertyIndex.encode(value).get(0));
                 }
             }
         }
@@ -92,12 +92,9 @@ public class PropertyIndexLookup {
         } else {
             // No index available, so first check this node for a match
             property = root.getProperty(name);
-            if (property != null) {
-                for (CoreValue cv : CoreValues.getValues(property)) {
-                    if (cv.equals(value)) {
-                        paths.add("");
-                        break;
-                    }
+            if (property != null){
+                if(PropertyValues.match(property, value)){
+                    paths.add("");
                 }
             }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexUpdate.java Thu Oct 11 14:58:28 2012
@@ -27,7 +27,6 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
@@ -50,22 +49,21 @@ class PropertyIndexUpdate {
         this.remove = Maps.newHashMap();
     }
 
-    public void insert(String path, Iterable<CoreValue> values) {
+    public void insert(String path, PropertyState value) {
         Preconditions.checkArgument(path.startsWith(this.path));
-        putValues(insert, path.substring(this.path.length()), values);
+        putValues(insert, path.substring(this.path.length()), value);
     }
 
-    public void remove(String path, Iterable<CoreValue> values) {
+    public void remove(String path, PropertyState value) {
         Preconditions.checkArgument(path.startsWith(this.path));
-        putValues(remove, path.substring(this.path.length()), values);
+        putValues(remove, path.substring(this.path.length()), value);
     }
 
-    private static void putValues(
-            Map<String, Set<String>> map,
-            String path, Iterable<CoreValue> values) {
-        for (CoreValue value : values) {
-            if (value.getType() != PropertyType.BINARY) {
-                String key = PropertyIndex.encode(value);
+    private static void putValues(Map<String, Set<String>> map, String path,
+            PropertyState value) {
+        if (value.getType().tag() != PropertyType.BINARY) {
+            List<String> keys = PropertyIndex.encode(value);
+            for (String key : keys) {
                 Set<String> paths = map.get(key);
                 if (paths == null) {
                     paths = Sets.newHashSet();
@@ -76,7 +74,6 @@ class PropertyIndexUpdate {
         }
     }
 
-
     public void apply() throws CommitFailedException {
         boolean unique = node.getProperty("unique") != null;
         NodeBuilder index = node.child(":index");

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ArrayBasedBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ArrayBasedBlob.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ArrayBasedBlob.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ArrayBasedBlob.java Thu Oct 11 14:58:28 2012
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 
 import javax.annotation.Nonnull;
 
@@ -30,6 +31,15 @@ public class ArrayBasedBlob extends Abst
         this.value = value;
     }
 
+    @Override
+    public String toString() {
+        try {
+            return new String(value, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            return "<blob>";
+        }
+    }
+
     @Nonnull
     @Override
     public InputStream getNewStream() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java Thu Oct 11 14:58:28 2012
@@ -29,7 +29,8 @@ public class BinaryPropertyState extends
 
     @Override
     public String getString() {
-        return "<binary>";
+        // TODO find a better way to represent string values with Blobs
+        return value.toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringBasedBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringBasedBlob.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringBasedBlob.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringBasedBlob.java Thu Oct 11 14:58:28 2012
@@ -31,6 +31,11 @@ public class StringBasedBlob extends Abs
         this.value = value;
     }
 
+    @Override
+    public String toString() {
+        return value;
+    }
+
     @Nonnull
     @Override
     public InputStream getNewStream() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java Thu Oct 11 14:58:28 2012
@@ -13,8 +13,6 @@
  */
 package org.apache.jackrabbit.oak.query;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -22,15 +20,9 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 
-import javax.jcr.PropertyType;
-
-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.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.memory.CoreValues;
 import org.apache.jackrabbit.oak.query.ast.AstVisitorBase;
 import org.apache.jackrabbit.oak.query.ast.BindVariableValueImpl;
 import org.apache.jackrabbit.oak.query.ast.ChildNodeImpl;
@@ -57,6 +49,8 @@ import org.apache.jackrabbit.oak.query.a
 import org.apache.jackrabbit.oak.query.ast.SourceImpl;
 import org.apache.jackrabbit.oak.query.ast.UpperCaseImpl;
 import org.apache.jackrabbit.oak.spi.query.Filter;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -80,7 +74,7 @@ public class Query {
 
     final SourceImpl source;
     final ConstraintImpl constraint;
-    final HashMap<String, CoreValue> bindVariableMap = new HashMap<String, CoreValue>();
+    final HashMap<String, PropertyValue> bindVariableMap = new HashMap<String, PropertyValue>();
     final HashMap<String, Integer> selectorIndexes = new HashMap<String, Integer>();
     final ArrayList<SelectorImpl> selectors = new ArrayList<SelectorImpl>();
 
@@ -92,17 +86,15 @@ public class Query {
     private long offset;
     private long size = -1;
     private boolean prepared;
-    private final CoreValueFactory valueFactory;
     private Root root;
     private NamePathMapper namePathMapper;
 
     Query(SourceImpl source, ConstraintImpl constraint, OrderingImpl[] orderings,
-          ColumnImpl[] columns, CoreValueFactory valueFactory) {
+          ColumnImpl[] columns) {
         this.source = source;
         this.constraint = constraint;
         this.orderings = orderings;
         this.columns = columns;
-        this.valueFactory = valueFactory;
     }
 
     public void init() {
@@ -280,7 +272,7 @@ public class Query {
         return source;
     }
 
-    void bindValue(String varName, CoreValue value) {
+    void bindValue(String varName, PropertyValue value) {
         bindVariableMap.put(varName, value);
     }
 
@@ -292,10 +284,6 @@ public class Query {
         this.offset = offset;
     }
 
-    public CoreValueFactory getValueFactory() {
-        return valueFactory;
-    }
-
     public void setExplain(boolean explain) {
         this.explain = explain;
     }
@@ -315,8 +303,8 @@ public class Query {
             String plan = source.getPlan(root);
             columns = new ColumnImpl[] { new ColumnImpl("explain", "plan", "plan")};
             ResultRowImpl r = new ResultRowImpl(this,
-                    new String[0],
-                    new CoreValue[] { getValueFactory().createValue(plan) },
+                    new String[0], 
+                    new PropertyValue[] { PropertyValues.newString(plan)},
                     null);
             it = Arrays.asList(r).iterator();
         } else {
@@ -347,18 +335,18 @@ public class Query {
                 ArrayList<ResultRowImpl> list = new ArrayList<ResultRowImpl>();
                 ResultRowImpl r = new ResultRowImpl(this,
                         new String[0],
-                        new CoreValue[] {
-                            getValueFactory().createValue("query"),
-                            getValueFactory().createValue(resultCount),
+                        new PropertyValue[] {
+                                PropertyValues.newString("query"),
+                                PropertyValues.newLong(resultCount)
                             },
                         null);
                 list.add(r);
                 for (SelectorImpl selector : selectors) {
                     r = new ResultRowImpl(this,
                             new String[0],
-                            new CoreValue[] {
-                                getValueFactory().createValue(selector.getSelectorName()),
-                                getValueFactory().createValue(selector.getScanCount()),
+                            new PropertyValue[] {
+                                    PropertyValues.newString(selector.getSelectorName()),
+                                    PropertyValues.newLong(selector.getScanCount()),
                                 },
                             null);
                     list.add(r);
@@ -369,11 +357,12 @@ public class Query {
         return it;
     }
 
-    public int compareRows(CoreValue[][] orderValues, CoreValue[][] orderValues2) {
+    public int compareRows(PropertyValue[] orderValues,
+            PropertyValue[] orderValues2) {
         int comp = 0;
         for (int i = 0, size = orderings.length; i < size; i++) {
-            CoreValue[] a = orderValues[i];
-            CoreValue[] b = orderValues2[i];
+            PropertyValue a = orderValues[i];
+            PropertyValue b = orderValues2[i];
             if (a == null || b == null) {
                 if (a == b) {
                     comp = 0;
@@ -384,7 +373,7 @@ public class Query {
                     comp = 1;
                 }
             } else {
-                comp = compareValues(a, b);
+                comp = a.compareTo(b);
             }
             if (comp != 0) {
                 if (orderings[i].isDescending()) {
@@ -396,125 +385,6 @@ public class Query {
         return comp;
     }
 
-    public static int compareValues(CoreValue[] orderValues, CoreValue[] orderValues2) {
-        int l1 = orderValues.length;
-        int l2 = orderValues2.length;
-        int len = Math.max(l1, l2);
-        for (int i = 0; i < len; i++) {
-            CoreValue a = i < l1 ? orderValues[i] : null;
-            CoreValue b = i < l2 ? orderValues2[i] : null;
-            int comp;
-            if (a == null) {
-                comp = 1;
-            } else if (b == null) {
-                comp = -1;
-            } else {
-                comp = a.compareTo(b);
-            }
-            if (comp != 0) {
-                return comp;
-            }
-        }
-        return 0;
-    }
-
-    public static int getType(PropertyState p, int ifUnknown) {
-        if (p.count() > 0) {
-            return p.getType().tag();
-        }
-        return ifUnknown;
-    }
-
-    /**
-     * Convert a value to the given target type, if possible.
-     * 
-     * @param v the value to convert
-     * @param targetType the target property type
-     * @return the converted value, or null if converting is not possible
-     */
-    public CoreValue convert(CoreValue v, int targetType) {
-        // TODO support full set of conversion features defined in the JCR spec
-        // at 3.6.4 Property Type Conversion
-        // re-use existing code if possible
-        int sourceType = v.getType();
-        if (sourceType == targetType) {
-            return v;
-        }
-        CoreValueFactory vf = getValueFactory();
-        switch (sourceType) {
-        case PropertyType.STRING:
-            switch(targetType) {
-            case PropertyType.BINARY:
-                try {
-                    byte[] data = v.getString().getBytes("UTF-8");
-                    return vf.createValue(new ByteArrayInputStream(data));
-                } catch (IOException e) {
-                    // I don't know in what case that could really occur
-                    // except if UTF-8 isn't supported
-                    throw new IllegalArgumentException(v.getString(), e);
-                }
-            }
-            return vf.createValue(v.getString(), targetType);
-        }
-        try {
-            switch (targetType) {
-            case PropertyType.STRING:
-                return vf.createValue(v.getString());
-            case PropertyType.BOOLEAN:
-                return vf.createValue(v.getBoolean());
-            case PropertyType.DATE:
-                return vf.createValue(v.getString(), PropertyType.DATE);
-            case PropertyType.LONG:
-                return vf.createValue(v.getLong());
-            case PropertyType.DOUBLE:
-                return vf.createValue(v.getDouble());
-            case PropertyType.DECIMAL:
-                return vf.createValue(v.getString(), PropertyType.DECIMAL);
-            case PropertyType.NAME:
-                return vf.createValue(getOakPath(v.getString()), PropertyType.NAME);
-            case PropertyType.PATH:
-                return vf.createValue(v.getString(), PropertyType.PATH);
-            case PropertyType.REFERENCE:
-                return vf.createValue(v.getString(), PropertyType.REFERENCE);
-            case PropertyType.WEAKREFERENCE:
-                return vf.createValue(v.getString(), PropertyType.WEAKREFERENCE);
-            case PropertyType.URI:
-                return vf.createValue(v.getString(), PropertyType.URI);
-            case PropertyType.BINARY:
-                try {
-                    byte[] data = v.getString().getBytes("UTF-8");
-                    return vf.createValue(new ByteArrayInputStream(data));
-                } catch (IOException e) {
-                    // I don't know in what case that could really occur
-                    // except if UTF-8 isn't supported
-                    throw new IllegalArgumentException(v.getString(), e);
-                }
-            }
-            throw new IllegalArgumentException("Unknown property type: " + targetType);
-        } catch (UnsupportedOperationException e) {
-            // TODO detect unsupported conversions, so that no exception is thrown
-            // because exceptions are slow
-            return null;
-            // throw new IllegalArgumentException("<unsupported conversion of " + 
-            //        v + " (" + PropertyType.nameFromValue(v.getType()) + ") to type " + 
-            //        PropertyType.nameFromValue(targetType) + ">");
-        }
-    }
-
-    public String getOakPath(String jcrPath) {
-        NamePathMapper m = getNamePathMapper();
-        if (m == null) {
-            // to simplify testing, a getNamePathMapper isn't required
-            return jcrPath;
-        }
-        String p = m.getOakPath(jcrPath);
-        if (p == null) {
-            throw new IllegalArgumentException("Not a valid JCR path: "
-                    + jcrPath);
-        }
-        return p;
-    }
-
     void prepare() {
         if (prepared) {
             return;
@@ -609,30 +479,19 @@ public class Query {
             paths[i] = s.currentPath();
         }
         int columnCount = columns.length;
-        CoreValue[] values = new CoreValue[columnCount];
+        PropertyValue[] values = new PropertyValue[columnCount];
         for (int i = 0; i < columnCount; i++) {
             ColumnImpl c = columns[i];
-            PropertyState p = c.currentProperty();
-            values[i] = p == null ? null : CoreValues.getValue(p);
+            values[i] = PropertyValues.create(c.currentProperty());
         }
-        CoreValue[][] orderValues;
+        PropertyValue[] orderValues;
         if (orderings == null) {
             orderValues = null;
         } else {
             int size = orderings.length;
-            orderValues = new CoreValue[size][];
+            orderValues = new PropertyValue[size];
             for (int i = 0; i < size; i++) {
-                PropertyState p = orderings[i].getOperand().currentProperty();
-                CoreValue[] x;
-                if (p == null) {
-                    x = null;
-                } else if (p.isArray()) {
-                    List<CoreValue> list = CoreValues.getValues(p);
-                    x = list.toArray(new CoreValue[list.size()]);
-                } else {
-                    x = new CoreValue[] { CoreValues.getValue(p) };
-                }
-                orderValues[i] = x;
+                orderValues[i] = PropertyValues.create(orderings[i].getOperand().currentProperty());
             }
         }
         return new ResultRowImpl(this, paths, values, orderValues);
@@ -657,8 +516,8 @@ public class Query {
         throw new IllegalArgumentException("Column not found: " + columnName);
     }
 
-    public CoreValue getBindVariableValue(String bindVariableName) {
-        CoreValue v = bindVariableMap.get(bindVariableName);
+    public PropertyValue getBindVariableValue(String bindVariableName) {
+        PropertyValue v = bindVariableMap.get(bindVariableName);
         if (v == null) {
             throw new IllegalArgumentException("Bind variable value not set: " + bindVariableName);
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java Thu Oct 11 14:58:28 2012
@@ -22,12 +22,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.query.index.TraversingIndex;
 import org.apache.jackrabbit.oak.spi.query.Filter;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -43,12 +42,10 @@ public class QueryEngineImpl {
     static final String JQOM = "JCR-JQOM";
 
     private final NodeStore store;
-    private final CoreValueFactory vf;
     private final QueryIndexProvider indexProvider;
 
     public QueryEngineImpl(NodeStore store, QueryIndexProvider indexProvider) {
         this.store = store;
-        this.vf = store.getValueFactory();
         this.indexProvider = indexProvider;
     }
 
@@ -72,16 +69,16 @@ public class QueryEngineImpl {
     private Query parseQuery(String statement, String language) throws ParseException {
         Query q;
         if (SQL2.equals(language) || JQOM.equals(language)) {
-            SQL2Parser parser = new SQL2Parser(vf);
+            SQL2Parser parser = new SQL2Parser();
             q = parser.parse(statement);
         } else if (SQL.equals(language)) {
-            SQL2Parser parser = new SQL2Parser(vf);
+            SQL2Parser parser = new SQL2Parser();
             parser.setSupportSQL1(true);
             q = parser.parse(statement);
         } else if (XPATH.equals(language)) {
             XPathToSQL2Converter converter = new XPathToSQL2Converter();
             String sql2 = converter.convert(statement);
-            SQL2Parser parser = new SQL2Parser(vf);
+            SQL2Parser parser = new SQL2Parser();
             try {
                 q = parser.parse(sql2);
             } catch (ParseException e) {
@@ -94,7 +91,7 @@ public class QueryEngineImpl {
     }
 
     public ResultImpl executeQuery(String statement, String language, 
-            long limit, long offset, Map<String, ? extends CoreValue> bindings,
+            long limit, long offset, Map<String, ? extends PropertyValue> bindings,
             Root root,
             NamePathMapper namePathMapper) throws ParseException {
         Query q = parseQuery(statement, language);
@@ -103,7 +100,7 @@ public class QueryEngineImpl {
         q.setLimit(limit);
         q.setOffset(offset);
         if (bindings != null) {
-            for (Entry<String, ? extends CoreValue> e : bindings.entrySet()) {
+            for (Entry<String, ? extends PropertyValue> e : bindings.entrySet()) {
                 q.bindValue(e.getKey(), e.getValue());
             }
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRowImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRowImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRowImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRowImpl.java Thu Oct 11 14:58:28 2012
@@ -16,10 +16,10 @@
  */
 package org.apache.jackrabbit.oak.query;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.query.ast.ColumnImpl;
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 
 /**
  * A query result row that keeps all data in memory.
@@ -28,10 +28,10 @@ public class ResultRowImpl implements Re
 
     private final Query query;
     private final String[] paths;
-    private final CoreValue[] values;
-    private final CoreValue[][] orderValues;
+    private final PropertyValue[] values;
+    private final PropertyValue[] orderValues;
 
-    ResultRowImpl(Query query, String[] paths, CoreValue[] values, CoreValue[][] orderValues) {
+    ResultRowImpl(Query query, String[] paths, PropertyValue[] values, PropertyValue[] orderValues) {
         this.query = query;
         this.paths = paths;
         this.values = values;
@@ -58,13 +58,13 @@ public class ResultRowImpl implements Re
     }
 
     @Override
-    public CoreValue getValue(String columnName) {
+    public PropertyValue getValue(String columnName) {
         return values[query.getColumnIndex(columnName)];
     }
 
     @Override
-    public CoreValue[] getValues() {
-        CoreValue[] v2 = new CoreValue[values.length];
+    public PropertyValue[] getValues() {
+        PropertyValue[] v2 = new PropertyValue[values.length];
         System.arraycopy(values, 0, v2, 0, values.length);
         return v2;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java Thu Oct 11 14:58:28 2012
@@ -16,11 +16,9 @@
  */
 package org.apache.jackrabbit.oak.query;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.query.ast.AstElementFactory;
-import org.apache.jackrabbit.oak.query.ast.Operator;
 import org.apache.jackrabbit.oak.query.ast.BindVariableValueImpl;
 import org.apache.jackrabbit.oak.query.ast.ColumnImpl;
 import org.apache.jackrabbit.oak.query.ast.ConstraintImpl;
@@ -28,12 +26,15 @@ import org.apache.jackrabbit.oak.query.a
 import org.apache.jackrabbit.oak.query.ast.JoinConditionImpl;
 import org.apache.jackrabbit.oak.query.ast.JoinType;
 import org.apache.jackrabbit.oak.query.ast.LiteralImpl;
+import org.apache.jackrabbit.oak.query.ast.Operator;
 import org.apache.jackrabbit.oak.query.ast.OrderingImpl;
 import org.apache.jackrabbit.oak.query.ast.PropertyExistenceImpl;
 import org.apache.jackrabbit.oak.query.ast.PropertyValueImpl;
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
 import org.apache.jackrabbit.oak.query.ast.SourceImpl;
 import org.apache.jackrabbit.oak.query.ast.StaticOperandImpl;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 
 import javax.jcr.PropertyType;
 import java.math.BigDecimal;
@@ -66,7 +67,7 @@ public class SQL2Parser {
     private int currentTokenType;
     private String currentToken;
     private boolean currentTokenQuoted;
-    private CoreValue currentValue;
+    private PropertyValue currentValue;
     private ArrayList<String> expected;
 
     // The bind variables
@@ -80,17 +81,14 @@ public class SQL2Parser {
     private boolean allowNumberLiterals = true;
 
     private final AstElementFactory factory = new AstElementFactory();
-    private final CoreValueFactory valueFactory;
 
     private boolean supportSQL1;
 
     /**
      * Create a new parser. A parser can be re-used, but it is not thread safe.
      *
-     * @param valueFactory the value factory
      */
-    public SQL2Parser(CoreValueFactory valueFactory) {
-        this.valueFactory = valueFactory;
+    public SQL2Parser() {
     }
 
     /**
@@ -136,7 +134,7 @@ public class SQL2Parser {
         if (!currentToken.isEmpty()) {
             throw getSyntaxError("<end>");
         }
-        Query q = new Query(source, constraint, orderings, columnArray, valueFactory);
+        Query q = new Query(source, constraint, orderings, columnArray);
         q.setExplain(explain);
         q.setMeasure(measure);
         try {
@@ -186,9 +184,9 @@ public class SQL2Parser {
     private String readName() throws ParseException {
         if (readIf("[")) {
             if (currentTokenType == VALUE) {
-                CoreValue value = readString();
+                PropertyValue value = readString();
                 read("]");
-                return value.getString();
+                return value.getValue(Type.STRING);
             } else {
                 int level = 1;
                 StringBuilder buff = new StringBuilder();
@@ -356,8 +354,8 @@ public class SQL2Parser {
                     if (!(esc instanceof LiteralImpl)) {
                         throw getSyntaxError("only ESCAPE '\' is supported");
                     }
-                    CoreValue v = ((LiteralImpl) esc).getLiteralValue();
-                    if (!v.getString().equals("\\")) {
+                    PropertyValue v = ((LiteralImpl) esc).getLiteralValue();
+                    if (!v.getValue(Type.STRING).equals("\\")) {
                         throw getSyntaxError("only ESCAPE '\' is supported");
                     }
                 }
@@ -518,7 +516,7 @@ public class SQL2Parser {
         } else if ("PROPERTY".equalsIgnoreCase(functionName)) {
             PropertyValueImpl pv = parsePropertyValue(readName());
             read(",");
-            op = factory.propertyValue(pv.getSelectorName(), pv.getPropertyName(), readString().getString());
+            op = factory.propertyValue(pv.getSelectorName(), pv.getPropertyName(), readString().getValue(Type.STRING));
         } else {
             throw getSyntaxError("LENGTH, NAME, LOCALNAME, SCORE, LOWER, UPPER, or PROPERTY");
         }
@@ -542,19 +540,19 @@ public class SQL2Parser {
             if (currentTokenType != VALUE) {
                 throw getSyntaxError("number");
             }
-            int valueType = currentValue.getType();
+            int valueType = currentValue.getType().tag();
             switch (valueType) {
             case PropertyType.LONG:
-                currentValue = valueFactory.createValue(-currentValue.getLong());
+                currentValue = PropertyValues.newLong(-currentValue.getValue(Type.LONG));
                 break;
             case PropertyType.DOUBLE:
-                currentValue = valueFactory.createValue(-currentValue.getDouble());
+                currentValue = PropertyValues.newDouble(-currentValue.getValue(Type.DOUBLE));
                 break;
             case PropertyType.BOOLEAN:
-                currentValue = valueFactory.createValue(!currentValue.getBoolean());
+                currentValue = PropertyValues.newBoolean(!currentValue.getValue(Type.BOOLEAN));
                 break;
             case PropertyType.DECIMAL:
-                currentValue = valueFactory.createValue(currentValue.getDecimal().negate());
+                currentValue = PropertyValues.newDecimal(currentValue.getValue(Type.DECIMAL).negate());
                 break;
             default:
                 throw getSyntaxError("Illegal operation: -" + currentValue);
@@ -577,10 +575,10 @@ public class SQL2Parser {
             }
             return var;
         } else if (readIf("TRUE")) {
-            LiteralImpl literal = getUncastLiteral(valueFactory.createValue(true));
+            LiteralImpl literal = getUncastLiteral(PropertyValues.newBoolean(true));
             return literal;
         } else if (readIf("FALSE")) {
-            LiteralImpl literal = getUncastLiteral(valueFactory.createValue(false));
+            LiteralImpl literal = getUncastLiteral(PropertyValues.newBoolean(false));
             return literal;
         } else if (readIf("CAST")) {
             read("(");
@@ -589,7 +587,7 @@ public class SQL2Parser {
                 throw getSyntaxError("literal");
             }
             LiteralImpl literal = (LiteralImpl) op;
-            CoreValue value = literal.getLiteralValue();
+            PropertyValue value = literal.getLiteralValue();
             read("AS");
             value = parseCastAs(value);
             read(")");
@@ -604,8 +602,8 @@ public class SQL2Parser {
                         throw getSyntaxError("literal");
                     }
                     LiteralImpl literal = (LiteralImpl) op;
-                    CoreValue value = literal.getLiteralValue();
-                    value = valueFactory.createValue(value.getString(), PropertyType.DATE);
+                    PropertyValue value = literal.getLiteralValue();
+                    value = PropertyValues.newDate(value.getValue(Type.STRING));
                     literal = factory.literal(value);
                     return literal;
                 }
@@ -620,44 +618,23 @@ public class SQL2Parser {
      * @param value the original value
      * @return the literal
      */
-    private LiteralImpl getUncastLiteral(CoreValue value) {
+    private LiteralImpl getUncastLiteral(PropertyValue value) {
         return factory.literal(value);
     }
 
-    private CoreValue parseCastAs(CoreValue value) throws ParseException {
+    private PropertyValue parseCastAs(PropertyValue value)
+            throws ParseException {
         if (currentTokenQuoted) {
             throw getSyntaxError("data type (STRING|BINARY|...)");
         }
         int propertyType = getPropertyTypeFromName(currentToken);
         read();
-        switch (propertyType) {
-        case PropertyType.STRING:
-            return valueFactory.createValue(value.getString());
-        case PropertyType.BINARY:
-            return valueFactory.createValue(value.getString(), PropertyType.BINARY);
-        case PropertyType.DATE:
-            return valueFactory.createValue(value.getString(), PropertyType.DATE);
-        case PropertyType.LONG:
-            return valueFactory.createValue(value.getLong());
-        case PropertyType.DOUBLE:
-            return valueFactory.createValue(value.getDouble());
-        case PropertyType.DECIMAL:
-            return valueFactory.createValue(value.getDecimal());
-        case PropertyType.BOOLEAN:
-            return valueFactory.createValue(value.getBoolean());
-        case PropertyType.NAME:
-            return valueFactory.createValue(value.getString(), PropertyType.NAME);
-        case PropertyType.PATH:
-            return valueFactory.createValue(value.getString(), PropertyType.PATH);
-        case PropertyType.REFERENCE:
-            return valueFactory.createValue(value.getString(), PropertyType.REFERENCE);
-        case PropertyType.WEAKREFERENCE:
-            return valueFactory.createValue(value.getString(), PropertyType.WEAKREFERENCE);
-        case PropertyType.URI:
-            return valueFactory.createValue(value.getString(), PropertyType.URI);
-        default:
+
+        PropertyValue v = PropertyValues.convert(value, propertyType, null);
+        if (v == null) {
             throw getSyntaxError("data type (STRING|BINARY|...)");
         }
+        return v;
     }
 
     /**
@@ -807,7 +784,7 @@ public class SQL2Parser {
         }
         String s;
         if (currentTokenType == VALUE) {
-            s = currentValue.getString();
+            s = currentValue.getValue(Type.STRING);
         } else {
             s = currentToken;
         }
@@ -815,11 +792,11 @@ public class SQL2Parser {
         return s;
     }
 
-    private CoreValue readString() throws ParseException {
+    private PropertyValue readString() throws ParseException {
         if (currentTokenType != VALUE) {
             throw getSyntaxError("string value");
         }
-        CoreValue value = currentValue;
+        PropertyValue value = currentValue;
         read();
         return value;
     }
@@ -999,7 +976,7 @@ public class SQL2Parser {
                         break;
                     }
                     checkLiterals(false);
-                    currentValue = valueFactory.createValue(number);
+                    currentValue = PropertyValues.newLong(number);
                     currentTokenType = VALUE;
                     currentToken = "0";
                     parseIndex = i;
@@ -1035,7 +1012,7 @@ public class SQL2Parser {
                 // (not in the JCR 1.0 spec)
                 // (confusing isn't it?)
                 currentTokenType = IDENTIFIER;
-                currentToken = currentValue.getString();
+                currentToken = currentValue.getValue(Type.STRING);
             }
             return;
         case CHAR_END:
@@ -1069,7 +1046,7 @@ public class SQL2Parser {
         }
         currentToken = "'";
         checkLiterals(false);
-        currentValue = valueFactory.createValue(result);
+        currentValue = PropertyValues.newString(result);
         parseIndex = i;
         currentTokenType = VALUE;
     }
@@ -1112,7 +1089,7 @@ public class SQL2Parser {
         }
         checkLiterals(false);
 
-        currentValue = valueFactory.createValue(bd);
+        currentValue = PropertyValues.newDecimal(bd);
         currentTokenType = VALUE;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java Thu Oct 11 14:58:28 2012
@@ -20,11 +20,11 @@ import java.text.ParseException;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.SessionQueryEngine;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
@@ -53,7 +53,7 @@ public class SessionQueryEngineImpl impl
 
     @Override
     public Result executeQuery(String statement, String language, long limit,
-            long offset, Map<String, ? extends CoreValue> bindings, Root root,
+            long offset, Map<String, ? extends PropertyValue> bindings, Root root,
             NamePathMapper namePathMapper) throws ParseException {
         return queryEngine.executeQuery(statement, language, limit, offset,
                 bindings, root, namePathMapper);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AstElementFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AstElementFactory.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AstElementFactory.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AstElementFactory.java Thu Oct 11 14:58:28 2012
@@ -13,7 +13,7 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 
 /**
  * A factory for syntax tree elements.
@@ -84,7 +84,7 @@ public class AstElementFactory {
         return new LengthImpl(propertyValue);
     }
 
-    public LiteralImpl literal(CoreValue literalValue) {
+    public LiteralImpl literal(PropertyValue literalValue) {
         return new LiteralImpl(literalValue);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/BindVariableValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/BindVariableValueImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/BindVariableValueImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/BindVariableValueImpl.java Thu Oct 11 14:58:28 2012
@@ -18,7 +18,7 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 
 /**
  * A bind variable.
@@ -46,7 +46,7 @@ public class BindVariableValueImpl exten
     }
 
     @Override
-    CoreValue currentValue() {
+    PropertyValue currentValue() {
         return query.getBindVariableValue(bindVariableName);
     }
 

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=1397098&r1=1397097&r2=1397098&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 Thu Oct 11 14:58:28 2012
@@ -18,9 +18,8 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
-import org.apache.jackrabbit.oak.query.Query;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 
 /**
  * A result column expression.
@@ -55,14 +54,14 @@ public class ColumnImpl extends AstEleme
         }
     }
 
-    public PropertyState currentProperty() {
+    public PropertyValue currentProperty() {
         if (propertyName == null) {
             // TODO for SELECT * FROM queries, currently return the path (for testing only)
             String p = selector.currentPath();
             if (p == null) {
                 return null;
             }
-            return PropertyStates.stringProperty(Query.JCR_PATH, p);
+            return PropertyValues.newString(p);
         }
         return selector.currentProperty(propertyName);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java Thu Oct 11 14:58:28 2012
@@ -18,11 +18,10 @@
  */
 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.CoreValues;
-import org.apache.jackrabbit.oak.query.Query;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 
 /**
  * A comparison operation (including "like").
@@ -51,67 +50,76 @@ public class ComparisonImpl extends Cons
         return operand2;
     }
 
+    public static int getType(PropertyValue p, int ifUnknown) {
+        if (p.count() > 0) {
+            return p.getType().tag();
+        }
+        return ifUnknown;
+    }
+
     @Override
     public boolean evaluate() {
         // JCR 2.0 spec, 6.7.16 Comparison:
         // "operand1 may evaluate to an array of values"
-        PropertyState p1 = operand1.currentProperty();
+        PropertyValue p1 = operand1.currentProperty();
         if (p1 == null) {
             return false;
         }
-        // "operand2 always evaluates to a scalar value"
-        CoreValue v2 = operand2.currentValue();
-        if (v2 == null) {
+        PropertyValue p2 = operand2.currentValue();
+        if (p2 == null) {
             // if the property doesn't exist, the result is always false
             // even for "null <> 'x'" (same as in SQL) 
             return false;
         }
-        boolean isArray = p1.isArray();
-        int v1Type = Query.getType(p1, v2.getType());
-        if (v1Type != v2.getType()) {
+        int v1Type = getType(p1, p2.getType().tag());
+        if (v1Type != p2.getType().tag()) {
             // "the value of operand2 is converted to the
             // property type of the value of operand1"
-            v2 = query.convert(v2, v1Type);
-            if (v2 == null) {
+            p2 = PropertyValues.convert(p2, v1Type, query.getNamePathMapper());
+            if (p2 == null) {
                 return false;
             }
         }
-        if (!isArray) {
-            return evaluate(CoreValues.getValue(p1), v2);
-        }
-        // for multi-valued properties: if any of the value matches,
-        // then return true
-        for (CoreValue v1 : CoreValues.getValues(p1)) {
-            if (evaluate(v1, v2)) {
-                return true;
-            }
-        }
-        return false;
+        return evaluate(p1, p2);
     }
 
-    private boolean evaluate(CoreValue v1, CoreValue v2) {
+    /**
+     * "operand2 always evaluates to a scalar value"
+     * 
+     * for multi-valued properties: if any of the value matches, then return true
+     * 
+     * @param p1
+     * @param p2
+     * @return
+     */
+    private boolean evaluate(PropertyValue p1, PropertyValue p2) {
         switch (operator) {
         case EQUAL:
-            return v1.equals(v2);
+            return PropertyValues.match(p1, p2);
+        case NOT_EQUAL:
+            return !PropertyValues.match(p1, p2);
         case GREATER_OR_EQUAL:
-            return v1.compareTo(v2) >= 0;
+            return p1.compareTo(p2) >= 0;
         case GREATER_THAN:
-            return v1.compareTo(v2) > 0;
+            return p1.compareTo(p2) > 0;
         case LESS_OR_EQUAL:
-            return v1.compareTo(v2) <= 0;
+            return p1.compareTo(p2) <= 0;
         case LESS_THAN:
-            return v1.compareTo(v2) < 0;
-        case NOT_EQUAL:
-            return !v1.equals(v2);
+            return p1.compareTo(p2) < 0;
         case LIKE:
-            return evaluateLike(v1, v2);
+            return evaluateLike(p1, p2);
         }
         throw new IllegalArgumentException("Unknown operator: " + operator);
     }
 
-    private static boolean evaluateLike(CoreValue v1, CoreValue v2) {
-        LikePattern like = new LikePattern(v2.getString());
-        return like.matches(v1.getString());
+    private static boolean evaluateLike(PropertyValue v1, PropertyValue v2) {
+        LikePattern like = new LikePattern(v2.getValue(Type.STRING));
+        for (String s : v1.getValue(Type.STRINGS)) {
+            if (like.matches(s)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     @Override
@@ -126,7 +134,7 @@ public class ComparisonImpl extends Cons
 
     @Override
     public void restrict(FilterImpl f) {
-        CoreValue v = operand2.currentValue();
+        PropertyValue v = operand2.currentValue();
         if (v != null) {
             operand1.restrict(f, operator, v);
             // TODO OAK-347
@@ -155,8 +163,7 @@ public class ComparisonImpl extends Cons
 
     @Override
     public void restrictPushDown(SelectorImpl s) {
-        CoreValue v = operand2.currentValue();
-        if (v != null) {
+        if (operand2.currentValue() != null) {
             if (operand1.canRestrictSelector(s)) {
                 s.restrictSelector(this);
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java Thu Oct 11 14:58:28 2012
@@ -16,18 +16,17 @@
  */
 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.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 
 /**
  * The base class for dynamic operands (such as a function or property).
  */
 public abstract class DynamicOperandImpl extends AstElement {
 
-    public abstract PropertyState currentProperty();
+    public abstract PropertyValue currentProperty();
 
-    public abstract void restrict(FilterImpl f, Operator operator, CoreValue v);
+    public abstract void restrict(FilterImpl f, Operator operator, PropertyValue v);
 
     /**
      * Check whether the condition can be applied to a selector (to restrict the

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/EquiJoinConditionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/EquiJoinConditionImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/EquiJoinConditionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/EquiJoinConditionImpl.java Thu Oct 11 14:58:28 2012
@@ -18,11 +18,9 @@
  */
 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.CoreValues;
-import org.apache.jackrabbit.oak.query.Query;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 
 /**
  * The "a.x = b.y" join condition.
@@ -62,61 +60,53 @@ public class EquiJoinConditionImpl exten
 
     @Override
     public boolean evaluate() {
-        PropertyState p1 = selector1.currentProperty(property1Name);
+        PropertyValue p1 = selector1.currentProperty(property1Name);
         if (p1 == null) {
             return false;
         }
-        PropertyState p2 = selector2.currentProperty(property2Name);
+        PropertyValue p2 = selector2.currentProperty(property2Name);
         if (p2 == null) {
             return false;
         }
         if (!p1.isArray() && !p2.isArray()) {
             // both are single valued
-            return CoreValues.getValue(p1).equals(CoreValues.getValue(p2));
+            return PropertyValues.match(p1, p2);
         }
         // TODO what is the expected result of an equi join for multi-valued properties?
         if (!p1.isArray() && p2.isArray()) {
-            CoreValue x = CoreValues.getValue(p1);
-            for (CoreValue y : CoreValues.getValues(p2)) {
-                if (y.getType() != x.getType()) {
-                    y = query.convert(y, x.getType());
-                }
-                if (y != null && x.equals(y)) {
-                    return true;
-                }
+            if (p1.getType().tag() != p2.getType().tag()) {
+                p1 = PropertyValues.convert(p1, p2.getType().tag(), query.getNamePathMapper());
+            }
+            if (p1 != null && PropertyValues.match(p1, p2)) {
+                return true;
             }
             return false;
         } else if (p1.isArray() && !p2.isArray()) {
-            CoreValue x = CoreValues.getValue(p2);
-            for (CoreValue y : CoreValues.getValues(p1)) {
-                if (y.getType() != x.getType()) {
-                    y = query.convert(y, x.getType());
-                }
-                if (x.equals(y)) {
-                    return true;
-                }
+            if (p1.getType().tag() != p2.getType().tag()) {
+                p2 = PropertyValues.convert(p2, p1.getType().tag(), query.getNamePathMapper());
+            }
+            if (p2 != null && PropertyValues.match(p1, p2)) {
+                return true;
             }
             return false;
         }
-        CoreValue[] l1 = CoreValues.getValues(p1).toArray(new CoreValue[p1.count()]);
-        CoreValue[] l2 = CoreValues.getValues(p2).toArray(new CoreValue[p2.count()]);
-        return Query.compareValues(l1, l2) == 0;
+        return PropertyValues.match(p1, p2);
     }
 
     @Override
     public void restrict(FilterImpl f) {
-        PropertyState p1 = selector1.currentProperty(property1Name);
-        PropertyState p2 = selector2.currentProperty(property2Name);
+        PropertyValue p1 = selector1.currentProperty(property1Name);
+        PropertyValue p2 = selector2.currentProperty(property2Name);
         if (f.getSelector() == selector1 && p2 != null) {
             if (!p2.isArray()) {
                 // TODO support join on multi-valued properties
-                f.restrictProperty(property1Name, Operator.EQUAL, CoreValues.getValue(p2));
+                f.restrictProperty(property1Name, Operator.EQUAL, p2);
             }
         }
         if (f.getSelector() == selector2 && p1 != null) {
             if (!p1.isArray()) {
                 // TODO support join on multi-valued properties
-                f.restrictProperty(property2Name, Operator.EQUAL, CoreValues.getValue(p1));
+                f.restrictProperty(property2Name, Operator.EQUAL, p1);
             }
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java?rev=1397098&r1=1397097&r2=1397098&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java Thu Oct 11 14:58:28 2012
@@ -18,17 +18,18 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+
 import java.text.ParseException;
 import java.util.ArrayList;
 
-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.api.Type;
 import org.apache.jackrabbit.oak.query.ast.ComparisonImpl.LikePattern;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
-
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
 
 /**
  * A fulltext "contains(...)" condition.
@@ -77,7 +78,7 @@ public class FullTextSearchImpl extends 
     public boolean evaluate() {
         StringBuilder buff = new StringBuilder();
         if (propertyName != null) {
-            PropertyState p = selector.currentProperty(propertyName);
+            PropertyValue p = selector.currentProperty(propertyName);
             if (p == null) {
                 return false;
             }
@@ -95,9 +96,9 @@ public class FullTextSearchImpl extends 
         // if a fulltext index is used, to avoid filtering too much
         // (we don't know what exact options are used in the fulltext index)
         // (stop word, special characters,...)
-        CoreValue v = fullTextSearchExpression.currentValue();
+        PropertyValue v = fullTextSearchExpression.currentValue();
         try {
-            FullTextExpression expr = FullTextParser.parse(v.getString());
+            FullTextExpression expr = FullTextParser.parse(v.getValue(Type.STRING));
             return expr.evaluate(buff.toString());
         } catch (ParseException e) {
             throw new IllegalArgumentException("Invalid expression: " + fullTextSearchExpression, e);
@@ -122,10 +123,10 @@ public class FullTextSearchImpl extends 
     public void restrict(FilterImpl f) {
         if (propertyName != null) {
             if (f.getSelector() == selector) {
-                f.restrictProperty(propertyName, Operator.NOT_EQUAL, (CoreValue) null);
+                f.restrictProperty(propertyName, Operator.NOT_EQUAL, null);
             }
         }
-        f.restrictFulltextCondition(fullTextSearchExpression.currentValue().getString());
+        f.restrictFulltextCondition(fullTextSearchExpression.currentValue().getValue(Type.STRING));
     }
 
     @Override

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=1397098&r1=1397097&r2=1397098&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 Thu Oct 11 14:58:28 2012
@@ -18,11 +18,10 @@
  */
 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;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 
 /**
  * A fulltext search score expression.
@@ -47,11 +46,11 @@ public class FullTextSearchScoreImpl ext
     }
 
     @Override
-    public PropertyState currentProperty() {
-        PropertyState p = selector.currentProperty(Query.JCR_SCORE);
+    public PropertyValue currentProperty() {
+        PropertyValue p = selector.currentProperty(Query.JCR_SCORE);
         if (p == null) {
             // TODO if score() is not supported by the index, use the value 0.0?
-            return PropertyStates.doubleProperty(Query.JCR_SCORE, 0.0);
+            return PropertyValues.newDouble(0.0);
         }
         return p;
     }
@@ -61,7 +60,7 @@ public class FullTextSearchScoreImpl ext
     }
 
     @Override
-    public void restrict(FilterImpl f, Operator operator, CoreValue v) {
+    public void restrict(FilterImpl f, Operator operator, PropertyValue v) {
         if (f.getSelector() == selector) {
             if (operator == Operator.NOT_EQUAL && v != null) {
                 // not supported

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=1397098&r1=1397097&r2=1397098&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 Thu Oct 11 14:58:28 2012
@@ -20,10 +20,10 @@ package org.apache.jackrabbit.oak.query.
 
 import javax.jcr.PropertyType;
 
-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.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.query.PropertyValue;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 
 /**
  * The function "length(..)".
@@ -51,23 +51,23 @@ public class LengthImpl extends DynamicO
     }
 
     @Override
-    public PropertyState currentProperty() {
+    public PropertyValue currentProperty() {
         PropertyState p = propertyValue.currentProperty();
         if (p == null) {
             return null;
         }
         if (!p.isArray()) {
             long length = p.size();
-            return PropertyStates.longProperty("LENGTH", length);
+            return PropertyValues.newLong(length);
         }
         // TODO what is the expected result for LENGTH(multiValueProperty)?
         throw new IllegalArgumentException("LENGTH(x) on multi-valued property is not supported");
     }
 
     @Override
-    public void restrict(FilterImpl f, Operator operator, CoreValue v) {
+    public void restrict(FilterImpl f, Operator operator, PropertyValue v) {
         if (v != null) {
-            switch (v.getType()) {
+            switch (v.getType().tag()) {
             case PropertyType.LONG:
             case PropertyType.DECIMAL:
             case PropertyType.DOUBLE:
@@ -81,7 +81,7 @@ public class LengthImpl extends DynamicO
             default:
                 throw new IllegalArgumentException(
                         "Can not compare the length with a constant of type "
-                                + PropertyType.nameFromValue(v.getType()) +
+                                + PropertyType.nameFromValue(v.getType().tag()) +
                                 " and value " + v.toString());
             }
         }



Mime
View raw message