You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2012/02/01 20:29:31 UTC

svn commit: r1239282 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory: query/InMemoryQueryProcessor.java types/PropertyUtil.java

Author: jens
Date: Wed Feb  1 19:29:31 2012
New Revision: 1239282

URL: http://svn.apache.org/viewvc?rev=1239282&view=rev
Log:
InMemory server: fix a small bug where some query operators fail on system properties

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyUtil.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java?rev=1239282&r1=1239281&r2=1239282&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java Wed Feb  1 19:29:31 2012
@@ -341,14 +341,14 @@ public class InMemoryQueryProcessor {
         public Boolean walkIn(Tree opNode, Tree colNode, Tree listNode) {
             ColumnReference colRef = getColumnReference(colNode);
             PropertyDefinition<?> pd = colRef.getPropertyDefinition();
-            PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
             List<Object> literals = onLiteralList(listNode);
+            Object prop = PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
+
             if (pd.getCardinality() != Cardinality.SINGLE) {
                 throw new IllegalStateException("Operator IN only is allowed on single-value properties ");
-            } else if (lVal == null) {
+            } else if (prop == null) {
                 return false;
             } else {
-                Object prop = lVal.getFirstValue();
                 return literals.contains(prop);
             }
         }
@@ -360,14 +360,13 @@ public class InMemoryQueryProcessor {
             // then it evaluates to true for null values (not set properties).
             ColumnReference colRef = getColumnReference(colNode);
             PropertyDefinition<?> pd = colRef.getPropertyDefinition();
-            PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
+            Object prop = PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
             List<Object> literals = onLiteralList(listNode);
             if (pd.getCardinality() != Cardinality.SINGLE) {
                 throw new IllegalStateException("Operator IN only is allowed on single-value properties ");
-            } else if (lVal == null) {
+            } else if (prop == null) {
                 return false;
             } else {
-                Object prop = lVal.getFirstValue();
                 return !literals.contains(prop);
             }
         }
@@ -437,13 +436,17 @@ public class InMemoryQueryProcessor {
 
         @Override
         public Boolean walkIsNull(Tree opNode, Tree colNode) {
-            Object propVal = getPropertyValue(colNode, so);
+            ColumnReference colRef = getColumnReference(colNode);
+            PropertyDefinition<?> pd = colRef.getPropertyDefinition();
+            Object propVal = PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
             return propVal == null;
         }
 
         @Override
         public Boolean walkIsNotNull(Tree opNode, Tree colNode) {
-            Object propVal = getPropertyValue(colNode, so);
+            ColumnReference colRef = getColumnReference(colNode);
+            PropertyDefinition<?> pd = colRef.getPropertyDefinition();
+            Object propVal = PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
             return propVal != null;
         }
 
@@ -465,7 +468,7 @@ public class InMemoryQueryProcessor {
                 throw new IllegalStateException("LIKE is not allowed for multi-value properties ");
             }
 
-            String propVal = (String) PropertyUtil.getProperty(so, colRef.getPropertyId());
+            String propVal = (String) PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
             
             String pattern = translatePattern((String) rVal); // SQL to Java
                                                               // regex
@@ -528,10 +531,10 @@ public class InMemoryQueryProcessor {
             // System.identityHashCode(leftChild) + " is " + leftChild);
             ColumnReference colRef = getColumnReference(leftChild);
             PropertyDefinition<?> pd = colRef.getPropertyDefinition();
-            Object val = PropertyUtil.getProperty(so, colRef.getPropertyId());
+            Object val = PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
             if (val==null) {
                 return null;
-            }if (val instanceof List<?>) {
+            } else if (val instanceof List<?>) {
                 throw new IllegalStateException("You can't query operators <, <=, ==, !=, >=, > on multi-value properties ");
             } else {
                 return InMemoryQueryProcessor.this.compareTo(pd, val, rVal);
@@ -709,19 +712,10 @@ public class InMemoryQueryProcessor {
         return typeQueryName;
     }
 
-    private Object getPropertyValue(Tree columnNode, StoredObject so) {
+    private Object xgetPropertyValue(Tree columnNode, StoredObject so) {
         ColumnReference colRef = getColumnReference(columnNode);
         PropertyDefinition<?> pd = colRef.getPropertyDefinition();
-        PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
-        if (null == lVal) {
-            return null;
-        } else {
-            if (pd.getCardinality() == Cardinality.SINGLE) {
-                return lVal.getFirstValue();
-            } else {
-                return lVal.getValues();
-            }
-        }
+        return PropertyUtil.getProperty(so, colRef.getPropertyId(), pd);
     }
 
     // translate SQL wildcards %, _ to Java regex syntax

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyUtil.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyUtil.java?rev=1239282&r1=1239281&r2=1239282&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyUtil.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyUtil.java Wed Feb  1 19:29:31 2012
@@ -21,6 +21,8 @@ package org.apache.chemistry.opencmis.in
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.enums.Cardinality;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Content;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Document;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
@@ -30,7 +32,7 @@ import org.apache.chemistry.opencmis.inm
 
 public class PropertyUtil {
     
-    public static Object getProperty(StoredObject so, String propertyId) {
+    public static Object getProperty(StoredObject so, String propertyId, PropertyDefinition<?> pd) {
         ContentStream content = null;
         DocumentVersion ver = null;
         VersionedDocument verDoc = null;
@@ -146,10 +148,12 @@ public class PropertyUtil {
 
        // try custom property:
        PropertyData<?> lVal = so.getProperties().get(propertyId);
-       if (lVal != null) {
-           return lVal.getValues().size() > 1 ? lVal.getValues() : lVal.getFirstValue();
-       }  else {
+       if (null == lVal)
            return null;
+       else if (pd.getCardinality() == Cardinality.SINGLE) {
+           return lVal.getFirstValue();
+       } else {
+           return lVal.getValues();
        }
     }