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.dictionary.DataDictionary; 27 28 import org.apache.derby.iapi.reference.SQLState; 29 30 import org.apache.derby.iapi.types.DataTypeDescriptor; 31 import org.apache.derby.iapi.types.TypeId; 32 import org.apache.derby.iapi.sql.compile.Visitor; 33 import org.apache.derby.iapi.sql.compile.Visitable; 34 35 import org.apache.derby.iapi.services.sanity.SanityManager; 36 37 import org.apache.derby.iapi.store.access.Qualifier; 38 39 import org.apache.derby.iapi.util.JBitSet; 40 41 import java.util.Vector ; 42 43 50 51 public abstract class BinaryListOperatorNode extends ValueNode 52 { 53 String methodName; 54 55 String operator; 56 57 String leftInterfaceType; 58 String rightInterfaceType; 59 60 ValueNode receiver; ValueNode leftOperand; 62 ValueNodeList rightOperandList; 63 64 71 72 public void init(Object leftOperand, Object rightOperandList, 73 Object operator, Object methodName) 74 { 75 this.leftOperand = (ValueNode) leftOperand; 76 this.rightOperandList = (ValueNodeList) rightOperandList; 77 this.operator = (String ) operator; 78 this.methodName = (String ) methodName; 79 } 80 81 87 88 public String toString() 89 { 90 if (SanityManager.DEBUG) 91 { 92 return "operator: " + operator + "\n" + 93 "methodName: " + methodName + "\n" + 94 super.toString(); 95 } 96 else 97 { 98 return ""; 99 } 100 } 101 102 108 109 public void printSubNodes(int depth) 110 { 111 if (SanityManager.DEBUG) 112 { 113 super.printSubNodes(depth); 114 115 if (leftOperand != null) 116 { 117 printLabel(depth, "leftOperand: "); 118 leftOperand.treePrint(depth + 1); 119 } 120 121 if (rightOperandList != null) 122 { 123 printLabel(depth, "rightOperandList: "); 124 rightOperandList.treePrint(depth + 1); 125 } 126 } 127 } 128 129 134 public void setClause(int clause) 135 { 136 super.setClause(clause); 137 leftOperand.setClause(clause); 138 rightOperandList.setClause(clause); 139 } 140 141 154 155 public ValueNode bindExpression( 156 FromList fromList, SubqueryList subqueryList, 157 Vector aggregateVector) 158 throws StandardException 159 { 160 leftOperand = leftOperand.bindExpression(fromList, subqueryList, aggregateVector); 161 rightOperandList.bindExpression(fromList, subqueryList, aggregateVector); 162 163 164 if (leftOperand.requiresTypeFromContext()) 165 { 166 ValueNode rightOperand = (ValueNode) rightOperandList.elementAt(0); 167 168 171 if (rightOperandList.containsAllParameterNodes()) 172 { 173 throw StandardException.newException(SQLState.LANG_BINARY_OPERANDS_BOTH_PARMS, 174 operator); 175 } 176 177 178 leftOperand.setType(rightOperandList.getTypeServices()); 179 } 180 181 182 if (rightOperandList.containsParameterNode()) 183 { 184 185 rightOperandList.setParameterDescriptor(leftOperand.getTypeServices()); 186 } 187 188 191 if (leftOperand.getTypeId().userType()) 192 { 193 leftOperand = leftOperand.genSQLJavaSQLTree(); 194 } 195 196 199 rightOperandList.genSQLJavaSQLTrees(); 200 201 202 bindComparisonOperator(); 203 204 return this; 205 } 206 207 214 public void bindComparisonOperator() 215 throws StandardException 216 { 217 boolean nullableResult; 218 219 220 rightOperandList.comparable(leftOperand); 221 222 230 nullableResult = leftOperand.getTypeServices().isNullable() || 231 rightOperandList.isNullable(); 232 setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, nullableResult)); 233 } 234 235 250 public ValueNode preprocess(int numTables, 251 FromList outerFromList, 252 SubqueryList outerSubqueryList, 253 PredicateList outerPredicateList) 254 throws StandardException 255 { 256 leftOperand = leftOperand.preprocess(numTables, 257 outerFromList, outerSubqueryList, 258 outerPredicateList); 259 rightOperandList.preprocess(numTables, 260 outerFromList, outerSubqueryList, 261 outerPredicateList); 262 return this; 263 } 264 265 270 public void setLeftOperand(ValueNode newLeftOperand) 271 { 272 leftOperand = newLeftOperand; 273 } 274 275 280 public ValueNode getLeftOperand() 281 { 282 return leftOperand; 283 } 284 285 291 public void setRightOperandList(ValueNodeList newRightOperandList) 292 { 293 rightOperandList = newRightOperandList; 294 } 295 296 301 public ValueNodeList getRightOperandList() 302 { 303 return rightOperandList; 304 } 305 306 331 public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) 332 throws StandardException 333 { 334 boolean pushable; 335 pushable = leftOperand.categorize(referencedTabs, simplePredsOnly); 336 pushable = (rightOperandList.categorize(referencedTabs, simplePredsOnly) && pushable); 337 return pushable; 338 } 339 340 348 public ValueNode remapColumnReferencesToExpressions() 349 throws StandardException 350 { 351 leftOperand = leftOperand.remapColumnReferencesToExpressions(); 353 rightOperandList.remapColumnReferencesToExpressions(); 354 return this; 355 } 356 357 362 public boolean isConstantExpression() 363 { 364 return (leftOperand.isConstantExpression() && 365 rightOperandList.isConstantExpression()); 366 } 367 368 369 public boolean constantExpression(PredicateList whereClause) 370 { 371 return (leftOperand.constantExpression(whereClause) && 372 rightOperandList.constantExpression(whereClause)); 373 } 374 375 388 protected int getOrderableVariantType() throws StandardException 389 { 390 int leftType = leftOperand.getOrderableVariantType(); 391 int rightType = rightOperandList.getOrderableVariantType(); 392 393 return Math.min(leftType, rightType); 394 } 395 396 404 public Visitable accept(Visitor v) 405 throws StandardException 406 { 407 Visitable returnNode = v.visit(this); 408 409 if (v.skipChildren(this)) 410 { 411 return returnNode; 412 } 413 414 if (leftOperand != null && !v.stopTraversal()) 415 { 416 leftOperand = (ValueNode)leftOperand.accept(v); 417 } 418 419 if (rightOperandList != null && !v.stopTraversal()) 420 { 421 rightOperandList = (ValueNodeList)rightOperandList.accept(v); 422 } 423 424 return returnNode; 425 } 426 427 430 protected boolean isEquivalent(ValueNode o) throws StandardException 431 { 432 if (!isSameNodeType(o)) 433 { 434 return false; 435 } 436 BinaryListOperatorNode other = (BinaryListOperatorNode)o; 437 if (!operator.equals(other.operator) 438 || !leftOperand.isEquivalent(other.getLeftOperand())) 439 { 440 return false; 441 } 442 443 int sz = getRightOperandList().size(); 444 if (sz != other.rightOperandList.size()) 445 { 446 return false; 447 } 448 for (int i = 0; i < sz; i++) 449 { 450 ValueNode e = (ValueNode)rightOperandList.elementAt(i); 451 if (!e.isEquivalent((ValueNode)other.rightOperandList.elementAt(i))) 452 { 453 return false; 454 } 455 } 456 return true; 457 } 458 } 459 | Popular Tags |