1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.compiler.MethodBuilder; 25 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.sql.compile.CompilerContext; 29 import org.apache.derby.iapi.sql.compile.TypeCompiler; 30 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 31 import org.apache.derby.iapi.types.JSQLType; 32 import org.apache.derby.iapi.types.DataTypeDescriptor; 33 import org.apache.derby.iapi.types.TypeId; 34 35 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor; 36 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 37 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 38 39 import org.apache.derby.iapi.reference.ClassName; 40 import org.apache.derby.iapi.reference.SQLState; 41 import org.apache.derby.iapi.reference.JDBC30Translation; 42 import org.apache.derby.iapi.error.StandardException; 43 44 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 45 import org.apache.derby.iapi.services.loader.ClassInspector; 46 import org.apache.derby.iapi.services.compiler.LocalField; 47 48 import org.apache.derby.iapi.util.JBitSet; 49 import org.apache.derby.iapi.services.classfile.VMOpcode; 50 51 import org.apache.derby.iapi.sql.conn.Authorizer; 52 53 import org.apache.derby.catalog.AliasInfo; 54 import org.apache.derby.catalog.TypeDescriptor; 55 import org.apache.derby.catalog.types.RoutineAliasInfo; 56 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 57 58 import org.apache.derby.catalog.UUID; 59 60 import java.util.Vector ; 61 import java.lang.reflect.Modifier ; 62 63 113 public class StaticMethodCallNode extends MethodCallNode 114 { 115 private TableName procedureName; 116 117 private LocalField[] outParamArrays; 118 private int[] applicationParameterNumbers; 119 120 private boolean isSystemCode; 121 private boolean alreadyBound; 122 123 private LocalField returnsNullOnNullState; 124 125 126 AliasDescriptor ad; 127 128 129 135 public void init(Object methodName, Object javaClassName) 136 { 137 if (methodName instanceof String ) 138 init(methodName); 139 else { 140 procedureName = (TableName) methodName; 141 init(procedureName.getTableName()); 142 } 143 144 this.javaClassName = (String ) javaClassName; 145 } 146 147 160 161 public JavaValueNode bindExpression( 162 FromList fromList, SubqueryList subqueryList, 163 Vector aggregateVector) 164 throws StandardException 165 { 166 if (alreadyBound) 168 return this; 169 170 171 bindParameters(fromList, subqueryList, aggregateVector); 172 173 174 178 if (javaClassName == null) 179 { 180 CompilerContext cc = getCompilerContext(); 181 182 if (ad == null) { 184 185 String schemaName = procedureName != null ? 186 procedureName.getSchemaName() : null; 187 188 boolean noSchema = schemaName == null; 189 190 SchemaDescriptor sd = getSchemaDescriptor(schemaName, schemaName != null); 191 192 193 resolveRoutine(fromList, subqueryList, aggregateVector, sd); 194 195 if (ad == null && noSchema && !forCallStatement) 196 { 197 sd = getSchemaDescriptor("SYSFUN", true); 203 204 resolveRoutine(fromList, subqueryList, aggregateVector, sd); 205 } 206 207 } 208 209 210 if (ad == null) 211 { 212 Object errName; 213 if (procedureName == null) 214 errName = methodName; 215 else 216 errName = procedureName; 217 218 throw StandardException.newException(SQLState.LANG_NO_SUCH_METHOD_ALIAS, errName); 219 } 220 221 222 223 224 cc.createDependency(ad); 225 226 227 methodName = ad.getAliasInfo().getMethodName(); 228 javaClassName = ad.getJavaClassName(); 229 } 230 231 232 javaClassName = verifyClassExist(javaClassName, true); 233 234 235 resolveMethodCall(javaClassName, true); 236 237 238 alreadyBound = true; 239 if (isPrivilegeCollectionRequired()) 240 getCompilerContext().addRequiredRoutinePriv(ad); 241 242 if (routineInfo != null) 245 { 246 if (methodParms != null) 247 optimizeDomainValueConversion(); 248 249 TypeDescriptor returnType = routineInfo.getReturnType(); 250 if (returnType != null) 251 { 252 TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId()); 253 254 if (returnTypeId.variableLength()) { 255 258 DataTypeDescriptor returnValueDtd = new DataTypeDescriptor( 259 returnTypeId, 260 returnType.getPrecision(), 261 returnType.getScale(), 262 returnType.isNullable(), 263 returnType.getMaximumWidth() 264 ); 265 266 267 ValueNode returnValueToSQL = (ValueNode) getNodeFactory().getNode( 268 C_NodeTypes.JAVA_TO_SQL_VALUE_NODE, 269 this, 270 getContextManager()); 271 272 ValueNode returnValueCastNode = (ValueNode) getNodeFactory().getNode( 273 C_NodeTypes.CAST_NODE, 274 returnValueToSQL, 275 returnValueDtd, 276 getContextManager()); 277 278 279 JavaValueNode returnValueToJava = (JavaValueNode) getNodeFactory().getNode( 280 C_NodeTypes.SQL_TO_JAVA_VALUE_NODE, 281 returnValueCastNode, 282 getContextManager()); 283 284 return returnValueToJava.bindExpression(fromList, subqueryList, aggregateVector); 285 } 286 287 } 288 } 289 290 return this; 291 } 292 293 304 private void optimizeDomainValueConversion() throws StandardException { 305 int count = methodParms.length; 306 for (int parm = 0; parm < count; parm++) 307 { 308 if (methodParms[parm] instanceof SQLToJavaValueNode && 309 ((SQLToJavaValueNode)methodParms[parm]).getSQLValueNode() instanceof 310 JavaToSQLValueNode) 311 { 312 JavaValueNode paramIsJavaValueNode = 315 ((JavaToSQLValueNode)((SQLToJavaValueNode)methodParms[parm]).getSQLValueNode()).getJavaValueNode(); 316 if (paramIsJavaValueNode instanceof StaticMethodCallNode) 317 { 318 StaticMethodCallNode paramIsMethodCallNode = (StaticMethodCallNode)paramIsJavaValueNode; 321 if (paramIsMethodCallNode.routineInfo != null && 326 paramIsMethodCallNode.routineInfo.calledOnNullInput()) 327 methodParms[parm] = 328 ((JavaToSQLValueNode)((SQLToJavaValueNode)methodParms[parm]).getSQLValueNode()).getJavaValueNode(); 329 } 330 } 331 } 332 } 333 334 347 private void resolveRoutine(FromList fromList, SubqueryList subqueryList, Vector aggregateVector, SchemaDescriptor sd) throws StandardException { 348 if (sd.getUUID() != null) { 349 350 java.util.List list = getDataDictionary().getRoutineList( 351 sd.getUUID().toString(), methodName, 352 forCallStatement ? AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR 353 ); 354 355 for (int i = list.size() - 1; i >= 0; i--) { 356 357 AliasDescriptor proc = (AliasDescriptor) list.get(i); 358 359 RoutineAliasInfo routineInfo = (RoutineAliasInfo) proc.getAliasInfo(); 360 int parameterCount = routineInfo.getParameterCount(); 361 if (parameterCount != methodParms.length) 362 continue; 363 364 367 TypeDescriptor[] parameterTypes = routineInfo.getParameterTypes(); 368 369 int sigParameterCount = parameterCount; 370 if (routineInfo.getMaxDynamicResultSets() > 0) 371 sigParameterCount++; 372 373 signature = new JSQLType[sigParameterCount]; 374 for (int p = 0; p < parameterCount; p++) { 375 376 378 TypeDescriptor td = parameterTypes[p]; 379 380 TypeId typeId = TypeId.getBuiltInTypeId(td.getJDBCTypeId()); 381 382 TypeId parameterTypeId = typeId; 383 384 385 int parameterMode = routineInfo.getParameterModes()[p]; 387 388 if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) { 389 390 String arrayType; 391 switch (typeId.getJDBCTypeId()) { 392 case java.sql.Types.SMALLINT: 393 case java.sql.Types.INTEGER: 394 case java.sql.Types.BIGINT: 395 case java.sql.Types.REAL: 396 case java.sql.Types.DOUBLE: 397 arrayType = getTypeCompiler(typeId).getCorrespondingPrimitiveTypeName().concat("[]"); 398 break; 399 default: 400 arrayType = typeId.getCorrespondingJavaTypeName().concat("[]"); 401 break; 402 } 403 404 typeId = TypeId.getUserDefinedTypeId(arrayType, false); 405 } 406 407 DataTypeDescriptor methoddtd = new DataTypeDescriptor( 409 typeId, 410 td.getPrecision(), 411 td.getScale(), 412 td.isNullable(), 413 td.getMaximumWidth() 414 ); 415 416 signature[p] = new JSQLType(methoddtd); 417 418 420 ValueNode sqlParamNode = null; 421 422 if (methodParms[p] instanceof SQLToJavaValueNode) { 423 SQLToJavaValueNode sql2j = (SQLToJavaValueNode) methodParms[p]; 424 sqlParamNode = sql2j.getSQLValueNode(); 425 } 426 else 427 { 428 } 429 430 boolean isParameterMarker = true; 431 if ((sqlParamNode == null) || !sqlParamNode.requiresTypeFromContext()) 432 { 433 if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) { 434 435 throw StandardException.newException(SQLState.LANG_DB2_PARAMETER_NEEDS_MARKER, 436 RoutineAliasInfo.parameterMode(parameterMode), 437 routineInfo.getParameterNames()[p]); 438 } 439 isParameterMarker = false; 440 } 441 else 442 { 443 if (applicationParameterNumbers == null) 444 applicationParameterNumbers = new int[parameterCount]; 445 if (sqlParamNode instanceof UnaryOperatorNode) { 446 ParameterNode pn = ((UnaryOperatorNode)sqlParamNode).getParameterOperand(); 447 applicationParameterNumbers[p] = pn.getParameterNumber(); 448 } else 449 applicationParameterNumbers[p] = ((ParameterNode) sqlParamNode).getParameterNumber(); 450 } 451 452 DataTypeDescriptor paramdtd = new DataTypeDescriptor( 454 parameterTypeId, 455 td.getPrecision(), 456 td.getScale(), 457 td.isNullable(), 458 td.getMaximumWidth() 459 ); 460 461 boolean needCast = false; 462 if (!isParameterMarker) 463 { 464 465 if (sqlParamNode instanceof UntypedNullConstantNode) 469 { 470 sqlParamNode.setType(paramdtd); 471 } 472 else 473 { 474 475 476 DataTypeDescriptor dts; 477 TypeId argumentTypeId; 478 479 if (sqlParamNode != null) 480 { 481 argumentTypeId = sqlParamNode.getTypeId(); 483 dts = sqlParamNode.getTypeServices(); 484 } 485 else 486 { 487 dts = DataTypeDescriptor.getSQLDataTypeDescriptor(methodParms[p].getJavaTypeName()); 489 if (dts == null) 490 { 491 throw StandardException.newException(SQLState.LANG_NO_CORRESPONDING_S_Q_L_TYPE, 492 methodParms[p].getJavaTypeName()); 493 } 494 495 argumentTypeId = dts.getTypeId(); 496 } 497 498 if (! getTypeCompiler(parameterTypeId).storable(argumentTypeId, getClassFactory())) 499 throw StandardException.newException(SQLState.LANG_NOT_STORABLE, 500 parameterTypeId.getSQLTypeName(), 501 argumentTypeId.getSQLTypeName() ); 502 503 if (!paramdtd.isExactTypeAndLengthMatch(dts)) 505 needCast = true; 506 } 507 } 508 else 509 { 510 if (parameterTypeId.variableLength()) { 515 516 if (parameterMode != JDBC30Translation.PARAMETER_MODE_OUT) 517 needCast = true; 518 } 519 } 520 521 522 if (needCast) 523 { 524 532 if (sqlParamNode == null) { 533 534 sqlParamNode = (ValueNode) getNodeFactory().getNode( 535 C_NodeTypes.JAVA_TO_SQL_VALUE_NODE, 536 methodParms[p], 537 getContextManager()); 538 } 539 540 ValueNode castNode = (ValueNode) getNodeFactory().getNode( 541 C_NodeTypes.CAST_NODE, 542 sqlParamNode, 543 paramdtd, 544 getContextManager()); 545 546 547 methodParms[p] = (JavaValueNode) getNodeFactory().getNode( 548 C_NodeTypes.SQL_TO_JAVA_VALUE_NODE, 549 castNode, 550 getContextManager()); 551 552 methodParms[p] = methodParms[p].bindExpression(fromList, subqueryList, aggregateVector); 553 } 554 555 if (isParameterMarker) 558 sqlParamNode.setType(paramdtd); 559 } 560 561 if (sigParameterCount != parameterCount) { 562 563 TypeId typeId = TypeId.getUserDefinedTypeId("java.sql.ResultSet[]", false); 564 565 DataTypeDescriptor dtd = new DataTypeDescriptor( 566 typeId, 567 0, 568 0, 569 false, 570 -1 571 ); 572 573 signature[parameterCount] = new JSQLType(dtd); 574 575 } 576 577 this.routineInfo = routineInfo; 578 ad = proc; 579 580 if (sd.isSystemSchema() && (routineInfo.getReturnType() == null) && routineInfo.getSQLAllowed() != RoutineAliasInfo.NO_SQL) 583 isSystemCode = true; 584 585 break; 586 } 587 } 588 } 589 590 594 public void generateOneParameter(ExpressionClassBuilder acb, 595 MethodBuilder mb, 596 int parameterNumber ) 597 throws StandardException 598 { 599 int parameterMode; 600 601 SQLToJavaValueNode sql2j = null; 602 if (methodParms[parameterNumber] instanceof SQLToJavaValueNode) 603 sql2j = (SQLToJavaValueNode) methodParms[parameterNumber]; 604 605 if (routineInfo != null) { 606 parameterMode = routineInfo.getParameterModes()[parameterNumber]; 607 } else { 608 612 parameterMode = JDBC30Translation.PARAMETER_MODE_IN; 613 614 if (sql2j != null) { 615 if (sql2j.getSQLValueNode().requiresTypeFromContext()) { 616 ParameterNode pn; 617 if (sql2j.getSQLValueNode() instanceof UnaryOperatorNode) 618 pn = ((UnaryOperatorNode)sql2j.getSQLValueNode()).getParameterOperand(); 619 else 620 pn = (ParameterNode) (sql2j.getSQLValueNode()); 621 622 int applicationParameterNumber = pn.getParameterNumber(); 624 625 String parameterType = methodParameterTypes[parameterNumber]; 626 627 if (parameterType.endsWith("[]")) { 628 629 MethodBuilder constructor = acb.getConstructor(); 631 acb.pushThisAsActivation(constructor); 632 constructor.callMethod(VMOpcode.INVOKEINTERFACE, null, 633 "getParameterValueSet", ClassName.ParameterValueSet, 0); 634 635 constructor.push(applicationParameterNumber); 636 constructor.push(JDBC30Translation.PARAMETER_MODE_UNKNOWN); 637 constructor.callMethod(VMOpcode.INVOKEINTERFACE, null, 638 "setParameterMode", "void", 2); 639 constructor.endStatement(); 640 } 641 } 642 } 643 } 644 645 switch (parameterMode) { 646 case JDBC30Translation.PARAMETER_MODE_IN: 647 case JDBC30Translation.PARAMETER_MODE_IN_OUT: 648 case JDBC30Translation.PARAMETER_MODE_UNKNOWN: 649 if (sql2j != null) 650 sql2j.returnsNullOnNullState = returnsNullOnNullState; 651 super.generateOneParameter(acb, mb, parameterNumber); 652 break; 653 654 case JDBC30Translation.PARAMETER_MODE_OUT: 655 break; 658 } 659 660 switch (parameterMode) { 661 case JDBC30Translation.PARAMETER_MODE_IN: 662 case JDBC30Translation.PARAMETER_MODE_UNKNOWN: 663 break; 664 665 case JDBC30Translation.PARAMETER_MODE_IN_OUT: 666 case JDBC30Translation.PARAMETER_MODE_OUT: 667 { 668 673 String methodParameterType = methodParameterTypes[parameterNumber]; 674 String arrayType = methodParameterType.substring(0, methodParameterType.length() - 2); 675 LocalField lf = acb.newFieldDeclaration(Modifier.PRIVATE, methodParameterType); 676 677 if (outParamArrays == null) 678 outParamArrays = new LocalField[methodParms.length]; 679 680 outParamArrays[parameterNumber] = lf; 681 682 mb.pushNewArray(arrayType, 1); 683 mb.putField(lf); 684 685 if (parameterMode != JDBC30Translation.PARAMETER_MODE_OUT) { 687 mb.swap(); 688 mb.setArrayElement(0); 689 mb.getField(lf); 690 } 691 break; 692 } 693 } 694 695 } 696 697 723 public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) 724 throws StandardException 725 { 726 730 if (simplePredsOnly) 731 { 732 return false; 733 } 734 735 boolean pushable = true; 736 737 pushable = pushable && super.categorize(referencedTabs, simplePredsOnly); 738 739 return pushable; 740 } 741 742 748 749 public String toString() 750 { 751 if (SanityManager.DEBUG) 752 { 753 return "javaClassName: " + 754 (javaClassName != null ? javaClassName : "null") + "\n" + 755 super.toString(); 756 } 757 else 758 { 759 return ""; 760 } 761 } 762 763 772 773 public void generateExpression(ExpressionClassBuilder acb, 774 MethodBuilder mb) 775 throws StandardException 776 { 777 if (routineInfo != null) { 778 779 if (!routineInfo.calledOnNullInput() && routineInfo.getParameterCount() != 0) 780 returnsNullOnNullState = acb.newFieldDeclaration(Modifier.PRIVATE, "boolean"); 781 782 } 783 784 if (returnsNullOnNullState != null) { 786 mb.push(false); 787 mb.setField(returnsNullOnNullState); 788 789 mb.pushThis(); 791 } 792 793 int nargs = generateParameters(acb, mb); 794 795 LocalField functionEntrySQLAllowed = null; 796 797 if (routineInfo != null) { 798 799 short sqlAllowed = routineInfo.getSQLAllowed(); 800 801 808 809 if (sqlAllowed != RoutineAliasInfo.NO_SQL) 810 { 811 812 int sqlOperation; 813 814 if (sqlAllowed == RoutineAliasInfo.READS_SQL_DATA) 815 sqlOperation = Authorizer.SQL_SELECT_OP; 816 else if (sqlAllowed == RoutineAliasInfo.MODIFIES_SQL_DATA) 817 sqlOperation = Authorizer.SQL_WRITE_OP; 818 else 819 sqlOperation = Authorizer.SQL_ARBITARY_OP; 820 821 generateAuthorizeCheck((ActivationClassBuilder) acb, mb, sqlOperation); 822 } 823 824 int statmentContextReferences = isSystemCode ? 2 : 1; 825 826 boolean isFunction = routineInfo.getReturnType() != null; 827 828 if (isFunction) 829 statmentContextReferences++; 830 831 832 if (statmentContextReferences != 0) { 833 acb.pushThisAsActivation(mb); 834 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 835 "getLanguageConnectionContext", ClassName.LanguageConnectionContext, 0); 836 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 837 "getStatementContext", "org.apache.derby.iapi.sql.conn.StatementContext", 0); 838 839 for (int scc = 1; scc < statmentContextReferences; scc++) 840 mb.dup(); 841 } 842 843 847 if (isSystemCode) { 848 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 849 "setSystemCode", "void", 0); 850 } 851 852 if (isFunction) 856 { 857 functionEntrySQLAllowed = acb.newFieldDeclaration(Modifier.PRIVATE, "short"); 858 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 859 "getSQLAllowed", "short", 0); 860 mb.setField(functionEntrySQLAllowed); 861 862 } 863 864 865 868 mb.push(sqlAllowed); 869 mb.push(false); 870 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 871 "setSQLAllowed", "void", 2); 872 873 } 874 875 if (routineInfo != null) { 877 878 int compiledResultSets = methodParameterTypes.length - methodParms.length; 879 880 if (compiledResultSets != 0) { 881 882 int maxDynamicResults = routineInfo.getMaxDynamicResultSets(); 884 if (maxDynamicResults > 0) { 885 MethodBuilder gdr = acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC, "int", "getMaxDynamicResults"); 886 gdr.push(maxDynamicResults); 887 gdr.methodReturn(); 888 gdr.complete(); 889 } 890 891 MethodBuilder gdr = acb.getClassBuilder().newMethodBuilder(Modifier.PUBLIC, "java.sql.ResultSet[][]", "getDynamicResults"); 893 894 MethodBuilder cons = acb.getConstructor(); 895 { 897 899 LocalField procedureResultSetsHolder = acb.newFieldDeclaration(Modifier.PRIVATE, "java.sql.ResultSet[][]"); 900 901 gdr.getField(procedureResultSetsHolder); 903 904 cons.pushNewArray("java.sql.ResultSet[]", compiledResultSets); 906 cons.setField(procedureResultSetsHolder); 907 908 909 for (int i = 0; i < compiledResultSets; i++) { 911 912 mb.pushNewArray("java.sql.ResultSet", 1); 913 mb.dup(); 914 915 mb.getField(procedureResultSetsHolder); 916 mb.swap(); 917 918 mb.setArrayElement(i); 919 } 920 } 921 922 gdr.methodReturn(); 924 gdr.complete(); 925 926 nargs += compiledResultSets; 927 } 928 929 } 930 931 String javaReturnType = getJavaTypeName(); 932 933 MethodBuilder mbnc = null; 934 MethodBuilder mbcm = mb; 935 936 937 if (returnsNullOnNullState != null) 940 { 941 mbnc = acb.newGeneratedFun(javaReturnType, Modifier.PRIVATE, methodParameterTypes); 942 943 Class [] throwsSet = ((java.lang.reflect.Method ) method).getExceptionTypes(); 945 for (int te = 0; te < throwsSet.length; te++) 946 { 947 mbnc.addThrownException(throwsSet[te].getName()); 948 } 949 950 mbnc.getField(returnsNullOnNullState); 951 mbnc.conditionalIf(); 952 953 mbnc.pushNull(javaReturnType); 956 957 mbnc.startElseCode(); 958 959 if (!actualMethodReturnType.equals(javaReturnType)) 960 mbnc.pushNewStart(javaReturnType); 961 962 for (int pa = 0; pa < nargs; pa++) 964 { 965 mbnc.getParameter(pa); 966 } 967 968 mbcm = mbnc; 969 } 970 971 mbcm.callMethod(VMOpcode.INVOKESTATIC, method.getDeclaringClass().getName(), methodName, 972 actualMethodReturnType, nargs); 973 974 975 if (returnsNullOnNullState != null) 976 { 977 if (!actualMethodReturnType.equals(javaReturnType)) 978 mbnc.pushNewComplete(1); 979 980 mbnc.completeConditional(); 981 982 mbnc.methodReturn(); 983 mbnc.complete(); 984 985 mb.callMethod(VMOpcode.INVOKEVIRTUAL, acb.getClassBuilder().getFullName(), mbnc.getName(), 987 javaReturnType, nargs); 988 mbnc = null; 989 } 990 991 992 if (routineInfo != null) { 993 994 if (functionEntrySQLAllowed != null) { 997 acb.pushThisAsActivation(mb); 998 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 999 "getLanguageConnectionContext", ClassName.LanguageConnectionContext, 0); 1000 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 1001 "getStatementContext", "org.apache.derby.iapi.sql.conn.StatementContext", 0); 1002 mb.getField(functionEntrySQLAllowed); 1003 mb.push(true); mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 1005 "setSQLAllowed", "void", 2); 1006 1007 } 1008 1009 if (outParamArrays != null) { 1010 1011 MethodBuilder constructor = acb.getConstructor(); 1012 1013 acb.pushThisAsActivation(constructor); 1015 constructor.callMethod(VMOpcode.INVOKEINTERFACE, null, 1016 "getParameterValueSet", ClassName.ParameterValueSet, 0); 1017 1018 acb.pushThisAsActivation(mb); 1020 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 1021 "getParameterValueSet", ClassName.ParameterValueSet, 0); 1022 1023 int[] parameterModes = routineInfo.getParameterModes(); 1024 for (int i = 0; i < outParamArrays.length; i++) { 1025 1026 int parameterMode = parameterModes[i]; 1027 if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) { 1028 1029 ValueNode sqlParamNode = ((SQLToJavaValueNode) methodParms[i]).getSQLValueNode(); 1031 1032 1033 int applicationParameterNumber = applicationParameterNumbers[i]; 1034 1035 constructor.dup(); 1037 constructor.push(applicationParameterNumber); 1038 constructor.push(parameterMode); 1039 constructor.callMethod(VMOpcode.INVOKEINTERFACE, null, 1040 "setParameterMode", "void", 2); 1041 1042 LocalField lf = outParamArrays[i]; 1044 1045 mb.dup(); 1046 mb.push(applicationParameterNumber); 1047 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, 1048 "getParameter", ClassName.DataValueDescriptor, 1); 1049 1050 DataTypeDescriptor paramdtd = sqlParamNode.getTypeServices(); 1052 1053 boolean isNumericType = paramdtd.getTypeId().isNumericTypeId(); 1054 1055 boolean isPrimitive = ((java.lang.reflect.Method ) method).getParameterTypes()[i].getComponentType().isPrimitive(); 1057 1058 if (isNumericType) { 1059 1061 if (!isPrimitive) 1062 mb.cast(ClassName.NumberDataValue); 1063 } 1064 else if (paramdtd.getTypeId().isBooleanTypeId()) 1065 { 1066 if (!isPrimitive) 1068 mb.cast(ClassName.BooleanDataValue); 1069 } 1070 1071 if (paramdtd.getTypeId().variableLength()) { 1072 mb.dup(); 1074 } 1075 1076 1077 mb.getField(lf); mb.getArrayElement(0); 1080 if (isNumericType && !isPrimitive) 1082 { 1083 mb.upCast("java.lang.Number"); 1084 } 1085 1086 mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "setValue", "void", 1); 1087 1088 if (paramdtd.getTypeId().variableLength()) { 1089 mb.push(isNumericType ? paramdtd.getPrecision() : paramdtd.getMaximumWidth()); 1090 mb.push(paramdtd.getScale()); 1091 mb.push(isNumericType); 1092 mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.VariableSizeDataValue, "setWidth", "void", 3); 1093 } 1095 } 1096 } 1097 constructor.endStatement(); 1098 mb.endStatement(); 1099 } 1100 1101 } 1102 } 1103 1104 1107 int getPrivType() 1108 { 1109 return Authorizer.EXECUTE_PRIV; 1110 } 1111} 1112 | Popular Tags |