1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.loader.ClassInspector; 25 26 import org.apache.derby.iapi.services.context.ContextManager; 27 28 import org.apache.derby.iapi.services.compiler.MethodBuilder; 29 import org.apache.derby.iapi.services.compiler.LocalField; 30 31 32 import org.apache.derby.iapi.services.sanity.SanityManager; 33 34 import org.apache.derby.iapi.error.StandardException; 35 import org.apache.derby.iapi.services.i18n.MessageService; 36 37 import org.apache.derby.iapi.sql.compile.CompilerContext; 38 39 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 40 41 import org.apache.derby.iapi.reference.SQLState; 42 43 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 44 45 import org.apache.derby.iapi.util.JBitSet; 46 47 import org.apache.derby.catalog.AliasInfo; 48 49 import java.lang.reflect.Member ; 50 import java.lang.reflect.Modifier ; 51 52 import java.util.Vector ; 53 import java.util.Enumeration ; 54 55 60 public class NewInvocationNode extends MethodCallNode 61 { 62 private boolean singleInstantiation = false; 64 65 private boolean delimitedIdentifier; 66 67 77 public void init( 78 Object javaClassName, 79 Object params, 80 Object delimitedIdentifier) 81 throws StandardException 82 { 83 super.init("<init>"); 84 addParms((Vector ) params); 85 86 this.javaClassName = (String ) javaClassName; 87 this.delimitedIdentifier = 88 ((Boolean ) delimitedIdentifier).booleanValue(); 89 } 90 91 96 void setSingleInstantiation() 97 { 98 singleInstantiation = true; 99 } 100 101 106 public Class [] getMethodParameterClasses() 107 { 108 ClassInspector ci = getClassFactory().getClassInspector(); 109 110 Class [] parmTypeClasses = new Class [methodParms.length]; 111 for (int i = 0; i < methodParms.length; i++) 112 { 113 String className = methodParameterTypes[i]; 114 try 115 { 116 parmTypeClasses[i] = ci.getClass(className); 117 } 118 catch (ClassNotFoundException cnfe) 119 { 120 123 if (SanityManager.DEBUG) 124 { 125 SanityManager.THROWASSERT( 126 "Unexpected exception - " + cnfe); 127 } 128 return null; 129 } 130 } 131 132 return parmTypeClasses; 133 } 134 135 148 149 public JavaValueNode bindExpression( 150 FromList fromList, SubqueryList subqueryList, 151 Vector aggregateVector) 152 throws StandardException 153 { 154 bindParameters(fromList, subqueryList, aggregateVector); 155 156 javaClassName = verifyClassExist(javaClassName, !delimitedIdentifier); 157 161 String [] parmTypeNames = getObjectSignature(); 162 boolean[] isParam = getIsParam(); 163 ClassInspector classInspector = getClassFactory().getClassInspector(); 164 165 168 try 169 { 170 171 method = classInspector.findPublicConstructor(javaClassName, 172 parmTypeNames, null, isParam); 173 174 177 if (method == null) 178 { 179 String [] primParmTypeNames = getPrimitiveSignature(false); 180 method = classInspector.findPublicConstructor(javaClassName, 181 parmTypeNames, primParmTypeNames, isParam); 182 } 183 } 184 catch (ClassNotFoundException e) 185 { 186 191 method = null; 192 } 193 194 if (method == null) 195 { 196 197 String parmTypes = ""; 198 for (int i = 0; i < parmTypeNames.length; i++) 199 { 200 if (i != 0) 201 parmTypes += ", "; 202 parmTypes += (parmTypeNames[i].length() != 0 ? 203 parmTypeNames[i] : 204 MessageService.getTextMessage( 205 SQLState.LANG_UNTYPED) 206 ); 207 } 208 209 throw StandardException.newException(SQLState.LANG_NO_CONSTRUCTOR_FOUND, 210 javaClassName, 211 parmTypes); 212 } 213 214 methodParameterTypes = classInspector.getParameterTypes(method); 215 216 for (int i = 0; i < methodParameterTypes.length; i++) 217 { 218 if (classInspector.primitiveType(methodParameterTypes[i])) 219 methodParms[i].castToPrimitive(true); 220 } 221 222 223 if ( someParametersAreNull() ) 224 { 225 setNullParameterInfo(methodParameterTypes); 226 } 227 228 229 if (SanityManager.DEBUG) { 230 SanityManager.ASSERT(javaClassName.equals(classInspector.getType(method)), 231 "Constructor is wrong type, expected " + javaClassName + 232 " actual is " + classInspector.getType(method)); 233 } 234 setJavaTypeName( javaClassName ); 235 236 return this; 237 } 238 239 264 public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) 265 throws StandardException 266 { 267 271 if (simplePredsOnly) 272 { 273 return false; 274 } 275 276 boolean pushable = true; 277 278 pushable = pushable && super.categorize(referencedTabs, simplePredsOnly); 279 280 return pushable; 281 } 282 283 289 void getCorrelationTables(JBitSet correlationMap) 290 throws StandardException 291 { 292 CollectNodesVisitor getCRs = new CollectNodesVisitor(ColumnReference.class); 293 super.accept(getCRs); 294 Vector colRefs = getCRs.getList(); 295 for (Enumeration e = colRefs.elements(); e.hasMoreElements(); ) 296 { 297 ColumnReference ref = (ColumnReference)e.nextElement(); 298 if (ref.getCorrelated()) 299 { 300 correlationMap.set(ref.getTableNumber()); 301 } 302 } 303 } 304 305 317 protected boolean assignableTo(String toClassName) throws StandardException 318 { 319 ClassInspector classInspector = getClassFactory().getClassInspector(); 320 return classInspector.assignableTo(javaClassName, toClassName); 321 } 322 323 324 338 protected Member findPublicMethod(String methodName, boolean staticMethod) 339 throws StandardException 340 { 341 Member publicMethod; 342 343 347 String [] parmTypeNames = getObjectSignature(); 348 boolean[] isParam = getIsParam(); 349 350 ClassInspector classInspector = getClassFactory().getClassInspector(); 351 352 try 353 { 354 publicMethod = classInspector.findPublicMethod(javaClassName, methodName, 355 parmTypeNames, null, isParam, staticMethod, false); 356 357 360 if (publicMethod == null) 361 { 362 String [] primParmTypeNames = getPrimitiveSignature(false); 363 publicMethod = classInspector.findPublicMethod(javaClassName, 364 methodName, parmTypeNames, 365 primParmTypeNames, isParam, staticMethod, false); 366 } 367 } 368 catch (ClassNotFoundException e) 369 { 370 376 if (SanityManager.DEBUG) 377 { 378 SanityManager.THROWASSERT( 379 "Unexpected ClassNotFoundException for javaClassName"); 380 } 381 return null; 382 } 383 384 return publicMethod; 385 } 386 387 396 397 public void generateExpression(ExpressionClassBuilder acb, 398 MethodBuilder mb) 399 throws StandardException 400 { 401 406 LocalField objectFieldLF = null; 407 if (singleInstantiation) 408 { 409 410 objectFieldLF = acb.newFieldDeclaration(Modifier.PRIVATE, javaClassName); 411 412 414 mb.getField(objectFieldLF); 415 mb.conditionalIfNull(); 416 } 417 418 mb.pushNewStart(javaClassName); 419 int nargs = generateParameters(acb, mb); 420 mb.pushNewComplete(nargs); 421 422 if (singleInstantiation) { 423 424 mb.putField(objectFieldLF); 425 mb.startElseCode(); 426 mb.getField(objectFieldLF); 427 mb.completeConditional(); 428 } 429 } 430 } 431 | Popular Tags |