📄 parameternode.java
字号:
orderableVariantType = type; } //////////////////////////////////////////////////////////////////////// // // OVERRIDE METHODS IN VALUE NODE THAT ARE USED WHILE BINDING REPLICATED // CALL WORK STATEMENTS. // // In this scenario, a JSQLType was replicated along with this parameter. // The JSQLType represents the bind() decision of the remote system, which // we want to reproduce locally. // //////////////////////////////////////////////////////////////////////// /** * Set the JSQLType of this parameter. This supports the unnamed parameters * that we use for replicated work units. * * @param type the JSQLType associated with this parameter */ public void setJSQLType ( JSQLType type ) { jsqlType = type; } /** * Get the JSQLType associated with this parameter. Again, part of method * resolution for replicated work units. * * @return the JSQLType that the remote system assigned */ public JSQLType getJSQLType() { return jsqlType; } //////////////////////////////////////////////////////////////////// // // CODE GENERATOR // //////////////////////////////////////////////////////////////////// /** * For a ParameterNode, we generate a call to the type factory * to get a DataValueDescriptor, and pass the result to the * setStorableDataValue method of the ParameterValueSet for the * generated class. We push the DataValueDescriptor field as the * generated expression. * * Generated code: * * In the constructor for the generated class: * * ((ParameterValueSet) pvs). * setStorableDataValue( * <generated null>, * parameterNumber, jdbcType, className); * * For the return value: * * (<java type name>) * ( (ParameterValueSet) pvs. * getParameter(parameterNumber) ) * * pvs is a ParameterValueSet that lives in the superclass of the class * being generated. * * @param acb The ExpressionClassBuilder for the class being built * @param mb The method the expression will go into * * * @exception StandardException Thrown on error */ public void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException { DataTypeDescriptor dtd = getTypeServices(); if ((dtd != null) && dtd.getTypeId().isXMLTypeId()) { // We're a parameter that corresponds to an XML column/target, // which we don't allow. We throw the error here instead of // in "bindExpression" because at the time of bindExpression, // we don't know yet what the type is going to be (only when // the node that points to this parameter calls // "setDescriptor" do we figure out the type). throw StandardException.newException( SQLState.LANG_ATTEMPT_TO_BIND_XML); } // PUSHCOMPILE /* Reuse code if possible */ //if (genRetval != null) // return genRetval; /* ** First, generate the holder in the constructor. */ generateHolder(acb); /* now do the return value */ /* First, get the field that holds the ParameterValueSet */ acb.pushPVSReference(mb); mb.push(parameterNumber); // arg mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getParameter", ClassName.DataValueDescriptor, 1); // For some types perform host variable checking // to match DB2/JCC where if a host variable is too // big it is not accepted, regardless of any trailing padding. switch (dtd.getJDBCTypeId()) { case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case Types.BLOB: mb.dup(); mb.push(dtd.getMaximumWidth()); mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "checkHostVariable", "void", 1); break; default: break; } /* Cast the result to its specific interface */ mb.cast(getTypeCompiler().interfaceName()); } // End of generateExpression /* ** parameters might never be used, but still need ** to have space allocated for them and be assigned ** to, for the query to operate. ** ** This generates the minimum code needed to make ** the parameter exist. */ void generateHolder(ExpressionClassBuilder acb) throws StandardException { MethodBuilder constructor = acb.getConstructor(); if (generated) return; generated = true; /* ** First, build the statement in the constructor. */ acb.pushPVSReference(constructor); acb.generateNull(constructor, getTypeCompiler()); constructor.upCast(ClassName.DataValueDescriptor); constructor.push(parameterNumber); // second arg TypeId myId = getTypeId(); constructor.push(myId.getJDBCTypeId()); // third arg constructor.push(myId.getCorrespondingJavaTypeName()); // fouth arg constructor.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "setStorableDataValue", "void", 4); /* The constructor portion is done */ } public TypeId getTypeId() { return (returnOutputParameter != null) ? returnOutputParameter.getTypeId() : super.getTypeId(); } //////////////////////////////////////////////////////////////////// // // STATIC ROUTINES // //////////////////////////////////////////////////////////////////// /** * Generate the code to create the ParameterValueSet, if necessary, * when constructing the activation. Also generate the code to call * a method that will throw an exception if we try to execute without * all the parameters being set. * * This generated code goes into the Activation's constructor early on. * * @param acb The ExpressionClassBuilder for the class we're building * @param numberOfParameters number of parameters for this statement * @param parameterList The parameter list for the statement. * * @return Nothing * * @exception StandardException on error */ static public void generateParameterValueSet(ExpressionClassBuilder acb, int numberOfParameters, Vector parameterList) throws StandardException { if (numberOfParameters > 0) { MethodBuilder constructor = acb.getConstructor(); /* ** Check the first parameter to see if it is a return ** parameter. */ boolean hasReturnParam = ((ParameterNode)parameterList.elementAt(0)).isReturnOutputParam(); /* ** Generate the following: ** ** pvs = ** getLanguageConnectionContext() ** .getLanguageFactory() ** .getParameterValueSet(numberOfParameters); ** ** pvs is a ParameterValueSet that lives in the superclass of ** the activation being generated. */ constructor.pushThis(); // for the put field down below /* Generate the call to getContext */ //?X constructor.pushThis(); //?Xconstructor.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getLanguageConnectionContext", //?X ClassName.LanguageConnectionContext, 0); /* ** Call getLanguageFactory() */ //?Xconstructor.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getLanguageFactory", //?X ClassName.LanguageFactory, 0); /* ** Call getParameterValueSet(<number of parameters>, <hasReturnParam>) */ constructor.push(numberOfParameters); // first arg constructor.push(hasReturnParam); // second arg constructor.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "setParameterValueSet", "void", 2); //?Xconstructor.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getParameterValueSet", //?X ClassName.ParameterValueSet, 2); /* Assign the return from getParameterValueSet() to the field */ //?Xconstructor.putField(ClassName.BaseActivation, "pvs", ClassName.ParameterValueSet); //?Xconstructor.endStatement(); /* ** Add a call to the execute() method to check ** for missing parameters */ MethodBuilder executeMethod = acb.getExecuteMethod(); executeMethod.pushThis(); executeMethod.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "throwIfMissingParms", "void", 0); } } /* ** When all other generation is done for the statement, ** we need to ensure all of the parameters have been touched. * * @param acb ExpressionClassBuilder * @param parameterList list of parameter * * @exception StandardException Thrown on error */ static public void generateParameterHolders ( ExpressionClassBuilder acb, Vector parameterList ) throws StandardException { if (parameterList == null) return; for (Enumeration paramEnum = parameterList.elements(); paramEnum.hasMoreElements(); ) { ((ParameterNode)paramEnum.nextElement()).generateHolder(acb); } } /** * Get the default value for the parameter. Parameters * may get default values for optimization purposes. * * @return the value, may be null */ DataValueDescriptor getDefaultValue() { return defaultValue; } /** * @see ValueNode#isParameterNode */ public boolean isParameterNode() { return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -