use of com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateJoinTableDesc in project Payara by payara.
the class UpdateQueryPlan method processJoinTables.
private void processJoinTables() {
Collection fields = updateDesc.getUpdatedJoinTableFields();
if (fields == null)
return;
Iterator fieldIter = fields.iterator();
ArrayList deleteStatements = new ArrayList();
ArrayList insertStatements = new ArrayList();
while (fieldIter.hasNext()) {
ForeignFieldDesc f = (ForeignFieldDesc) fieldIter.next();
Collection descs = updateDesc.getUpdateJoinTableDescs(f);
Iterator descIter = descs.iterator();
ColumnElement c = (ColumnElement) f.assocLocalColumns.get(0);
QueryTable t = addQueryTable(config.findTableDesc(c.getDeclaringTable()));
while (descIter.hasNext()) {
UpdateJoinTableDesc desc = (UpdateJoinTableDesc) descIter.next();
int action = getAction(desc.getAction());
UpdateStatement s = (UpdateStatement) createStatement(t);
s.setAction(action);
if (action == ACT_INSERT) {
insertStatements.add(s);
} else if (action == ACT_DELETE) {
// RESOLVE: There are redundant deletes from join tables that causes
// update to fail with no rows affected. To work around this problem
// for now, we set the minAffectedRows to 0.
// We need to figure out why there are redundant deletes.
s.minAffectedRows = 0;
deleteStatements.add(s);
}
s.addLocalConstraints(action, f, desc.getParentStateManager());
s.addForeignConstraints(action, f, desc.getForeignStateManager());
}
}
// All join table delete statements have to go first and all
// join table insert statements have to go last.
ArrayList oldStatements = statements;
statements = deleteStatements;
statements.addAll(oldStatements);
statements.addAll(insertStatements);
}
Aggregations