chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1236118 - in /chemistry/opencmis/trunk/chemistry-opencmis-server: chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/ chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis...
Date Thu, 26 Jan 2012 09:43:29 GMT
Author: jens
Date: Thu Jan 26 09:43:29 2012
New Revision: 1236118

URL: http://svn.apache.org/viewvc?rev=1236118&view=rev
Log:
fix query parser and InMemory server to support muliple aliases on same property [CMIS-496]

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/PropertyCreationHelper.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.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=1236118&r1=1236117&r2=1236118&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
Thu Jan 26 09:43:29 2012
@@ -142,8 +142,8 @@ public class InMemoryQueryProcessor {
             matches = matches.subList(start, stop);
         }
         List<ObjectData> objDataList = new ArrayList<ObjectData>();
-        Map<String, String> props = queryObj.getRequestedProperties();
-        Map<String, String> funcs = queryObj.getRequestedFuncs();
+        Map<String, String> props = queryObj.getRequestedPropertiesByAlias();
+        Map<String, String> funcs = queryObj.getRequestedFuncsByAlias();
         for (StoredObject so : matches) {
             TypeDefinition td = tm.getTypeById(so.getTypeId()).getTypeDefinition();
             ObjectData od = PropertyCreationHelper.getObjectDataQueryResult(td, so, user,
props, funcs,

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.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/PropertyCreationHelper.java?rev=1236118&r1=1236117&r2=1236118&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
Thu Jan 26 09:43:29 2012
@@ -247,7 +247,7 @@ public class PropertyCreationHelper {
             Map<String, String> requestedIds, Map<String, String> requestedFuncs)
{
         // build properties collection
 
-        List<String> idList = new ArrayList<String>(requestedIds.keySet());
+        List<String> idList = new ArrayList<String>(requestedIds.values());
         BindingsObjectFactory objectFactory = new BindingsObjectFactoryImpl();
         Map<String, PropertyData<?>> properties = new HashMap<String, PropertyData<?>>();
         so.fillProperties(properties, objectFactory, idList);
@@ -265,41 +265,40 @@ public class PropertyCreationHelper {
         }
 
         Map<String, PropertyData<?>> mappedProperties = new HashMap<String,
PropertyData<?>>();
-        if (requestedIds.containsKey("*")) {
+        if (requestedIds.containsValue("*")) {
             for (Map.Entry<String, PropertyData<?>> prop : properties.entrySet())
{
                 // map property id to property query name
                 String queryName = td.getPropertyDefinitions().get(prop.getKey()).getQueryName();
                 String localName = td.getPropertyDefinitions().get(prop.getKey()).getLocalName();
                 String displayName = td.getPropertyDefinitions().get(prop.getKey()).getDisplayName();
-                AbstractPropertyData<?> ad = (AbstractPropertyData<?>) prop.getValue();
// a
-                                                                                        //
bit
-                                                                                        //
dirty
+                AbstractPropertyData<?> ad = clonePropertyData(prop.getValue()); 
+                
                 ad.setQueryName(queryName);
                 ad.setLocalName(localName);
                 ad.setDisplayName(displayName);
-                mappedProperties.put(queryName, prop.getValue());
+                mappedProperties.put(queryName, ad);
             }
         } else {
             // replace all ids with query names or alias:
-            for (Map.Entry<String, PropertyData<?>> prop : properties.entrySet())
{
-                String queryNameOrAlias = requestedIds.get(prop.getKey());
-                String localName = td.getPropertyDefinitions().get(prop.getKey()).getLocalName();
-                String displayName = td.getPropertyDefinitions().get(prop.getKey()).getDisplayName();
-                AbstractPropertyData<?> ad = (AbstractPropertyData<?>) prop.getValue();
// a
-                                                                                        //
bit
-                                                                                        //
dirty
+            for (Entry<String, String> propAlias : requestedIds.entrySet()) {
+                String queryNameOrAlias = propAlias.getKey();
+                PropertyData<?> prop = properties.get(propAlias.getValue());
+                String localName = td.getPropertyDefinitions().get(prop.getId()).getLocalName();
+                String displayName = td.getPropertyDefinitions().get(prop.getId()).getDisplayName();
+                AbstractPropertyData<?> ad = clonePropertyData(prop); 
+                
                 ad.setQueryName(queryNameOrAlias);
                 ad.setLocalName(localName);
                 ad.setDisplayName(displayName);
-                mappedProperties.put(queryNameOrAlias, prop.getValue());
+                mappedProperties.put(queryNameOrAlias, ad);
             }
         }
         // add functions:
         BindingsObjectFactory objFactory = new BindingsObjectFactoryImpl();
         for (Entry<String, String> funcEntry : requestedFuncs.entrySet()) {
-            PropertyInteger pi = objFactory.createPropertyIntegerData(funcEntry.getKey(),
BigInteger.valueOf(100));
+            PropertyInteger pi = objFactory.createPropertyIntegerData(funcEntry.getValue(),
BigInteger.valueOf(100));
             // fixed dummy value
-            mappedProperties.put(funcEntry.getValue(), pi);
+            mappedProperties.put(funcEntry.getKey(), pi);
         }
 
         Properties props = new PropertiesImpl(mappedProperties.values());
@@ -451,4 +450,52 @@ public class PropertyCreationHelper {
         else
             return null;
     }
+    
+    private static AbstractPropertyData<?> clonePropertyData(PropertyData<?>
prop) {
+        AbstractPropertyData<?> ad = null;
+        
+        if (prop instanceof PropertyBooleanImpl) {
+            PropertyBooleanImpl clone = new PropertyBooleanImpl();
+            clone.setValues(((PropertyBooleanImpl)prop).getValues());
+            ad = clone;
+        } else if (prop instanceof PropertyDateTimeImpl) {
+            PropertyDateTimeImpl clone = new PropertyDateTimeImpl();
+            clone.setValues(((PropertyDateTimeImpl)prop).getValues());
+            ad = clone;
+        } else if (prop instanceof PropertyDecimalImpl) {
+            PropertyDecimalImpl clone = new PropertyDecimalImpl();
+            clone.setValues(((PropertyDecimalImpl)prop).getValues());
+            ad = clone;
+        } else if (prop instanceof PropertyHtmlImpl) {
+            PropertyHtmlImpl clone = new PropertyHtmlImpl();
+            clone.setValues(((PropertyHtmlImpl)prop).getValues());
+            ad = clone;
+        } else if (prop instanceof PropertyIdImpl) {
+            PropertyIdImpl clone = new PropertyIdImpl();
+            clone.setValues(((PropertyIdImpl)prop).getValues());
+            ad = clone;
+        } else if (prop instanceof PropertyIntegerImpl) {
+            PropertyIntegerImpl clone = new PropertyIntegerImpl();
+            clone.setValues(((PropertyIntegerImpl)prop).getValues());
+            ad = clone;
+        } else if (prop instanceof PropertyStringImpl) {
+            PropertyStringImpl clone = new PropertyStringImpl();
+            clone.setValues(((PropertyStringImpl)prop).getValues());
+            ad = clone;
+        } else if (prop instanceof PropertyUriImpl) {
+            PropertyUriImpl clone = new PropertyUriImpl();
+            clone.setValues(((PropertyUriImpl)prop).getValues());
+            ad = clone;
+        } else {
+            throw new RuntimeException("Unknown property type: " + prop.getClass());
+        }
+        
+        ad.setDisplayName(prop.getDisplayName());
+        ad.setId(prop.getId());
+        ad.setLocalName(prop.getLocalName());
+        ad.setQueryName(prop.getQueryName());
+        ad.setExtensions(prop.getExtensions());
+
+        return ad;        
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java?rev=1236118&r1=1236117&r2=1236118&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
Thu Jan 26 09:43:29 2012
@@ -235,11 +235,31 @@ public class QueryObject {
      * return a map of all columns that have been requested in the SELECT part
      * of the statement.
      *
+     * @return a map with a String as a key and value. key is the alias if 
+     * an alias was given or the query name otherwise. value is the query 
+     * name of the property.
+     */
+    public Map<String, String> getRequestedPropertiesByAlias() {
+        return getRequestedProperties(true);
+    }
+    
+    /**
+     * return a map of all columns that have been requested in the SELECT part
+     * of the statement.
+     *
      * @return a map with a String as a key and value. key is the query name of
      *         the property, value is the alias if an alias was given or the
      *         query name otherwise.
+     *         
+     * @deprecated  Use getRequestedPropertiesByAlias instead.
      */
+    @Deprecated
     public Map<String, String> getRequestedProperties() {
+        return getRequestedProperties(false);
+    }
+    
+    private Map<String, String> getRequestedProperties(boolean byAlias) {
+
         Map<String, String> res = new HashMap<String, String>();
         for (CmisSelector sel : selectReferences) {
             if (sel instanceof ColumnReference) {
@@ -251,7 +271,10 @@ public class QueryObject {
                 }
                 String propDescr = colRef.getAliasName() == null ? colRef.getPropertyQueryName()
: colRef
                         .getAliasName();
-                res.put(key, propDescr);
+                if (byAlias)
+                    res.put(propDescr, key);
+                else
+                    res.put(key, propDescr);
             }
         }
         return res;
@@ -264,14 +287,37 @@ public class QueryObject {
      * @return a map with a String as a key and value. key is the function name
      *         of the property, value is the alias if an alias was given or the
      *         function name otherwise.
+     *         
+     * @deprecated  Use getRequestedPropertiesByAlias instead.
      */
+    @Deprecated
     public Map<String, String> getRequestedFuncs() {
+        return getRequestedFuncs(false);
+    }
+    
+    /**
+     * return a map of all functions that have been requested in the SELECT part
+     * of the statement.
+     *
+     * @return a map with a String as a key and value. key is the alias if an 
+     * alias was given or the function name otherwise, value is the a name
+     * of the property. 
+     */
+    public Map<String, String> getRequestedFuncsByAlias() {
+        return getRequestedFuncs(true);
+    }
+
+    private Map<String, String> getRequestedFuncs(boolean byAlias) {
+
         Map<String, String> res = new HashMap<String, String>();
         for (CmisSelector sel : selectReferences) {
             if (sel instanceof FunctionReference) {
                 FunctionReference funcRef = (FunctionReference) sel;
                 String propDescr = funcRef.getAliasName() == null ? funcRef.getName() : funcRef.getAliasName();
-                res.put(funcRef.getName(), propDescr);
+                if (byAlias)
+                    res.put(propDescr, funcRef.getName());
+                else
+                    res.put(funcRef.getName(), propDescr);
             }
         }
         return res;



Mime
View raw message