jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1383892 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query: Query.java ast/ComparisonImpl.java ast/EquiJoinConditionImpl.java
Date Wed, 12 Sep 2012 11:35:31 GMT
Author: thomasm
Date: Wed Sep 12 11:35:30 2012
New Revision: 1383892

URL: http://svn.apache.org/viewvc?rev=1383892&view=rev
Log:
OAK-28 Query implementation: queries should not fail just because the value can't be converted

Modified:
    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/ast/ComparisonImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/EquiJoinConditionImpl.java

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=1383892&r1=1383891&r2=1383892&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
Wed Sep 12 11:35:30 2012
@@ -420,6 +420,13 @@ public class Query {
         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
@@ -444,40 +451,49 @@ public class Query {
             }
             return vf.createValue(v.getString(), targetType);
         }
-        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);
+        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) + ">");
         }
-        throw new IllegalArgumentException("Unknown property type: " + targetType);
     }
 
     public String getOakPath(String jcrPath) {

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=1383892&r1=1383891&r2=1383892&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
Wed Sep 12 11:35:30 2012
@@ -71,6 +71,9 @@ public class ComparisonImpl extends Cons
             // "the value of operand2 is converted to the
             // property type of the value of operand1"
             v2 = query.convert(v2, v1Type);
+            if (v2 == null) {
+                return false;
+            }
         }
         if (!isArray) {
             return evaluate(p1.getValue(), v2);

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=1383892&r1=1383891&r2=1383892&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
Wed Sep 12 11:35:30 2012
@@ -97,7 +97,7 @@ public class EquiJoinConditionImpl exten
                 if (y.getType() != x.getType()) {
                     y = query.convert(y, x.getType());
                 }
-                if (x.equals(y)) {
+                if (y != null && x.equals(y)) {
                     return true;
                 }
             }



Mime
View raw message