Search in sources :

Example 16 with MethodBuilder

use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.

the class CursorNode method generate.

/**
 * Do code generation for this CursorNode
 *
 * @param acb	The ActivationClassBuilder for the class being built
 * @param mb	The method the generated code is to go into
 *
 * @exception StandardException		Thrown on error
 */
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
    if (// if this cursor references session schema tables, do following
    indexOfSessionTableNamesInSavedObjects != -1) {
        MethodBuilder constructor = acb.getConstructor();
        constructor.pushThis();
        constructor.push(indexOfSessionTableNamesInSavedObjects);
        constructor.putField(org.apache.derby.shared.common.reference.ClassName.BaseActivation, "indexOfSessionTableNamesInSavedObjects", "int");
        constructor.endStatement();
    }
    // generate the parameters
    generateParameterValueSet(acb);
    // tell the outermost result set that it is the outer
    // result set of the statement.
    resultSet.markStatementResultSet();
    // this will generate an expression that will be a ResultSet
    resultSet.generate(acb, mb);
    /*
		** Generate the position code if this cursor is updatable.  This
		** involves generating methods to get the cursor result set, and
		** the target result set (which is for the base row).  Also,
		** generate code to store the cursor result set in a generated
		** field.
		*/
    if (needTarget) {
        // PUSHCOMPILE - could be put into a single method
        acb.rememberCursor(mb);
        acb.addCursorPositionCode();
    }
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 17 with MethodBuilder

use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.

the class DMLModStatementNode method generateGenerationClauses.

/**
 *	Generate the code to evaluate all of the generation clauses. If there
 *	are generation clauses, this routine builds an Activation method which
 *	evaluates the generation clauses and fills in the computed columns.
 *
 * @param rcl  describes the row of expressions to be put into the bas table
 * @param resultSetNumber  index of base table into array of ResultSets
 * @param isUpdate true if this is for an UPDATE statement
 * @param ecb code generation state variable
 * @param mb the method being generated
 *
 * @exception StandardException		Thrown on error
 */
