1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.error.StandardException; 25 26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 27 28 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 29 30 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 31 32 import org.apache.derby.iapi.services.compiler.MethodBuilder; 33 34 import org.apache.derby.iapi.services.sanity.SanityManager; 35 36 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 37 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 38 import org.apache.derby.iapi.sql.compile.NodeFactory; 39 import org.apache.derby.iapi.services.context.ContextManager; 40 41 47 48 public class BetweenOperatorNode extends BinaryListOperatorNode 49 { 50 56 57 public void init(Object leftOperand, Object betweenValues) 58 { 59 if (SanityManager.DEBUG) 60 { 61 ValueNodeList betweenVals = (ValueNodeList) betweenValues; 62 63 SanityManager.ASSERT(betweenVals.size() == 2, 64 "betweenValues.size() (" + 65 betweenVals.size() + 66 ") is expected to be 2"); 67 } 68 69 super.init(leftOperand, betweenValues, "BETWEEN", null); 70 } 71 72 88 ValueNode eliminateNots(boolean underNotNode) 89 throws StandardException 90 { 91 BinaryComparisonOperatorNode leftBCO; 92 BinaryComparisonOperatorNode rightBCO; 93 OrNode newOr; 94 95 if (SanityManager.DEBUG) 96 SanityManager.ASSERT(rightOperandList.size() == 2, 97 "rightOperandList.size() (" + 98 rightOperandList.size() + 99 ") is expected to be 2"); 100 101 if (! underNotNode) 102 { 103 return this; 104 } 105 106 109 110 117 118 NodeFactory nodeFactory = getNodeFactory(); 119 ContextManager cm = getContextManager(); 120 121 122 leftBCO = (BinaryComparisonOperatorNode) 123 nodeFactory.getNode( 124 C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE, 125 leftOperand, 126 rightOperandList.elementAt(0), 127 cm); 128 129 leftBCO.bindComparisonOperator(); 130 131 132 rightBCO = (BinaryComparisonOperatorNode) 133 nodeFactory.getNode( 134 C_NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE, 135 leftOperand, 136 rightOperandList.elementAt(1), 137 cm); 138 139 rightBCO.bindComparisonOperator(); 140 141 142 newOr = (OrNode) nodeFactory.getNode( 143 C_NodeTypes.OR_NODE, 144 leftBCO, 145 rightBCO, 146 cm); 147 newOr.postBindFixup(); 148 149 150 leftBCO.setBetweenSelectivity(); 151 rightBCO.setBetweenSelectivity(); 152 153 return newOr; 154 } 155 156 171 public ValueNode preprocess(int numTables, 172 FromList outerFromList, 173 SubqueryList outerSubqueryList, 174 PredicateList outerPredicateList) 175 throws StandardException 176 { 177 ValueNode leftClone1; 178 ValueNode rightOperand; 179 180 181 super.preprocess(numTables, 182 outerFromList, outerSubqueryList, 183 outerPredicateList); 184 185 189 if (!(leftOperand instanceof ColumnReference)) 190 { 191 return this; 192 } 193 194 198 leftClone1 = leftOperand.getClone(); 199 200 207 208 NodeFactory nodeFactory = getNodeFactory(); 209 ContextManager cm = getContextManager(); 210 211 QueryTreeNode trueNode = nodeFactory.getNode( 212 C_NodeTypes.BOOLEAN_CONSTANT_NODE, 213 Boolean.TRUE, 214 cm); 215 216 217 BinaryComparisonOperatorNode lessEqual = 218 (BinaryComparisonOperatorNode) nodeFactory.getNode( 219 C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE, 220 leftClone1, 221 rightOperandList.elementAt(1), 222 cm); 223 224 225 lessEqual.bindComparisonOperator(); 226 227 228 AndNode newAnd = (AndNode) nodeFactory.getNode( 229 C_NodeTypes.AND_NODE, 230 lessEqual, 231 trueNode, 232 cm); 233 newAnd.postBindFixup(); 234 235 236 BinaryComparisonOperatorNode greaterEqual = 237 (BinaryComparisonOperatorNode) nodeFactory.getNode( 238 C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE, 239 leftOperand, 240 rightOperandList.elementAt(0), 241 cm); 242 243 244 greaterEqual.bindComparisonOperator(); 245 246 247 newAnd = (AndNode) nodeFactory.getNode( 248 C_NodeTypes.AND_NODE, 249 greaterEqual, 250 newAnd, 251 cm); 252 newAnd.postBindFixup(); 253 254 255 lessEqual.setBetweenSelectivity(); 256 greaterEqual.setBetweenSelectivity(); 257 258 return newAnd; 259 } 260 261 270 271 public void generateExpression(ExpressionClassBuilder acb, 272 MethodBuilder mb) 273 throws StandardException 274 { 275 AndNode newAnd; 276 BinaryComparisonOperatorNode leftBCO; 277 BinaryComparisonOperatorNode rightBCO; 278 279 if (SanityManager.DEBUG) 280 SanityManager.ASSERT(rightOperandList.size() == 2, 281 "rightOperandList.size() (" + 282 rightOperandList.size() + 283 ") is expected to be 2"); 284 285 290 291 NodeFactory nodeFactory = getNodeFactory(); 292 ContextManager cm = getContextManager(); 293 294 295 leftBCO = (BinaryComparisonOperatorNode) 296 nodeFactory.getNode( 297 C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE, 298 leftOperand, 299 rightOperandList.elementAt(0), 300 cm); 301 302 leftBCO.bindComparisonOperator(); 303 304 305 rightBCO = (BinaryComparisonOperatorNode) 306 nodeFactory.getNode( 307 C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE, 308 leftOperand, 309 rightOperandList.elementAt(1), 310 cm); 311 312 rightBCO.bindComparisonOperator(); 313 314 315 newAnd = (AndNode) nodeFactory.getNode( 316 C_NodeTypes.AND_NODE, 317 leftBCO, 318 rightBCO, 319 cm); 320 newAnd.postBindFixup(); 321 newAnd.generateExpression(acb, mb); 322 } 323 } 324 | Popular Tags |