mirror of https://github.com/apache/openjpa.git
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:
parent
04e07ebd0b
commit
942599e797
|
@ -50,6 +50,15 @@ public class MySQLDictionary
|
||||||
*/
|
*/
|
||||||
public boolean driverDeserializesBlobs = true;
|
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() {
|
public MySQLDictionary() {
|
||||||
platform = "MySQL";
|
platform = "MySQL";
|
||||||
validationSQL = "SELECT NOW()";
|
validationSQL = "SELECT NOW()";
|
||||||
|
@ -131,6 +140,22 @@ public class MySQLDictionary
|
||||||
return super.getForeignKeyConstraintSQL(fk);
|
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) {
|
protected void appendSelectRange(SQLBuffer buf, long start, long end) {
|
||||||
buf.append(" LIMIT ").appendValue(start).append(", ");
|
buf.append(" LIMIT ").appendValue(start).append(", ");
|
||||||
if (end == Long.MAX_VALUE)
|
if (end == Long.MAX_VALUE)
|
||||||
|
|
Loading…
Reference in New Issue