public void generateGenerationClauses(ResultColumnList rcl, int resultSetNumber, boolean isUpdate, ExpressionClassBuilder ecb, MethodBuilder mb) throws StandardException {
    boolean hasGenerationClauses = false;
    for (ResultColumn rc : rcl) {
        // 
        if (rc.hasGenerationClause()) {
            hasGenerationClauses = true;
            break;
        }
    }
    // if there are not generation clauses, we just want to pass null.
    if (!hasGenerationClauses) {
        mb.pushNull(ClassName.GeneratedMethod);
    } else {
        MethodBuilder userExprFun = generateGenerationClauses(rcl, resultSetNumber, isUpdate, ecb);
        // generation clause evaluation is used in the final result set
        // as an access of the new static
        // field holding a reference to this new method.
        ecb.pushMethodReference(mb, userExprFun);
    }
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 18 with MethodBuilder

use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.

the class DMLModStatementNode method generateCodeForTemporaryTable.

/**
 * If the DML is on a temporary table, generate the code to mark temporary table as modified in the current UOW.
 * At rollback transaction (or savepoint), we will check if the temporary table was modified in that UOW.
 * If yes, we will remove all the data from the temporary table
 *
 * @param acb	The ActivationClassBuilder for the class being built
 *
 * @exception StandardException		Thrown on error
 */
protected void generateCodeForTemporaryTable(ActivationClassBuilder acb) throws StandardException {
    if (targetTableDescriptor != null && targetTableDescriptor.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE && targetTableDescriptor.isOnRollbackDeleteRows() == true) {
        MethodBuilder mb = acb.getExecuteMethod();
        mb.pushThis();
        mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getLanguageConnectionContext", ClassName.LanguageConnectionContext, 0);
        mb.push(targetTableDescriptor.getName());
        mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "markTempTableAsModifiedInUnitOfWork", "void", 1);
        mb.endStatement();
    }
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 19 with MethodBuilder

use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.

the class CallStatementNode method generate.

/**
 * Code generation for CallStatementNode.
 * The generated code will contain:
 *		o  A generated void method for the user's method call.
 *
 * @param acb	The ActivationClassBuilder for the class being built
 * @param mb	The method for the execute() method to be built
 *
 * @exception StandardException		Thrown on error
 */
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
    JavaValueNode methodCallBody;
    /* generate the parameters */
    generateParameterValueSet(acb);
    /* 
		 * Skip over the JavaToSQLValueNode and call generate() for the JavaValueNode.
		 * (This skips over generated code which is unnecessary since we are throwing
		 * away any return value and which won't work with void methods.)
		 * generates:
		 *     <methodCall.generate(acb)>;
		 * and adds it to userExprFun
		 */
    methodCallBody = methodCall.getJavaValueNode();
    /*
		** Tell the method call that its return value (if any) will be
		** discarded.  This is so it doesn't generate the ?: operator
		** that would return null if the receiver is null.  This is
		** important because the ?: operator cannot be made into a statement.
		*/
    methodCallBody.markReturnValueDiscarded();
    // this sets up the method
    // generates:
    // void userExprFun {
    // method_call(<args>);
    // }
    // 
    // An expression function is used to avoid reflection.
    // Since the arguments to a procedure are simple, this
    // will be the only expression function and so it will
    // be executed directly as e0.
    MethodBuilder userExprFun = acb.newGeneratedFun("void", Modifier.PUBLIC);
    userExprFun.addThrownException("java.lang.Exception");
    methodCallBody.generate(acb, userExprFun);
    userExprFun.endStatement();
    userExprFun.methodReturn();
    userExprFun.complete();
    acb.pushGetResultSetFactoryExpression(mb);
    // first arg
    acb.pushMethodReference(mb, userExprFun);
    // arg 2
    acb.pushThisAsActivation(mb);
    mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getCallStatementResultSet", ClassName.ResultSet, 2);
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 20 with MethodBuilder

use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.

the class CastNode method genDataValueConversion.

private void genDataValueConversion(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException {
    MethodBuilder acbConstructor = acb.getConstructor();
    String resultTypeName = getTypeCompiler().interfaceName();
    /* field = method call */
    /* Allocate an object for re-use to hold the result of the operator */
    LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, resultTypeName);
    /*
		** Store the result of the method call in the field, so we can re-use
		** the object.
		*/
    acb.generateNull(acbConstructor, getTypeCompiler(getTypeId()), getTypeServices().getCollationType());
    acbConstructor.setField(field);
    if (!sourceCTI.userType() && !getTypeId().userType()) {
        // targetDVD reference for the setValue method call
        mb.getField(field);
        mb.swap();
        mb.upCast(ClassName.DataValueDescriptor);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.DataValueDescriptor, "setValue", "void", 1);
    } else {
        /* 
			** generate: expr.getObject()
			*/
        mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.DataValueDescriptor, "getObject", "java.lang.Object", 0);
        // castExpr
        // instance for the setValue/setObjectForCast method call
        mb.getField(field);
        // push it before the value
        mb.swap();
        /*
			** We are casting a java type, generate:
			**
			**		DataValueDescriptor.setObjectForCast(java.lang.Object castExpr, boolean instanceOfExpr, destinationClassName)
			** where instanceOfExpr is "source instanceof destinationClass".
			**
			*/
        String destinationType = getTypeId().getCorrespondingJavaTypeName();
        // at this point method instance and cast result are on the stack
        // we duplicate the cast value in order to perform the instanceof check
        mb.dup();
        mb.isInstanceOf(destinationType);
        mb.push(destinationType);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.DataValueDescriptor, "setObjectForCast", "void", 3);
    }
    mb.getField(field);
    /* 
		** If we are casting to a variable length datatype, we
		** have to make sure we have set it to the correct
		** length.
		*/
    if (getTypeId().variableLength()) {
        boolean isNumber = getTypeId().isNumericTypeId();
        // to leave the DataValueDescriptor value on the stack, since setWidth is void
        mb.dup();
        /* setWidth() is on VSDV - upcast since
			 * decimal implements subinterface
			 * of VSDV.
			 */
        mb.push(isNumber ? getTypeServices().getPrecision() : getTypeServices().getMaximumWidth());
        mb.push(getTypeServices().getScale());
        mb.push(!sourceCTI.variableLength() || isNumber || assignmentSemantics);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.VariableSizeDataValue, "setWidth", "void", 3);
    }
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder) LocalField(org.apache.derby.iapi.services.compiler.LocalField)

Aggregations

MethodBuilder (org.apache.derby.iapi.services.compiler.MethodBuilder)48 LocalField (org.apache.derby.iapi.services.compiler.LocalField)18 ReferencedColumnsDescriptorImpl (org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl)3 OptimizablePredicate (org.apache.derby.iapi.sql.compile.OptimizablePredicate)3 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 FormatableArrayHolder (org.apache.derby.iapi.services.io.FormatableArrayHolder)1 FormatableIntHolder (org.apache.derby.iapi.services.io.FormatableIntHolder)1 GeneratedClass (org.apache.derby.iapi.services.loader.GeneratedClass)1 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)1 CostEstimate (org.apache.derby.iapi.sql.compile.CostEstimate)1 StaticCompiledOpenConglomInfo (org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo)1 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)1 SqlXmlUtil (org.apache.derby.iapi.types.SqlXmlUtil)1 StandardException (org.apache.derby.shared.common.error.StandardException)1