chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r815786 - in /incubator/chemistry/branches/0.62/chemistry: chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/ chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/ chemistry-commons/src/main/antlr3/or...
Date Wed, 16 Sep 2009 13:55:00 GMT
Author: fguillaume
Date: Wed Sep 16 13:54:59 2009
New Revision: 815786

URL: http://svn.apache.org/viewvc?rev=815786&view=rev
Log:
More JOIN support, allow returning result sets from joins

Modified:
    incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
    incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
    incubator/chemistry/branches/0.62/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java
    incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
    incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
    incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java
    incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
    incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
Wed Sep 16 13:54:59 2009
@@ -367,7 +367,8 @@
     public boolean isMediaEntry(ObjectEntry object)
             throws ResponseContextException {
         SPI spi = repository.getSPI(); // TODO XXX connection leak
-        return spi.hasContentStream(object);
+        return getContentType(object) != null && getContentSize(object) != -1
+                && spi.hasContentStream(object);
     }
 
     @Override

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISTypesCollection.java
Wed Sep 16 13:54:59 2009
@@ -228,7 +228,7 @@
                 if (defaultValue != null) {
                     Element dv = factory.newElement(CMIS.DEFAULT_VALUE, def);
                     for (String s : PropertiesElement.getStringsForValue(
-                            defaultValue, pd)) {
+                            defaultValue, pd.getType(), pd.isMultiValued())) {
                         el = factory.newElement(CMIS.VALUE, dv);
                         el.setText(s);
                     }

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/abdera/PropertiesElement.java
Wed Sep 16 13:54:59 2009
@@ -136,9 +136,20 @@
     }
 
     public void setProperties(Map<String, Serializable> values, Type type) {
-        for (PropertyDefinition propertyDefinition : type.getPropertyDefinitions()) {
-            setProperty(values.get(propertyDefinition.getId()),
-                    propertyDefinition);
+        if (type != null) {
+            for (PropertyDefinition propertyDefinition : type.getPropertyDefinitions()) {
+                setProperty(values.get(propertyDefinition.getId()),
+                        propertyDefinition);
+            }
+        } else {
+            // this is a simple record set from a query result, guess the types
+            // TODO should get an ObjectEntry here, which should type its values
+            for (Entry<String, Serializable> entry : values.entrySet()) {
+                String key = entry.getKey();
+                Serializable value = entry.getValue();
+                PropertyType propertyType = guessType(key, value);
+                setProperty(key, value, propertyType);
+            }
         }
     }
 
@@ -148,8 +159,10 @@
             // TODO assumes this isn't called several times
             return;
         }
-        QName qname = propertyQName(propertyDefinition);
-        List<String> values = getStringsForValue(value, propertyDefinition);
+        QName qname = propertyQName(propertyDefinition.getType());
+        List<String> values = getStringsForValue(value,
+                propertyDefinition.getType(),
+                propertyDefinition.isMultiValued());
         ExtensibleElement el = addExtension(qname);
         el.setAttributeValue(CMIS.PDID, propertyDefinition.getId());
         String localName = propertyDefinition.getLocalName();
@@ -167,6 +180,24 @@
         }
     }
 
