1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.services.context.ContextManager; 27 28 import org.apache.derby.iapi.sql.compile.CompilerContext; 29 30 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 31 import org.apache.derby.iapi.reference.SQLState; 32 import org.apache.derby.iapi.error.StandardException; 33 import org.apache.derby.iapi.store.access.Qualifier; 34 35 36 import org.apache.derby.iapi.sql.compile.Visitable; 37 import org.apache.derby.iapi.sql.compile.Visitor; 38 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 39 40 import org.apache.derby.iapi.services.loader.ClassInspector; 41 42 import org.apache.derby.iapi.services.compiler.MethodBuilder; 43 import org.apache.derby.iapi.services.sanity.SanityManager; 44 45 import org.apache.derby.iapi.types.JSQLType; 46 47 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 48 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 49 import org.apache.derby.iapi.error.ExceptionSeverity; 50 import org.apache.derby.iapi.util.JBitSet; 51 import org.apache.derby.iapi.services.classfile.VMOpcode; 52 53 import org.apache.derby.catalog.AliasInfo; 54 55 import java.lang.reflect.Modifier ; 56 57 import java.util.Vector ; 58 59 63 public class NonStaticMethodCallNode extends MethodCallNode 64 { 65 69 JavaValueNode receiver; 70 71 72 private boolean isStatic; 73 74 81 public void init( 82 Object methodName, 83 Object receiver) 84 throws StandardException 85 { 86 super.init(methodName); 87 88 94 if (receiver instanceof JavaToSQLValueNode) 95 { 96 this.receiver = ((JavaToSQLValueNode) receiver). 97 getJavaValueNode(); 98 } 99 else 100 { 101 this.receiver = (JavaValueNode) getNodeFactory(). 102 getNode( 103 C_NodeTypes.SQL_TO_JAVA_VALUE_NODE, 104 receiver, 105 getContextManager()); 106 } 112 } 113 114 127 128 public JavaValueNode bindExpression( 129 FromList fromList, SubqueryList subqueryList, 130 Vector aggregateVector) 131 throws StandardException 132 { 133 boolean nullParameter = false; 134 String [] parmTypeNames; 135 136 137 if (receiver instanceof SQLToJavaValueNode) 138 { 139 ValueNode SQLValue = 140 ((SQLToJavaValueNode) receiver).getSQLValueNode(); 141 142 if (SanityManager.DEBUG) 143 SanityManager.ASSERT(!(SQLValue instanceof UntypedNullConstantNode), 144 "UntypedNullConstantNode found as a receiver of a non-static method call"); 145 146 156 if (SQLValue.requiresTypeFromContext()) 157 { 158 if ( SQLValue.getTypeServices() == null ) 159 { throw StandardException.newException(SQLState.LANG_PARAMETER_RECEIVER, methodName); } 160 } 161 } 162 163 bindParameters(fromList, subqueryList, aggregateVector); 164 165 169 receiver = receiver.bindExpression(fromList, subqueryList, aggregateVector); 170 171 String type = receiver.getJSQLType().getSQLType().getTypeId().getSQLTypeName(); 173 if ( type.equals("BLOB") || type.equals("CLOB") || type.equals("NCLOB") ) { 174 throw StandardException.newException(SQLState.LOB_AS_METHOD_ARGUMENT_OR_RECEIVER); 175 } 176 177 javaClassName = receiver.getJavaTypeName(); 178 179 180 if (ClassInspector.primitiveType(javaClassName)) 181 { 182 throw StandardException.newException(SQLState.LANG_PRIMITIVE_RECEIVER, methodName, javaClassName); 183 } 184 185 186 resolveMethodCall(javaClassName, false); 187 188 189 isStatic = Modifier.isStatic(method.getModifiers()); 190 191 return this; 192 } 193 194 219 public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) 220 throws StandardException 221 { 222 226 if (simplePredsOnly) 227 { 228 return false; 229 } 230 231 boolean pushable = true; 232 233 pushable = pushable && super.categorize(referencedTabs, simplePredsOnly); 234 235 if (receiver != null) 236 { 237 pushable = pushable && receiver.categorize(referencedTabs, simplePredsOnly); 238 } 239 240 return pushable; 241 } 242 243 255 protected int getOrderableVariantType() throws StandardException 256 { 257 int receiverVariant = receiver.getOrderableVariantType(); 258 259 if (receiverVariant > Qualifier.SCAN_INVARIANT) { 260 261 if (receiver.getJavaTypeName().equals("org.apache.derby.iapi.db.TriggerExecutionContext")) 265 receiverVariant = Qualifier.SCAN_INVARIANT; 266 } 267 268 269 int thisVariant = super.getOrderableVariantType(); 270 if (receiverVariant < thisVariant) return receiverVariant; 272 return thisVariant; 273 } 274 275 283 public JavaValueNode remapColumnReferencesToExpressions() 284 throws StandardException 285 { 286 if (receiver != null) 287 { 288 receiver.remapColumnReferencesToExpressions(); 289 } 290 291 return super.remapColumnReferencesToExpressions(); 292 } 293 294 300 301 public void printSubNodes(int depth) 302 { 303 if (SanityManager.DEBUG) 304 { 305 int parm; 306 307 super.printSubNodes(depth); 308 if (receiver != null) 309 { 310 printLabel(depth, "receiver :"); 311 receiver.treePrint(depth + 1); 312 } 313 } 314 } 315 316 329 public void preprocess(int numTables, 330 FromList outerFromList, 331 SubqueryList outerSubqueryList, 332 PredicateList outerPredicateList) 333 throws StandardException 334 { 335 super.preprocess(numTables, 336 outerFromList, outerSubqueryList, 337 outerPredicateList); 338 receiver.preprocess(numTables, 339 outerFromList, outerSubqueryList, 340 outerPredicateList); 341 342 } 343 344 353 354 public void generateExpression(ExpressionClassBuilder acb, 355 MethodBuilder mb) 356 throws StandardException 357 { 358 boolean inConditional = false; 359 371 if ( ( ! valueReturnedToSQLDomain()) && ( ! returnValueDiscarded())) 372 { 373 if (generateReceiver(acb, mb, receiver)) 374 { 375 379 384 385 inConditional = true; 386 mb.conditionalIfNull(); 387 mb.pushNull(getJavaTypeName()); 388 mb.startElseCode(); 389 } 390 } 391 392 401 402 Class declaringClass = method.getDeclaringClass(); 403 404 408 409 short methodType; 410 411 if (declaringClass.isInterface()) 412 methodType = VMOpcode.INVOKEINTERFACE; 413 else if (isStatic) 414 methodType = VMOpcode.INVOKESTATIC; 415 else 416 methodType = VMOpcode.INVOKEVIRTUAL; 417 418 getReceiverExpression(acb, mb, receiver); 419 if (isStatic) 420 mb.endStatement(); 422 int nargs = generateParameters(acb, mb); 423 424 mb.callMethod(methodType, declaringClass.getName(), methodName, getJavaTypeName(), nargs); 425 426 if (inConditional) 427 mb.completeConditional(); 428 } 429 430 452 protected boolean generateReceiver(ExpressionClassBuilder acb, 453 MethodBuilder mb) 454 throws StandardException 455 { 456 462 if (isStatic) 463 return false; 464 465 return generateReceiver(acb, mb, receiver); 466 } 467 468 476 public Visitable accept(Visitor v) 477 throws StandardException 478 { 479 if (v.skipChildren(this)) 480 { 481 return v.visit(this); 482 } 483 484 Visitable returnNode = super.accept(v); 485 486 if (receiver != null && !v.stopTraversal()) 487 { 488 receiver = (JavaValueNode)receiver.accept(v); 489 } 490 491 return returnNode; 492 } 493 } 494 | Popular Tags |