openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r725485 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel: exps/QueryExpressions.java jpql/JPQLExpressionBuilder.java
Date Wed, 10 Dec 2008 23:34:56 GMT
Author: fancy
Date: Wed Dec 10 15:34:55 2008
New Revision: 725485

URL: http://svn.apache.org/viewvc?rev=725485&view=rev
Log:
OPENJPA-805 JPQL updates - iteration 1
Sync up with JPQL.jjt to pass regression

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java?rev=725485&r1=725484&r2=725485&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
Wed Dec 10 15:34:55 2008
@@ -61,6 +61,7 @@
     public Value[] ordering = EMPTY_VALUES;
     public boolean[] ascending = StoreQuery.EMPTY_BOOLEANS;
     public String[] orderingClauses = StoreQuery.EMPTY_STRINGS;
+    public String[] orderingAliases = StoreQuery.EMPTY_STRINGS;
     public LinkedMap parameterTypes = StoreQuery.EMPTY_PARAMS;
     public int operation = QueryOperations.OP_SELECT;
     public ClassMetaData[] accessPath = StoreQuery.EMPTY_METAS;

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=725485&r1=725484&r2=725485&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Wed Dec 10 15:34:55 2008
@@ -321,11 +321,17 @@
         Expression exp = null;
         for (int i = 0; i < count; i++) {
             JPQLNode parent = parametersNode.getChild(i);
-            JPQLNode node = onlyChild(parent);
+            JPQLNode node = firstChild(parent);
+            JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
+                : null;; 
             Value proj = getValue(node);
+            String alias = aliasNode == null ? nextAlias()
+                 : aliasNode.text;
             exps.projections[i] = proj;
-            exps.projectionClauses[i] = assemble(node);
-            exps.projectionAliases[i] = nextAlias();
+            exps.projectionClauses[i] = aliasNode == null ?
+                assemble(node.id == JJTSCALAREXPRESSION ? firstChild(node)
+                    : node) : alias;
+            exps.projectionAliases[i] = alias;
         }
         return exp;
     }
@@ -377,15 +383,30 @@
             int ordercount = orderby.getChildCount();
             exps.ordering = new Value[ordercount];
             exps.orderingClauses = new String[ordercount];
+            exps.orderingAliases = new String[ordercount];
             exps.ascending = new boolean[ordercount];
             for (int i = 0; i < ordercount; i++) {
                 JPQLNode node = orderby.getChild(i);
                 exps.ordering[i] = getValue(firstChild(node));
                 exps.orderingClauses[i] = assemble(firstChild(node));
+                exps.orderingAliases[i] = firstChild(node).text;
                 // ommission of ASC/DESC token implies ascending
                 exps.ascending[i] = node.getChildCount() <= 1 ||
                     lastChild(node).id == JJTASCENDING ? true : false;
             }
+            // check if order by selec item alias
+            for (int i = 0; i < ordercount; i++) {
+                if (exps.orderingClauses[i] != null && 
+                    !exps.orderingClauses[i].equals(""))
+                    continue;
+                for (int j = 0; j < exps.projections.length; j++) {
+                    if (exps.projectionAliases[j].equalsIgnoreCase(
+                        exps.orderingAliases[i])) {
+                        exps.ordering[i] = exps.projections[j];
+                        break;
+                    }
+                }
+            }
         }
     }
 
@@ -719,6 +740,9 @@
         boolean not = node.not;
 
         switch (node.id) {
+            case JJTSCALAREXPRESSION:
+                return eval(onlyChild(node));
+
             case JJTWHERE: // top-level WHERE clause
                 return getExpression(onlyChild(node));
 



Mime
View raw message