chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r1004761 - in /incubator/chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antl...
Date Tue, 05 Oct 2010 18:27:38 GMT
Author: fguillaume
Date: Tue Oct  5 18:27:37 2010
New Revision: 1004761

URL: http://svn.apache.org/viewvc?rev=1004761&view=rev
Log:
Add needed framework for JOIN parsing

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/Properties.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ColumnReference.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/FunctionReference.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/Properties.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/Properties.java?rev=1004761&r1=1004760&r2=1004761&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/Properties.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/Properties.java
Tue Oct  5 18:27:37 2010
@@ -25,7 +25,10 @@ public interface Properties extends Exte
 
     /**
      * Returns a map of properties (property id => property). Should not be used
-     * with queries because some repositories don't set property ids.
+     * with queries because some repositories don't set property ids, and
+     * because when dealing with queries the proper key is usually the query
+     * name (when using JOINs, several properties with the same id may be
+     * returned).
      */
     Map<String, PropertyData<?>> getProperties();
 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g?rev=1004761&r1=1004760&r2=1004761&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g
Tue Oct  5 18:27:37 2010
@@ -192,23 +192,30 @@ table_reference:
 
 table_join:
     ^(JOIN join_kind one_table join_specification?)
+    {
+        boolean hasSpec = $join_specification.tree != null;
+        queryObj.addJoin($join_kind.kind, $one_table.alias, hasSpec);
+    }
     ;
 
-one_table:
+one_table returns [String alias]:
     ^(TABLE table_name correlation_name?)
       {
-          queryObj.addType($correlation_name.text, $table_name.text);
+          $alias = queryObj.addType($correlation_name.text, $table_name.text);
       }
     ;
 
-join_kind:
-    INNER | LEFT | OUTER;
+join_kind returns [String kind]:
+      INNER { $kind = "INNER"; }
+    | LEFT  { $kind = "LEFT"; }
+    | RIGHT { $kind = "RIGHT"; }
+    ;
 
 join_specification:
     ^(ON cr1=column_reference EQ cr2=column_reference)
     {
-          queryObj.addJoinReference($cr1.start, $cr1.result);
-          queryObj.addJoinReference($cr2.start, $cr2.result);
+        queryObj.addJoinReference($cr1.start, $cr1.result);
+        queryObj.addJoinReference($cr2.start, $cr2.result);
     }
     ;
 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ColumnReference.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ColumnReference.java?rev=1004761&r1=1004760&r2=1004761&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ColumnReference.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ColumnReference.java
Tue Oct  5 18:27:37 2010
@@ -72,6 +72,9 @@ public class ColumnReference extends Cmi
 
     @Override
     public String toString() {
-        return "Column Reference for column " + propQueryName + " in type " + typeQueryName;
+        return "ColumnReference("
+                + (typeQueryName == null ? "" : typeQueryName + ".")
+                + propQueryName + (aliasName == null ? "" : " AS " + aliasName)
+                + ")";
     }
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/FunctionReference.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/FunctionReference.java?rev=1004761&r1=1004760&r2=1004761&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/FunctionReference.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/FunctionReference.java
Tue Oct  5 18:27:37 2010
@@ -21,7 +21,7 @@ package org.apache.chemistry.opencmis.se
 public class FunctionReference extends CmisSelector {
 
     public enum CmisQlFunction { SCORE, };
-    
+
     private CmisQlFunction function;
 
     public FunctionReference(CmisQlFunction func) {
@@ -32,8 +32,9 @@ public class FunctionReference extends C
         return function;
     }
 
+    @Override
     public String toString() {
-        return "FunctionReference for " + function.toString();
+        return "FunctionReference(" + function.toString() + ")";
     }
 
     @Override

Modified: incubator/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/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java?rev=1004761&r1=1004760&r2=1004761&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
Tue Oct  5 18:27:37 2010
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
@@ -56,11 +57,14 @@ public class QueryObject {
     protected QueryConditionProcessor queryProcessor;
 
     // from part
-    /**
-     * map from alias name to type query name
-     */
+    /** map from alias name to type query name */
     protected Map<String, String> froms = new LinkedHashMap<String, String>();
 
+    /** main from alias name */
+    protected String from = null;
+
+    protected List<JoinSpec> joinSpecs = new LinkedList<JoinSpec>();
+
     // where part
     protected Map<Integer, CmisSelector> columnReferences = new HashMap<Integer,
CmisSelector>();
     protected Tree whereTree;
@@ -68,6 +72,35 @@ public class QueryObject {
     // order by part
     protected List<SortSpec> sortSpecs = new ArrayList<SortSpec>();
 
+    public static class JoinSpec {
+
+        /** INNER / LEFT / RIGHT */
+        public String kind;
+
+        /** Alias or full table type */
+        public String alias;
+
+        public ColumnReference onLeft;
+
+        public ColumnReference onRight;
+
+        public JoinSpec(String kind, String alias) {
+            this.kind = kind;
+            this.alias = alias;
+        }
+
+        public void setSelectors(ColumnReference onLeft, ColumnReference onRight) {
+            this.onLeft = onLeft;
+            this.onRight = onRight;
+        }
+
+        @Override
+        public String toString() {
+            return "JoinReference(" + kind + "," + alias + "," + onLeft + ","
+                    + onRight + ")";
+        }
+    }
+
     public class SortSpec {
         public boolean ascending;
         public Integer colRefKey; // key in columnReferencesMap point to column
@@ -134,17 +167,24 @@ public class QueryObject {
     // ///////////////////////////////////////////////////////
     // FROM part
 
-    public void addType(String aliasName, String typeQueryName) {
+    public String addType(String aliasName, String typeQueryName) {
         LOG.debug("add alias: " + aliasName + " for: " + typeQueryName);
         if (froms.containsKey(aliasName)) {
             throw new CmisInvalidArgumentException("You cannot use name " + aliasName
                     + " more than once as alias in a from part.");
-        } else {
-            if (null != aliasName)
-                froms.put(aliasName, typeQueryName);
-            else
-                froms.put(typeQueryName, typeQueryName);
         }
+        if (aliasName == null) {
+            aliasName = typeQueryName;
+        }
+        froms.put(aliasName, typeQueryName);
+        if (from == null) {
+            from = aliasName;
+        }
+        return aliasName;
+    }
+
+    public String getMainTypeAlias() {
+        return from;
     }
 
     public Map<String, String> getTypes() {
@@ -233,6 +273,22 @@ public class QueryObject {
         return Collections.unmodifiableList(joinReferences);
     }
 
+    public void addJoin(String kind, String alias, boolean hasSpec) {
+        JoinSpec join = new JoinSpec(kind, alias);
+        if (hasSpec) {
+            // get columns from last added references
+            int n = joinReferences.size();
+            ColumnReference onLeft = (ColumnReference) joinReferences.get(n - 2);
+            ColumnReference onRight = (ColumnReference) joinReferences.get(n - 1);
+            join.setSelectors(onLeft, onRight);
+        }
+        joinSpecs.add(join);
+    }
+
+    public List<JoinSpec> getJoins() {
+        return joinSpecs;
+    }
+
     // ///////////////////////////////////////////////////////
     // WHERE part
 



Mime
View raw message