openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r725530 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/ openjpa-kernel/src/main/java/o...
Date Thu, 11 Dec 2008 01:43:53 GMT
Author: fancy
Date: Wed Dec 10 17:43:52 2008
New Revision: 725530

URL: http://svn.apache.org/viewvc?rev=725530&view=rev
Log:
OPENJPA-805 JPQL iteration 1 add support for select ScalarExpression & Order By selectAlias

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StringFunction.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Substring.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Trim.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Val.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Value.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestOrderByQuery.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java
Wed Dec 10 17:43:52 2008
@@ -21,6 +21,7 @@
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
+import org.apache.openjpa.kernel.exps.Value;
 
 /**
  * Abstract value for easy extension.
@@ -32,6 +33,7 @@
 
     protected static final String TRUE = "1 = 1";
     protected static final String FALSE = "1 <> 1";
+    private String _alias = null;
 
     public boolean isVariable() {
         return false;
@@ -85,5 +87,17 @@
     public int getId() {
         return Val.VAL;
     }
+
+    public String getAlias() {
+        return _alias;
+    }
+
+    public void setAlias(String alias) {
+        _alias = alias;
+    }
+
+    public Value getSelectAs() {
+        return _alias != null ? this : null;
+    }
 }
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java
Wed Dec 10 17:43:52 2008
@@ -114,7 +114,8 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false,
+            getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java
Wed Dec 10 17:43:52 2008
@@ -75,7 +75,8 @@
         ctx.store.getDBDictionary().comparison(buf, _op,
             new FilterValueImpl(sel, ctx, bstate.state1, _val1),
             new FilterValueImpl(sel, ctx, bstate.state2, _val2));
-        sel.append(buf, state.joins);
+        if (sel != null)
+            sel.append(buf, state.joins);
     }
 
     public void selectColumns(Select sel, ExpContext ctx, ExpState state, 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java
Wed Dec 10 17:43:52 2008
@@ -97,7 +97,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java
Wed Dec 10 17:43:52 2008
@@ -130,7 +130,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     public Object load(ExpContext ctx, ExpState state, Result res)

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java
Wed Dec 10 17:43:52 2008
@@ -149,7 +149,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
Wed Dec 10 17:43:52 2008
@@ -98,7 +98,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
Wed Dec 10 17:43:52 2008
@@ -113,7 +113,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StringFunction.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StringFunction.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StringFunction.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StringFunction.java
Wed Dec 10 17:43:52 2008
@@ -85,7 +85,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
Wed Dec 10 17:43:52 2008
@@ -132,7 +132,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Substring.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Substring.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Substring.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Substring.java
Wed Dec 10 17:43:52 2008
@@ -95,7 +95,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Trim.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Trim.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Trim.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Trim.java
Wed Dec 10 17:43:52 2008
@@ -122,7 +122,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
Wed Dec 10 17:43:52 2008
@@ -101,7 +101,7 @@
 
     public void orderBy(Select sel, ExpContext ctx, ExpState state, 
         boolean asc) {
-        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
     }
 
     private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
Wed Dec 10 17:43:52 2008
@@ -64,6 +64,10 @@
     public final int INDEXOF_VAL = 10;
     public final int ABS_VAL = 11;
     public final int SQRT_VAL = 12;
+    public final int SIMPLECASE_VAL = 13;
+    public final int GENERALCASE_VAL = 14;
+    public final int WHENCONDITION_VAL = 15;
+    public final int WHENSCALAR_VAL = 16;
 
     /**
      * Initialize the value. This method should recursively initialize any
@@ -160,4 +164,6 @@
         SQLBuffer sql);
 
     public int getId();
+
+    public Value getSelectAs();
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
Wed Dec 10 17:43:52 2008
@@ -44,7 +44,7 @@
             + ")))";
         stringLengthFunction = "LENGTH({0})";
         concatenateFunction = "(CAST({0} AS VARCHAR(" + varcharCastLength
-            + ")))||(CAST({1} AS VARCHAR(1000)))";
+            + ")) || CAST({1} AS VARCHAR(1000)))";
 
         trimLeadingFunction = "LTRIM({0})";
         trimTrailingFunction = "RTRIM({0})";

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Wed Dec 10 17:43:52 2008
@@ -240,6 +240,8 @@
     public boolean supportsXMLColumn = false;
     public boolean reportsSuccessNoInfoOnBatchUpdates = false;
     public boolean supportsSelectFromFinalTable = false;
+    public boolean supportsSimpleCaseExpression = true;
+    public boolean supportsGeneralCaseExpression = true;
     
     /**
      * Some Databases append whitespace after the schema name 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DerbyDictionary.java
Wed Dec 10 17:43:52 2008
@@ -62,6 +62,7 @@
         supportsDefaultDeleteAction = false;
         requiresCastForMathFunctions = true;
         requiresCastForComparisons = true;
+        supportsSimpleCaseExpression = false;
 
         supportsComments = true;
 

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
Wed Dec 10 17:43:52 2008
@@ -29,6 +29,7 @@
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.kernel.exps.Value;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.schema.Column;
@@ -721,14 +722,15 @@
             return sel.orderBy(cols, asc, joins, select, isUnion());
         }
 
-        public boolean orderBy(SQLBuffer sql, boolean asc, boolean select) {
-            return orderBy(sql, asc, null, select);
+        public boolean orderBy(SQLBuffer sql, boolean asc, boolean select,
+            Value selAs) {
+            return orderBy(sql, asc, null, select, selAs);
         }
 
         public boolean orderBy(SQLBuffer sql, boolean asc, Joins joins,
-            boolean select) {
+            boolean select, Value selAs) {
             recordOrder(sql.getSQL(false), asc);
-            return sel.orderBy(sql, asc, joins, select, isUnion());
+            return sel.orderBy(sql, asc, joins, select, isUnion(), selAs);
         }
 
         public boolean orderBy(String sql, boolean asc, boolean select) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java Wed Dec
10 17:43:52 2008
@@ -29,6 +29,7 @@
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.kernel.exps.Value;
 
 /**
  * Abstraction of a SQL SELECT statement.
@@ -499,14 +500,14 @@
      * Add an ORDER BY clause.
      * Optionally selects ordering data if not already selected.
      */
