empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject empire-db git commit: EMPIREDB-257 refrain from adding the same expression twice in the orderBy phrase
Date Fri, 30 Jun 2017 15:18:03 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master 6f3cd4751 -> 6e30d8773


EMPIREDB-257
refrain from adding the same expression twice in the orderBy phrase


Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/6e30d877
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/6e30d877
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/6e30d877

Branch: refs/heads/master
Commit: 6e30d877372d4f7b37865b3ff6ada8ac90270b20
Parents: 6f3cd47
Author: Rainer Döbele <doebele@apache.org>
Authored: Fri Jun 30 17:17:59 2017 +0200
Committer: Rainer Döbele <doebele@apache.org>
Committed: Fri Jun 30 17:17:59 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/empire/db/DBCommandExpr.java   | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/6e30d877/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java b/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
index 205fc94..ee3da2a 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
@@ -436,8 +436,21 @@ public abstract class DBCommandExpr extends DBExpr
             orderBy = new ArrayList<DBOrderByExpr>();
         // Add order by expression
         for (DBOrderByExpr expr : exprs)
-        {
-            orderBy.add(expr);
+        {   // find existing
+            for (DBOrderByExpr ob : orderBy)
+            {   // Compare expression
+                if (ob.getColumnExpr().equals(expr.getColumnExpr()))
+                {   // already there, replace
+                    ob.setDescending(expr.isDescending());
+                    expr = null;
+                    break;
+                }
+            }
+            // add, if not replaced
+            if (expr!=null)
+            {   // add expression
+                orderBy.add(expr);
+            }
         }
     }
 


Mime
View raw message