empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1359727 - /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
Date Tue, 10 Jul 2012 15:24:30 GMT
Author: doebele
Date: Tue Jul 10 15:24:29 2012
New Revision: 1359727

URL: http://svn.apache.org/viewvc?rev=1359727&view=rev
Log:
EMPIREDB-141
Allow Oracle optimizer hint for updates

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java?rev=1359727&r1=1359726&r2=1359727&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBCommandOracle.java
Tue Jul 10 15:24:29 2012
@@ -22,6 +22,7 @@ package org.apache.empire.db.oracle;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.db.DBColumn;
 import org.apache.empire.db.DBColumnExpr;
 import org.apache.empire.db.DBCommand;
@@ -145,9 +146,8 @@ public class DBCommandOracle extends DBC
             throw new ObjectNotValidException(this);
         // Prepares statement
         buf.append("SELECT ");
-        if (optimizerHint != null)
-        {
-            // Append an optimizer hint to the select statement e.g. SELECT /*+ RULE */
+        if (StringUtils.isNotEmpty(optimizerHint))
+        {   // Append an optimizer hint to the select statement e.g. SELECT /*+ RULE */
             buf.append("/*+ ").append(optimizerHint).append(" */ ");
         }
         if (selectDistinct)
@@ -193,7 +193,42 @@ public class DBCommandOracle extends DBC
     {
         // No Joins: Use Default
         if (joins==null || set==null)
-            return super.getUpdate();
+            return getSimpleUpdate();
+        else
+            return getUpdateWithJoins();
+    }
+
+    protected String getSimpleUpdate()
+    {
+        resetParamUsage();
+        if (set == null)
+            return null;
+        StringBuilder buf = new StringBuilder("UPDATE ");
+        DBRowSet table =  set.get(0).getTable();
+        long context = CTX_FULLNAME;
+        // Optimizer Hint
+        if (StringUtils.isNotEmpty(optimizerHint))
+        {   // Append an optimizer hint to the select statement e.g. SELECT /*+ RULE */
+            buf.append("/*+ ").append(optimizerHint).append(" */ ");
+            // Append alias (if necessary)
+            if (optimizerHint.contains(table.getAlias()))
+                context |= CTX_ALIAS;
+        }
+        // table
+        table.addSQL(buf, context);
+        // Simple Statement
+        context = CTX_NAME | CTX_VALUE;
+        // Set Expressions
+        buf.append("\r\nSET ");
+        addListExpr(buf, set, context, ", ");
+        // Add Where
+        addWhere(buf, context);
+        // done
+        return buf.toString();
+    }
+    
+    protected String getUpdateWithJoins()
+    {
         // Generate Merge expression
         resetParamUsage();
         StringBuilder buf = new StringBuilder("MERGE INTO ");



Mime
View raw message