deleteTableContents optimization for MySQL. This is disabled by default, as MySQL may fail if using InnoDB + delete constraints.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@492032 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2007-01-03 03:02:45 +00:00
parent 04e07ebd0b
commit 942599e797
1 changed files with 25 additions and 0 deletions

View File

@ -50,6 +50,15 @@ public class MySQLDictionary
*/
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()";
@ -130,6 +139,22 @@ public class MySQLDictionary
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) {
buf.append(" LIMIT ").appendValue(start).append(", ");