+    // sets a property without all the type information, used for result sets
+    public void setProperty(String key, Serializable value, PropertyType propertyType) {
+        if (value == null) {
+            // TODO assumes this isn't called several times
+            return;
+        }
+        QName qname = propertyQName(propertyType);
+        boolean multi = false;
+        List<String> values = getStringsForValue(value, propertyType, multi);
+        ExtensibleElement el = addExtension(qname);
+        el.setAttributeValue(CMIS.PDID, key);
+        for (String s : values) {
+            Element val = el.addExtension(CMIS.VALUE);
+            // don't merge these two lines as JDK 5 has problems compiling it
+            val.setText(s);
+        }
+    }
+
     /**
      * Finds the list of Strings that are the XML form for the value.
      *
@@ -177,8 +208,7 @@
     // TODO move this to a helper somewhere else
     @SuppressWarnings( { "null", "unchecked" })
     public static List<String> getStringsForValue(Serializable value,
-            PropertyDefinition propertyDefinition) {
-        boolean multi = propertyDefinition.isMultiValued();
+            PropertyType propertyType, boolean multi) {
         List<String> values = null;
         if (multi) {
             if (value.getClass().isArray()) {
@@ -192,8 +222,7 @@
                 return null;
             }
         }
-        PropertyType type = propertyDefinition.getType();
-        switch (type.ordinal()) {
+        switch (propertyType.ordinal()) {
         case PropertyType.STRING_ORD:
         case PropertyType.ID_ORD:
             if (multi) {
@@ -239,21 +268,21 @@
             }
             break;
         case PropertyType.URI_ORD:
-            throw new UnsupportedOperationException(type.toString());
+            throw new UnsupportedOperationException(propertyType.toString());
         case PropertyType.XML_ORD:
-            throw new UnsupportedOperationException(type.toString());
+            throw new UnsupportedOperationException(propertyType.toString());
         case PropertyType.HTML_ORD:
-            throw new UnsupportedOperationException(type.toString());
+            throw new UnsupportedOperationException(propertyType.toString());
         case PropertyType.XHTML_ORD:
-            throw new UnsupportedOperationException(type.toString());
+            throw new UnsupportedOperationException(propertyType.toString());
         default:
-            throw new UnsupportedOperationException(type.toString());
+            throw new UnsupportedOperationException(propertyType.toString());
         }
         return values;
     }
 
-    protected static QName propertyQName(PropertyDefinition def) {
-        switch (def.getType().ordinal()) {
+    protected static QName propertyQName(PropertyType propertyType) {
+        switch (propertyType.ordinal()) {
         case PropertyType.STRING_ORD:
             return CMIS.PROPERTY_STRING;
         case PropertyType.DECIMAL_ORD:
@@ -275,8 +304,41 @@
         case PropertyType.XHTML_ORD:
             return CMIS.PROPERTY_XHTML;
         default:
-            throw new UnsupportedOperationException(def.getType().toString());
+            throw new UnsupportedOperationException(propertyType.toString());
+        }
+    }
+
+    // TODO XXX we shouldn't guess, values should be typed in ObjectEntry
+    protected static PropertyType guessType(String key, Serializable value) {
+        for (String n : Arrays.asList( //
+                Property.ID, //
+                Property.TYPE_ID, //
+                Property.BASE_TYPE_ID, //
+                Property.VERSION_SERIES_ID, //
+                Property.VERSION_SERIES_CHECKED_OUT_ID, //
+                Property.PARENT_ID, //
+                Property.SOURCE_ID, //
+                Property.TARGET_ID)) {
+            if (key.toUpperCase().endsWith(n.toUpperCase())) {
+                return PropertyType.ID;
+            }
+        }
+        if (value instanceof String) {
+            return PropertyType.STRING;
+        }
+        if (value instanceof BigDecimal) {
+            return PropertyType.DECIMAL;
+        }
+        if (value instanceof Number) {
+            return PropertyType.INTEGER;
+        }
+        if (value instanceof Boolean) {
+            return PropertyType.BOOLEAN;
+        }
+        if (value instanceof Calendar) {
+            return PropertyType.DATETIME;
         }
+        return PropertyType.STRING;
     }
 
     @SuppressWarnings("boxing")

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/cmissql/CmisSqlParser.g
Wed Sep 16 13:54:59 2009
@@ -225,8 +225,8 @@
     ;
 
 sort_specification:
-      column_name -> column_name ASC
-    | column_name ( ASC | DESC )
+      column_reference -> column_reference ASC
+    | column_reference ( ASC | DESC )
     ;
 
 correlation_name:

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/antlr3/org/apache/chemistry/impl/simple/CmisSqlSimpleWalker.g
Wed Sep 16 13:54:59 2009
@@ -271,7 +271,7 @@
     ;
 
 sort_specification:
-    column_name ( ASC | DESC )
+    column_reference ( ASC | DESC )
     ;
 
 correlation_name:

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleData.java
Wed Sep 16 13:54:59 2009
@@ -33,8 +33,12 @@
     private static final long serialVersionUID = 1L;
 
     public SimpleData(String typeId, BaseType baseType) {
-        put(Property.TYPE_ID, typeId);
-        put(Property.BASE_TYPE_ID, baseType.getId());
+        if (typeId != null) {
+            put(Property.TYPE_ID, typeId);
+        }
+        if (baseType != null) {
+            put(Property.BASE_TYPE_ID, baseType.getId());
+        }
     }
 
 }

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
Wed Sep 16 13:54:59 2009
@@ -56,7 +56,8 @@
     }
 
     public BaseType getBaseType() {
-        return BaseType.get((String) data.get(Property.BASE_TYPE_ID));
+        String baseTypeId = (String) data.get(Property.BASE_TYPE_ID);
+        return baseTypeId == null ? null : BaseType.get(baseTypeId);
     }
 
     public ChangeInfo getChangeInfo() {

Modified: incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
URL: http://svn.apache.org/viewvc/incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite?rev=815786&r1=815785&r2=815786&view=diff
==============================================================================
--- incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
(original)
+++ incubator/chemistry/branches/0.62/chemistry/chemistry-commons/src/test/gunit/org/apache/chemistry/cmissql/CmisSql.testsuite
Wed Sep 16 13:54:59 2009
@@ -64,10 +64,10 @@
 "'abc'" OK
 
 order_by_clause:
-"ORDER BY foo" -> (ORDER_BY foo ASC)
-"ORDER BY foo ASC" -> (ORDER_BY foo ASC)
-"ORDER BY foo DESC" -> (ORDER_BY foo DESC)
-"ORDER BY foo, bar DESC" -> (ORDER_BY foo ASC bar DESC)
+"ORDER BY foo" -> (ORDER_BY (COL foo) ASC)
+"ORDER BY foo ASC" -> (ORDER_BY (COL foo) ASC)
+"ORDER BY foo DESC" -> (ORDER_BY (COL foo) DESC)
+"ORDER BY t.foo, bar DESC" -> (ORDER_BY (COL t foo) ASC (COL bar) DESC)
 
 column_reference:
 "foo" -> (COL foo)
@@ -123,7 +123,7 @@
 query:
 "SELECT * FROM Document" -> (SELECT * (FROM (TABLE Document)))
 "SELECT a, b, c FROM Document" -> (SELECT (LIST (COL a) (COL b) (COL c)) (FROM (TABLE
Document)))
-"SELECT a, b FROM Document ORDER BY a, b" -> (SELECT (LIST (COL a) (COL b)) (FROM (TABLE
Document)) (ORDER_BY a ASC b ASC))
+"SELECT a, b FROM Document ORDER BY a, b" -> (SELECT (LIST (COL a) (COL b)) (FROM (TABLE
Document)) (ORDER_BY (COL a) ASC (COL b) ASC))
 
 
 // Examples from the specs.



Mime
View raw message