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 2019/07/25 12:20:19 UTC

[empire-db] branch master updated: EMPIREDB-299: improve Oracle MERGE INTO statements

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 6d256ef  EMPIREDB-299: improve Oracle MERGE INTO statements
6d256ef is described below

commit 6d256ef910ee73a28c56db8afe627f1a0565f1d0
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Thu Jul 25 14:20:14 2019 +0200

    EMPIREDB-299: improve Oracle MERGE INTO statements
---
 .../apache/empire/db/oracle/DBCommandOracle.java   | 27 +++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java b/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
index de5eaa7..1255f42 100644
--- a/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
+++ b/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
@@ -35,6 +35,7 @@ import org.apache.empire.db.DBRowSet;
 import org.apache.empire.db.DBTable;
 import org.apache.empire.db.expr.column.DBAliasExpr;
 import org.apache.empire.db.expr.column.DBValueExpr;
+import org.apache.empire.db.expr.compare.DBCompareColExpr;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
 import org.apache.empire.db.expr.join.DBColumnJoinExpr;
 import org.apache.empire.db.expr.join.DBJoinExpr;
@@ -312,9 +313,12 @@ public class DBCommandOracle extends DBCommand
         DBCommand inner = this.clone();
         inner.clearSelect();
         inner.clearOrderBy();
+        DBRowSet outerTable = updateJoin.getOuterTable();
+        if (outerTable==null)
+            outerTable=table;
         for (DBColumn jcol : joinColumns)
         {   // Select join columns
-            if (jcol.getRowSet()!=table)
+            if (jcol.getRowSet().equals(outerTable)==false)
                 inner.select(jcol);
         }
         // find the source table
@@ -365,6 +369,17 @@ public class DBCommandOracle extends DBCommand
         {   buf.append(" AND ");
             updateJoin.getWhere().addSQL(buf, CTX_DEFAULT);
         }
+        // More constraints
+        for (DBCompareExpr we : this.where) 
+        {
+            DBCompareColExpr cce = (DBCompareColExpr)we;
+            DBColumn ccecol = cce.getColumnExpr().getUpdateColumn();
+            if (table.isKeyColumn(ccecol)&& !isSetColumn(ccecol))  
+            {
+                buf.append(" AND ");
+                cce.addSQL(buf, CTX_DEFAULT);
+            }
+        }
         // Set Expressions
         buf.append(")\r\nWHEN MATCHED THEN UPDATE ");
         buf.append("\r\nSET ");
@@ -372,6 +387,16 @@ public class DBCommandOracle extends DBCommand
         // done
         return buf.toString();
     }
+        
+    protected boolean isSetColumn(DBColumn col)
+    {
+        for (DBSetExpr se : this.set)
+        {
+            if (se.getColumn().equals(col))
+                return true;
+        }
+        return false;
+    }
     
     /**
      * Creates an Oracle specific delete statement.