1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import java.sql.Types ; 25 import java.util.Enumeration ; 26 import java.util.Vector ; 27 28 import org.apache.derby.iapi.error.StandardException; 29 import org.apache.derby.iapi.reference.ClassName; 30 import org.apache.derby.iapi.reference.SQLState; 31 import org.apache.derby.iapi.services.classfile.VMOpcode; 32 import org.apache.derby.iapi.services.compiler.MethodBuilder; 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 import org.apache.derby.iapi.sql.compile.CompilerContext; 35 import org.apache.derby.iapi.store.access.Qualifier; 36 import org.apache.derby.iapi.types.DataTypeDescriptor; 37 import org.apache.derby.iapi.types.DataValueDescriptor; 38 import org.apache.derby.iapi.types.JSQLType; 39 import org.apache.derby.iapi.types.TypeId; 40 41 46 47 public class ParameterNode extends ValueNode 48 { 49 50 53 private int parameterNumber; 54 55 62 63 private DataTypeDescriptor[] typeServices; 64 65 71 private DataValueDescriptor defaultValue; 72 73 78 private JSQLType jsqlType; 79 80 private int orderableVariantType = Qualifier.QUERY_INVARIANT; 81 82 87 private ValueNode returnOutputParameter; 88 89 92 public ParameterNode() 93 { 94 } 95 96 104 105 public void init(Object parameterNumber, Object defaultValue) 106 { 107 this.defaultValue = (DataValueDescriptor) defaultValue; 108 this.parameterNumber = ((Integer ) parameterNumber).intValue(); 109 } 110 111 116 117 int getParameterNumber() 118 { 119 return parameterNumber; 120 } 121 122 128 129 void setDescriptors(DataTypeDescriptor[] descriptors) 130 { 131 132 137 141 typeServices = descriptors; 142 } 143 144 149 150 public void setType(DataTypeDescriptor descriptor) throws StandardException 151 { 152 if (SanityManager.DEBUG) 153 SanityManager.ASSERT(typeServices != null, 154 "typeServices not initialized"); 155 156 157 if ( ! descriptor.isNullable()) 158 { 159 163 descriptor = new DataTypeDescriptor(descriptor, true); 164 } 165 166 typeServices[parameterNumber] = descriptor; 167 168 super.setType(descriptor); 172 173 if ( getJSQLType() == null ) { setJSQLType( new JSQLType( descriptor ) ); } 174 } 175 176 180 public void setReturnOutputParam(ValueNode valueNode) 181 { 182 returnOutputParameter = valueNode; 183 } 184 185 191 public boolean isReturnOutputParam() 192 { 193 return returnOutputParameter != null; 194 } 195 196 212 213 public ValueNode bindExpression( 214 FromList fromList, SubqueryList subqueryList, 215 Vector aggregateVector) 216 throws StandardException 217 { 218 checkReliability( "?", CompilerContext.UNNAMED_PARAMETER_ILLEGAL ); 219 220 return this; 221 } 222 223 228 public boolean isConstantExpression() 229 { 230 return true; 231 } 232 233 234 public boolean constantExpression(PredicateList whereClause) 235 { 236 return true; 237 } 238 239 251 protected int getOrderableVariantType() 252 { 253 return orderableVariantType; 255 } 256 257 263 void setOrderableVariantType(int type) 264 { 265 orderableVariantType = type; 266 } 267 268 279 285 public void setJSQLType 286 ( 287 JSQLType type 288 ) 289 { jsqlType = type; } 290 291 297 public JSQLType getJSQLType() 298 { 299 return jsqlType; 300 } 301 302 303 309 322 public void generateExpression(ExpressionClassBuilder acb, 323 MethodBuilder mb) 324 throws StandardException 325 { 326 DataTypeDescriptor dtd = getTypeServices(); 327 if ((dtd != null) && dtd.getTypeId().isXMLTypeId()) { 328 throw StandardException.newException( 335 SQLState.LANG_ATTEMPT_TO_BIND_XML); 336 } 337 338 339 340 mb.pushThis(); 341 mb.push(parameterNumber); 343 mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "getParameter", 344 ClassName.DataValueDescriptor, 1); 345 346 350 switch (dtd.getJDBCTypeId()) { 351 case Types.BINARY: 352 case Types.VARBINARY: 353 case Types.LONGVARBINARY: 354 case Types.BLOB: 355 mb.dup(); 356 mb.push(dtd.getMaximumWidth()); 357 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "checkHostVariable", 358 "void", 1); 359 break; 360 361 default: 362 break; 363 } 364 365 366 mb.cast(getTypeCompiler().interfaceName()); 367 } 369 public TypeId getTypeId() throws StandardException 370 { 371 return (returnOutputParameter != null) ? 372 returnOutputParameter.getTypeId() : super.getTypeId(); 373 } 374 375 381 395 static public void generateParameterValueSet(ExpressionClassBuilder acb, 396 int numberOfParameters, 397 Vector parameterList) 398 throws StandardException 399 { 400 if (numberOfParameters > 0) 401 { 402 MethodBuilder constructor = acb.getConstructor(); 403 404 408 boolean hasReturnParam = ((ParameterNode)parameterList.elementAt(0)).isReturnOutputParam(); 409 410 421 422 constructor.pushThis(); 424 425 431 434 437 438 constructor.push(numberOfParameters); constructor.push(hasReturnParam); 441 constructor.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, 442 "setParameterValueSet", "void", 2); 443 444 447 448 451 455 MethodBuilder executeMethod = acb.getExecuteMethod(); 456 457 executeMethod.pushThis(); 458 executeMethod.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "throwIfMissingParms", "void", 0); 459 } 460 } 461 462 468 DataValueDescriptor getDefaultValue() 469 { 470 return defaultValue; 471 } 472 473 476 public boolean requiresTypeFromContext() 477 { 478 return true; 479 } 480 481 484 public boolean isParameterNode() 485 { 486 return true; 487 } 488 489 492 protected boolean isEquivalent(ValueNode o) 493 { 494 return false; 495 } 496 } 497 | Popular Tags |