1 21 package oracle.toplink.essentials.internal.parsing; 23 24 import java.util.Hashtable ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 28 import oracle.toplink.essentials.expressions.Expression; 29 import oracle.toplink.essentials.internal.sessions.AbstractSession; 30 31 36 public class SelectGenerationContext extends GenerationContext { 37 private boolean useParallelExpressions = false; 40 41 private boolean shouldCheckSelectNodeBeforeResolving = false; 44 private boolean isNotIndicatedInMemberOf = false; 45 46 private MemberOfNode memberOfNode = null; 50 51 private boolean shouldUseOuterJoins = false; 53 54 private GenerationContext outer = null; 56 57 public SelectGenerationContext() { 58 super(); 59 } 60 61 64 public SelectGenerationContext(GenerationContext outer, ParseTree newParseTree) { 65 this(outer.getParseTreeContext(), outer.getSession(), newParseTree); 66 this.outer = outer; 67 } 68 69 public SelectGenerationContext(ParseTreeContext newContext, AbstractSession newSession, ParseTree newParseTree) { 70 super(newContext, newSession, newParseTree); 71 72 useParallelExpressions = this.computeUseParallelExpressions(); 74 } 75 76 public void setMemberOfNode(MemberOfNode newMemberOfNode) { 78 memberOfNode = newMemberOfNode; 79 } 80 81 public MemberOfNode getMemberOfNode() { 82 return memberOfNode; 83 } 84 85 private boolean computeUseParallelExpressions() { 86 boolean computedUseParallelExpressions; 87 88 computedUseParallelExpressions = ((SelectNode)this.parseTree.getQueryNode()).hasOneToOneSelected(this); 91 computedUseParallelExpressions = computedUseParallelExpressions || ((SelectNode)this.parseTree.getQueryNode()).isVariableInINClauseSelected(this) || this.parseTree.getContext().hasMoreThanOneVariablePerType() || this.parseTree.getContext().hasMoreThanOneAliasInFrom(); 94 return computedUseParallelExpressions; 95 } 96 97 public boolean useParallelExpressions() { 100 return useParallelExpressions; 101 } 102 103 public void checkSelectNodeBeforeResolving(boolean shouldCheck) { 106 shouldCheckSelectNodeBeforeResolving = shouldCheck; 107 } 108 109 public boolean shouldCheckSelectNodeBeforeResolving() { 112 return shouldCheckSelectNodeBeforeResolving; 113 } 114 115 public boolean shouldUseOuterJoins() { 117 return shouldUseOuterJoins; 118 } 119 120 public void useOuterJoins() { 121 shouldUseOuterJoins = true; 122 } 123 124 public void dontUseOuterJoins() { 125 shouldUseOuterJoins = false; 126 } 127 128 public boolean hasMemberOfNode() { 130 return memberOfNode != null; 131 } 132 133 134 public GenerationContext getOuterContext() { 135 return outer; 136 } 137 138 142 public Expression joinVariables(Set variables) { 143 if ((outer == null) || (variables == null) || variables.isEmpty()) { 144 return null; 146 } 147 Expression expr = null; 148 for (Iterator i = variables.iterator(); i.hasNext(); ) { 149 String name = (String )i.next(); 150 VariableNode var = new VariableNode(name); 151 Expression innerExpr = var.generateExpression(this); 152 Expression outerExpr = var.generateExpression(outer); 153 Expression join = innerExpr.equal(outerExpr); 154 expr = var.appendExpression(expr, join); 155 } 156 return expr; 157 } 158 } 159 | Popular Tags |