openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r666915 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql: DBDictionary.java MySQLDictionary.java
Date Wed, 11 Jun 2008 23:55:46 GMT
Author: pcl
Date: Wed Jun 11 16:55:46 2008
New Revision: 666915

URL: http://svn.apache.org/viewvc?rev=666915&view=rev
Log:
OPENJPA-597. Merge from ../branches/1.1.x. svn merge -c 655600 ../branches/1.1.x

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=666915&r1=666914&r2=666915&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Wed Jun 11 16:55:46 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 = "\\";
@@ -1896,8 +1897,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();
@@ -1993,6 +2002,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)
@@ -2020,7 +2051,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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=666915&r1=666914&r2=666915&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
Wed Jun 11 16:55:46 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