openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r492032 - /incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
Date Wed, 03 Jan 2007 03:02:46 GMT
Author: pcl
Date: Tue Jan  2 19:02:45 2007
New Revision: 492032

URL: http://svn.apache.org/viewvc?view=rev&rev=492032
Log:
deleteTableContents optimization for MySQL. This is disabled by default, as MySQL may fail
if using InnoDB + delete constraints.

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

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?view=diff&rev=492032&r1=492031&r2=492032
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
Tue Jan  2 19:02:45 2007
@@ -50,6 +50,15 @@
      */
     public boolean driverDeserializesBlobs = true;
 
+    /**
+     * Whether to inline multi-table bulk-delete operations into MySQL's 
+     * combined <code>DELETE FROM foo, bar, baz</code> syntax. 
+     * Defaults to false, since this may fail in the presence of InnoDB tables
+     * with foreign keys.
+     * @see http://dev.mysql.com/doc/refman/5.0/en/delete.html
+     */
+    public boolean optimizeMultiTableDeletes = false;
+
     public MySQLDictionary() {
         platform = "MySQL";
         validationSQL = "SELECT NOW()";
@@ -129,6 +138,22 @@
         if (fk.getColumns().length > 1)
             return null;
         return super.getForeignKeyConstraintSQL(fk);
+    }
+    
+    public String[] getDeleteTableContentsSQL(Table[] tables) {
+        // mysql >= 4 supports more-optimal delete syntax
+        if (!optimizeMultiTableDeletes)
+            return super.getDeleteTableContentsSQL(tables);
+        else {
+            StringBuffer buf = new StringBuffer(tables.length * 8);
+            buf.append("DELETE FROM ");
+            for (int i = 0; i < tables.length; i++) {
+                buf.append(tables[i].getFullName());
+                if (i < tables.length - 1)
+                    buf.append(", ");
+            }
+            return new String[] { buf.toString() };
+        }
     }
 
     protected void appendSelectRange(SQLBuffer buf, long start, long end) {



Mime
View raw message