1 21 package oracle.toplink.essentials.internal.parsing; 23 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 28 import oracle.toplink.essentials.expressions.*; 29 import oracle.toplink.essentials.internal.expressions.ConstantExpression; 30 import oracle.toplink.essentials.internal.queryframework.ReportItem; 31 import oracle.toplink.essentials.queryframework.ReportQuery; 32 33 37 public class ExistsNode extends Node { 38 39 40 private boolean notIndicated = false; 41 42 45 public ExistsNode() { 46 super(); 47 } 48 49 54 public void validate(ParseTreeContext context) { 55 if (left != null) { 56 57 SubqueryNode subqueryNode = (SubqueryNode)getLeft(); 59 subqueryNode.validate(context); 61 62 TypeHelper typeHelper = context.getTypeHelper(); 63 setType(typeHelper.getBooleanType()); 64 } 65 } 66 67 71 public Expression generateExpression(GenerationContext context) { 72 SubqueryNode subqueryNode = (SubqueryNode)getLeft(); 73 ReportQuery reportQuery = subqueryNode.getReportQuery(context); 74 List items = reportQuery.getItems(); 84 for (Iterator i = items.iterator(); i.hasNext();) { 85 ReportItem item = (ReportItem)i.next(); 86 Expression expr = item.getAttributeExpression(); 87 reportQuery.addNonFetchJoinedAttribute(expr); 88 } 89 reportQuery.clearItems(); 90 Expression one = new ConstantExpression(new Integer (1), new ExpressionBuilder()); 91 reportQuery.addItem("one", one); 92 reportQuery.dontUseDistinct(); 93 Expression expr = context.getBaseExpression(); 94 return notIndicated() ? expr.notExists(reportQuery) : 95 expr.exists(reportQuery); 96 } 97 98 103 public void indicateNot() { 104 notIndicated = true; 105 } 106 107 public boolean notIndicated() { 108 return notIndicated; 109 } 110 111 } 112 | Popular Tags |