if (hasCustomDeleteQuery()) {
return;
}
Expression builder = new ExpressionBuilder();
Expression directKeyExp = null;
List<DatabaseField> identityFields = getContainerPolicy().getIdentityFieldsForMapKey();
Iterator<DatabaseField> i = identityFields.iterator();
while (i.hasNext()){
DatabaseField field = i.next();
Expression fieldExpression = builder.getField(field).equal(builder.getParameter(field));
if (directKeyExp == null){
directKeyExp = fieldExpression;
} else {
directKeyExp = directKeyExp.and(fieldExpression);
}
}
Expression expression = null;
SQLDeleteStatement statement = new SQLDeleteStatement();
// Construct an expression to delete from the relation table.
for (int index = 0; index < getReferenceKeyFields().size(); index++) {
DatabaseField referenceKey = getReferenceKeyFields().get(index);
DatabaseField sourceKey = getSourceKeyFields().get(index);
Expression subExp1 = builder.getField(referenceKey);
Expression subExp2 = builder.getParameter(sourceKey);
Expression subExpression = subExp1.equal(subExp2);
expression = subExpression.and(expression);
}
expression = expression.and(directKeyExp);
statement.setWhereClause(expression);
statement.setTable(getReferenceTable());
getDeleteQuery().setSQLStatement(statement);