* INTERNAL
* Generate the TopLink expression for this node
*/
public Expression generateExpression(GenerationContext context) {
SubqueryNode subqueryNode = (SubqueryNode)getLeft();
ReportQuery reportQuery = subqueryNode.getReportQuery(context);
// Replace the SELECT clause of the exists subquery by SELECT 1 to
// avoid problems with databases not supporting mutiple columns in the
// subquery SELECT clause in SQL.
// The original select clause expressions might include relationship
// navigations which should result in FK joins in the generated SQL,
// e.g. ... EXISTS (SELECT o.customer FROM Order o ...). Add the
// select clause expressions as non fetch join attributes to the
// ReportQuery representing the subquery. This make sure the FK joins
// get generated.
List items = reportQuery.getItems();
for (Iterator i = items.iterator(); i.hasNext();) {
ReportItem item = (ReportItem)i.next();
Expression expr = item.getAttributeExpression();
reportQuery.addNonFetchJoinedAttribute(expr);
}
reportQuery.clearItems();
Expression one = new ConstantExpression(new Integer(1), new ExpressionBuilder());
reportQuery.addItem("one", one);
reportQuery.dontUseDistinct();
Expression expr = context.getBaseExpression();
return notIndicated() ? expr.notExists(reportQuery) :
expr.exists(reportQuery);
}