1 21 package oracle.toplink.essentials.internal.parsing; 23 24 import java.util.Set ; 25 26 import oracle.toplink.essentials.expressions.*; 27 import oracle.toplink.essentials.queryframework.ReportQuery; 28 29 33 public class SubqueryNode extends Node { 34 35 private EJBQLParseTree subqueryParseTree; 36 37 39 private Set outerVars; 40 41 44 public SubqueryNode() { 45 super(); 46 } 47 48 49 public ReportQuery getReportQuery(GenerationContext context) { 50 ReportQuery innerQuery = new ReportQuery(); 51 GenerationContext innerContext = 52 subqueryParseTree.populateSubquery(innerQuery, context); 53 Expression joins = innerContext.joinVariables(outerVars); 54 if (joins != null) { 55 Expression where = innerQuery.getSelectionCriteria(); 56 where = appendExpression(where, joins); 57 innerQuery.setSelectionCriteria(where); 58 } 59 return innerQuery; 60 } 61 62 66 public void validate(ParseTreeContext context) { 67 subqueryParseTree.validate(context); 68 outerVars = context.getOuterScopeVariables(); 69 SelectNode selectNode = (SelectNode)subqueryParseTree.getQueryNode(); 70 Node selectExpr = (Node)selectNode.getSelectExpressions().get(0); 72 setType(selectExpr.getType()); 73 } 74 75 79 public Expression generateExpression(GenerationContext context) { 80 Expression base = context.getBaseExpression(); 81 ReportQuery innerQuery = getReportQuery(context); 82 return base.subQuery(innerQuery); 83 } 84 85 89 public boolean isSubqueryNode() { 90 return true; 91 } 92 93 94 public void setParseTree(EJBQLParseTree parseTree) { 95 this.subqueryParseTree = parseTree; 96 } 97 98 99 public EJBQLParseTree getParseTree() { 100 return subqueryParseTree; 101 } 102 103 } 104 105 | Popular Tags |