OPENJPA-597. Merge from ../branches/1.1.x. svn merge -c 655600 ../branches/1.1.x

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@666915 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2008-06-11 23:55:46 +00:00
parent 1a45d110a2
commit 629977fb1c
2 changed files with 38 additions and 2 deletions

View File

@ -232,6 +232,7 @@ public class DBDictionary
public boolean supportsSelectEndIndex = false; public boolean supportsSelectEndIndex = false;
public int rangePosition = RANGE_POST_SELECT; public int rangePosition = RANGE_POST_SELECT;
public boolean requiresAliasForSubselect = false; public boolean requiresAliasForSubselect = false;
public boolean requiresTargetForDelete = false;
public boolean allowsAliasInBulkClause = true; public boolean allowsAliasInBulkClause = true;
public boolean supportsMultipleNontransactionalResultSets = true; public boolean supportsMultipleNontransactionalResultSets = true;
public String searchStringEscape = "\\"; public String searchStringEscape = "\\";
@ -1896,8 +1897,16 @@ public class DBDictionary
protected SQLBuffer toBulkOperation(ClassMapping mapping, Select sel, protected SQLBuffer toBulkOperation(ClassMapping mapping, Select sel,
JDBCStore store, Object[] params, Map updateParams) { JDBCStore store, Object[] params, Map updateParams) {
SQLBuffer sql = new SQLBuffer(this); 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 "); sql.append("DELETE FROM ");
}
}
else else
sql.append("UPDATE "); sql.append("UPDATE ");
sel.addJoinClassConditions(); sel.addJoinClassConditions();
@ -1993,6 +2002,28 @@ public class DBDictionary
return sql; 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, protected void appendUpdates(Select sel, JDBCStore store, SQLBuffer sql,
Object[] params, Map updateParams, boolean allowAlias) { Object[] params, Map updateParams, boolean allowAlias) {
if (updateParams == null || updateParams.size() == 0) if (updateParams == null || updateParams.size() == 0)
@ -2020,7 +2051,11 @@ public class DBDictionary
Val val = (Val) next.getValue(); Val val = (Val) next.getValue();
Column col = fmd.getColumns()[0]; Column col = fmd.getColumns()[0];
sql.append(col.getName()); if (allowAlias) {
sql.append(sel.getColumnAlias(col));
} else {
sql.append(col.getName());
}
sql.append(" = "); sql.append(" = ");
ExpState state = val.initialize(sel, ctx, 0); ExpState state = val.initialize(sel, ctx, 0);

View File

@ -73,6 +73,7 @@ public class MySQLDictionary
constraintNameMode = CONS_NAME_MID; constraintNameMode = CONS_NAME_MID;
supportsMultipleNontransactionalResultSets = false; supportsMultipleNontransactionalResultSets = false;
requiresAliasForSubselect = true; // new versions requiresAliasForSubselect = true; // new versions
requiresTargetForDelete = true;
supportsSelectStartIndex = true; supportsSelectStartIndex = true;
supportsSelectEndIndex = true; supportsSelectEndIndex = true;