openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r655600 - in /openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql: DBDictionary.java MySQLDictionary.java
Date Mon, 12 May 2008 18:58:00 GMT
Author: pcl
Date: Mon May 12 11:58:00 2008
New Revision: 655600

URL: http://svn.apache.org/viewvc?rev=655600&view=rev
Log:
OPENJPA-597. Committing on behalf of Sandeep Srivastava.

Modified:
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=655600&r1=655599&r2=655600&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Mon May 12 11:58:00 2008
@@ -232,6 +232,7 @@
     public boolean supportsSelectEndIndex = false;
     public int rangePosition = RANGE_POST_SELECT;
     public boolean requiresAliasForSubselect = false;
+    public boolean requiresTargetForDelete = false;
     public boolean allowsAliasInBulkClause = true;
     public boolean supportsMultipleNontransactionalResultSets = true;
     public String searchStringEscape = "\\";
@@ -1873,8 +1874,16 @@
     protected SQLBuffer toBulkOperation(ClassMapping mapping, Select sel,
         JDBCStore store, Object[] params, Map updateParams) {
         SQLBuffer sql = new SQLBuffer(this);
-        if (updateParams == null)
+        if (updateParams == null) {
+          if (requiresTargetForDelete) {
+            sql.append("DELETE ");
+            SQLBuffer deleteTargets = getDeleteTargets(sel);
+            sql.append(deleteTargets);
+            sql.append(" FROM ");
+          } else {
             sql.append("DELETE FROM ");
+          }
+        }
         else
             sql.append("UPDATE ");
         sel.addJoinClassConditions();
@@ -1970,6 +1979,28 @@
         return sql;
     }
 
+    protected SQLBuffer getDeleteTargets(Select sel) {
+      SQLBuffer deleteTargets = new SQLBuffer(this);
+      Collection aliases = sel.getTableAliases();
+      // Assumes aliases are of the form "TABLENAME t0"
+      for (Iterator itr = aliases.iterator(); itr.hasNext();) {
+        String tableAlias = itr.next().toString();
+        int spaceIndex = tableAlias.indexOf(' ');
+        if (spaceIndex > 0 && spaceIndex < tableAlias.length() - 1) {
+          if (allowsAliasInBulkClause) {
+            deleteTargets.append(tableAlias.substring(spaceIndex + 1));
+          } else {
+            deleteTargets.append(tableAlias.substring(0, spaceIndex));
+          }
+        } else {
+          deleteTargets.append(tableAlias);
+        }
+        if (itr.hasNext())
+          deleteTargets.append(", ");
+      }      
+      return deleteTargets;      
+    }
+
     protected void appendUpdates(Select sel, JDBCStore store, SQLBuffer sql,
         Object[] params, Map updateParams, boolean allowAlias) {
         if (updateParams == null || updateParams.size() == 0)
@@ -1997,7 +2028,11 @@
             Val val = (Val) next.getValue();
 
             Column col = fmd.getColumns()[0];
-            sql.append(col.getName());
+            if (allowAlias) {
+              sql.append(sel.getColumnAlias(col));
+            } else {
+              sql.append(col.getName());  
+            }            
             sql.append(" = ");
 
             ExpState state = val.initialize(sel, ctx, 0);

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=655600&r1=655599&r2=655600&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
Mon May 12 11:58:00 2008
@@ -73,6 +73,7 @@
         constraintNameMode = CONS_NAME_MID;
         supportsMultipleNontransactionalResultSets = false;
         requiresAliasForSubselect = true; // new versions
+        requiresTargetForDelete = true;
         supportsSelectStartIndex = true;
         supportsSelectEndIndex = true;
 



Mime
View raw message