-    public boolean orderBy(SQLBuffer sql, boolean asc, boolean sel);
+    public boolean orderBy(SQLBuffer sql, boolean asc, boolean sel, Value selAs);
 
     /**
      * Add an ORDER BY clause.
      * Optionally selects ordering data if not already selected.
      */
     public boolean orderBy(SQLBuffer sql, boolean asc, Joins joins,
-        boolean sel);
+        boolean sel, Value selAs);
 
     /**
      * Add an ORDER BY clause.

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Wed
Dec 10 17:43:52 2008
@@ -55,6 +55,7 @@
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Table;
 import org.apache.openjpa.kernel.StoreContext;
+import org.apache.openjpa.kernel.exps.Value;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.ApplicationIds;
@@ -1235,28 +1236,28 @@
         return seld;
     }
 
-    public boolean orderBy(SQLBuffer sql, boolean asc, boolean sel) {
-        return orderBy(sql, asc, (Joins) null, sel);
+    public boolean orderBy(SQLBuffer sql, boolean asc, boolean sel, Value selAs) {
+        return orderBy(sql, asc, (Joins) null, sel, selAs);
     }
 
     public boolean orderBy(SQLBuffer sql, boolean asc, Joins joins,
-        boolean sel) {
-        return orderBy(sql, asc, joins, sel, false);
+        boolean sel, Value selAs) {
+        return orderBy(sql, asc, joins, sel, false, selAs);
     }
 
     /**
      * Allow unions to set aliases on order columns.
      */
     boolean orderBy(SQLBuffer sql, boolean asc, Joins joins, boolean sel,
-        boolean aliasOrder) {
-        return orderBy((Object) sql, asc, joins, sel, aliasOrder);
+        boolean aliasOrder, Value selAs) {
+        return orderBy((Object) sql, asc, joins, sel, aliasOrder, selAs);
     }
 
     /**
      * Order on a SQL buffer or string.
      */
     private boolean orderBy(Object sql, boolean asc, Joins joins, boolean sel,
-        boolean aliasOrder) {
+        boolean aliasOrder, Value selAs) {
         Object order = sql;
         if (aliasOrder) {
             order = toOrderAlias(_orders++);
@@ -1265,11 +1266,11 @@
         if ((_flags & RECORD_ORDERED) != 0) {
             if (_ordered == null)
                 _ordered = new ArrayList(5);
-            _ordered.add(sql);
+            _ordered.add(selAs == null ? sql : selAs);
         }
 
         getJoins(joins, true);
-        appendOrdering(order, asc);
+        appendOrdering(selAs != null ? selAs.getAlias() : order, asc);
         if (sel) {
             int idx = _selects.indexOfAlias(sql);
             if (idx == -1) {
@@ -1293,7 +1294,7 @@
      */
     boolean orderBy(String sql, boolean asc, Joins joins, boolean sel,
         boolean aliasOrder) {
-        return orderBy((Object) sql, asc, joins, sel, aliasOrder);
+        return orderBy((Object) sql, asc, joins, sel, aliasOrder, null);
     }
 
     public void clearOrdering() {
@@ -3027,6 +3028,8 @@
                         as = ((String) alias).replace('.', '_');
                     else if (_selectAs != null)
                         as = (String) _selectAs.get(id);
+                    else if (id instanceof Value)
+                        as = ((Value) id).getAlias();
 
                     if (as != null) {
                         if (ident && _idents != null)

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Val.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Val.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Val.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Val.java Wed
Dec 10 17:43:52 2008
@@ -36,6 +36,7 @@
     implements Value {
 
     private ClassMetaData _meta = null;
+    private String _alias = null;
 
     /**
      * Return this value as a projection on the given candidate.
@@ -118,4 +119,16 @@
         visitor.enter(this);
         visitor.exit(this);
     }
+
+    public String getAlias() {
+        return _alias;
+    }
+
+    public void setAlias(String alias) {
+        _alias = alias;
+    }
+
+    public Value getSelectAs() {
+        return _alias != null ? this : null;
+    }
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Value.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Value.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Value.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Value.java Wed
Dec 10 17:43:52 2008
@@ -73,4 +73,19 @@
      * Accept a visit from a tree visitor.
      */
     public void acceptVisit(ExpressionVisitor visitor);
+
+    /**
+     * Return select item alias
+     */
+    public String getAlias();
+
+    /**
+     * Set select item alias
+     */
+    public void setAlias(String alias);
+
+    /**
+     * Return 'this' concrete class if alias is set, otherwise null
+     */
+    public Value getSelectAs();
 }

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=725530&r1=725529&r2=725530&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 17:43:52 2008
@@ -327,6 +327,8 @@
             Value proj = getValue(node);
             String alias = aliasNode == null ? nextAlias()
                  : aliasNode.text;
+            if (aliasNode != null)
+                proj.setAlias(alias);
             exps.projections[i] = proj;
             exps.projectionClauses[i] = aliasNode == null ?
                 assemble(node.id == JJTSCALAREXPRESSION ? firstChild(node)

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestOrderByQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestOrderByQuery.java?rev=725530&r1=725529&r2=725530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestOrderByQuery.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestOrderByQuery.java
Wed Dec 10 17:43:52 2008
@@ -64,6 +64,31 @@
 		em.getTransaction().commit();
 	}
     
+    public void testOrderByAliasAscending() {
+        String jpql = "SELECT p.name as name FROM Game p ORDER BY name ASC";
+        EntityManager em = emf.createEntityManager();
+        
+        List<String> names = em.createQuery(jpql).getResultList();
+        assertOrdering(names.toArray(new String[names.size()]), true);
+    }
+    
+    public void testOrderByConcatAliasDescending() {
+        String jpql = "SELECT CONCAT(p.name, '123') as cname " +
+            "FROM Game p ORDER BY cname DESC";
+        EntityManager em = emf.createEntityManager();
+        
+        List<String> names = em.createQuery(jpql).getResultList();
+        assertOrdering(names.toArray(new String[names.size()]), false);
+    }
+    
+    public void testOrderByAliasDescending() {
+        String jpql = "SELECT p.name as name FROM Game p ORDER BY name DESC";
+        EntityManager em = emf.createEntityManager();
+        
+        List<String> names = em.createQuery(jpql).getResultList();
+        assertOrdering(names.toArray(new String[names.size()]), false);
+    }
+    
     public void testOrderByQueryAscending() {
     	String jpql = "SELECT p FROM Game p ORDER BY p.name ASC";
     	EntityManager em = emf.createEntityManager();



Mime
View raw message