You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2021/04/16 15:37:08 UTC

[empire-db] branch master updated: EMPIREDB-342 improve allowed join expressions

This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 3d919df  EMPIREDB-342 improve allowed join expressions
3d919df is described below

commit 3d919df48ba091a7676b85adcef9705f204213ba
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Fri Apr 16 17:37:03 2021 +0200

    EMPIREDB-342
    improve allowed join expressions
---
 .../main/java/org/apache/empire/db/DBCommand.java  | 22 ++++++++++++++++++++--
 .../empire/db/expr/compare/DBParenthesisExpr.java  |  5 +++++
 .../empire/db/expr/join/DBCompareJoinExpr.java     | 10 +++++++---
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
index 67b1f6d..b2aea65 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
@@ -440,6 +440,15 @@ public abstract class DBCommand extends DBCommandExpr
     }
 
     /**
+     * Returns all set expressions as unmodifiable list
+     * @return the list of DBSetExpr used for set
+     */
+    public List<DBSetExpr> getSetExpressions()
+    {
+        return (this.set!=null ? Collections.unmodifiableList(this.set) : null);
+    }
+
+    /**
      * Adds an command parameter which will be used in a prepared statement.
      * The command parameter returned may be used to alter the value.
      * 
@@ -898,9 +907,9 @@ public abstract class DBCommand extends DBCommandExpr
     }
     
     /**
-     * Returns a array of all select DBColumnExpr for this command 
+     * Returns an array of all select expressions
      * 
-     * @return a array of all DBColumnExpr objects or <code>null</code> if there are no selects
+     * @return an array of all DBColumnExpr objects or <code>null</code> if there is nothing to select
      */
     @Override
     public DBColumnExpr[] getSelectExprList()
@@ -917,6 +926,15 @@ public abstract class DBCommand extends DBCommandExpr
     }
 
     /**
+     * Returns all select expressions as unmodifiable list
+     * @return the list of DBColumnExpr used for select
+     */
+    public List<DBColumnExpr> getSelectExpressions()
+    {
+        return (this.select!=null ? Collections.unmodifiableList(this.select) : null);
+    }
+
+    /**
      * Clears the select distinct option.
      */
     public void clearSelectDistinct()
diff --git a/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBParenthesisExpr.java b/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBParenthesisExpr.java
index 719b077..f61ec7e 100644
--- a/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBParenthesisExpr.java
+++ b/empire-db/src/main/java/org/apache/empire/db/expr/compare/DBParenthesisExpr.java
@@ -36,6 +36,11 @@ public class DBParenthesisExpr extends DBCompareExpr
     {
         this.wrap = wrap;
     }
+    
+    public DBCompareExpr getWrapped()
+    {
+        return wrap;
+    }
 
     @Override
     public DBDatabase getDatabase()
diff --git a/empire-db/src/main/java/org/apache/empire/db/expr/join/DBCompareJoinExpr.java b/empire-db/src/main/java/org/apache/empire/db/expr/join/DBCompareJoinExpr.java
index bbc02f6..1ded2ee 100644
--- a/empire-db/src/main/java/org/apache/empire/db/expr/join/DBCompareJoinExpr.java
+++ b/empire-db/src/main/java/org/apache/empire/db/expr/join/DBCompareJoinExpr.java
@@ -25,6 +25,7 @@ import org.apache.empire.db.DBRowSet;
 import org.apache.empire.db.expr.compare.DBCompareAndOrExpr;
 import org.apache.empire.db.expr.compare.DBCompareColExpr;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
+import org.apache.empire.db.expr.compare.DBParenthesisExpr;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,9 +46,12 @@ public class DBCompareJoinExpr extends DBColumnJoinExpr
     
     private static DBColumnExpr findFirstColumn(DBCompareExpr expr)
     {
-        // DBCompareORExpr 
-        while (expr instanceof DBCompareAndOrExpr)
-               expr = ((DBCompareAndOrExpr)expr).getLeft();
+        // DBParenthesisExpr
+        if (expr instanceof DBParenthesisExpr)
+            return findFirstColumn(((DBParenthesisExpr)expr).getWrapped());
+        // DBCompareORExpr
+        if (expr instanceof DBCompareAndOrExpr)
+            return findFirstColumn(((DBCompareAndOrExpr)expr).getLeft());
         // Get Colum Expr
         if (expr instanceof DBCompareColExpr)
             return ((DBCompareColExpr)expr).getColumnExpr();