Search in sources :

Example 1 with LocalField

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

the class ActivationClassBuilder method getCurrentSetup.

// /////////////////////////////////////////////////////////////////////
// 
// CURRENT DATE/TIME SUPPORT
// 
// /////////////////////////////////////////////////////////////////////
/*
		The first time a current datetime is needed, create the class
		level support for it. The first half of the logic is in our parent
		class.
	 */
@Override
protected LocalField getCurrentSetup() {
    if (cdtField != null)
        return cdtField;
    LocalField lf = super.getCurrentSetup();
    // 3) the execute method gets a statement (prior to the return)
    // to tell cdt to restart:
    // cdt.forget();
    MethodBuilder execute = getExecuteMethod();
    execute.getField(lf);
    execute.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null, "forget", "void", 0);
    return lf;
}
Also used : LocalField(org.apache.derby.iapi.services.compiler.LocalField) MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 2 with LocalField

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

the class PredicateList method generateStartKey.

/**
 * @see OptimizablePredicateList#generateStartKey
 *
 * @exception StandardException		Thrown on error
 */
public void generateStartKey(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable) throws StandardException {
    ExpressionClassBuilder acb = (ExpressionClassBuilder) acbi;
    if (numberOfStartPredicates != 0) {
        /* This sets up the method and the static field */
        MethodBuilder exprFun = acb.newExprFun();
        /* Now we fill in the body of the method */
        LocalField rowField = generateIndexableRow(acb, numberOfStartPredicates);
        int colNum = 0;
        for (Predicate pred : this) {
            if (!pred.isStartKey())
                continue;
            generateSetColumn(acb, exprFun, colNum, pred, optTable, rowField, true);
            colNum++;
        }
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(colNum == numberOfStartPredicates, "Number of start predicates does not match");
        }
        finishKey(acb, mb, exprFun, rowField);
        return;
    }
    mb.pushNull(ClassName.GeneratedMethod);
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder) LocalField(org.apache.derby.iapi.services.compiler.LocalField) OptimizablePredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate)

Example 3 with LocalField

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

the class PredicateList method generateStopKey.

/**
 * @see OptimizablePredicateList#generateStopKey
 *
 * @exception StandardException		Thrown on error
 */
public void generateStopKey(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable) throws StandardException {
    ExpressionClassBuilder acb = (ExpressionClassBuilder) acbi;
    if (numberOfStopPredicates != 0) {
        /* This sets up the method and the static field */
        MethodBuilder exprFun = acb.newExprFun();
        /* Now we fill in the body of the method */
        LocalField rowField = generateIndexableRow(acb, numberOfStopPredicates);
        int colNum = 0;
        for (Predicate pred : this) {
            if (!pred.isStopKey())
                continue;
            generateSetColumn(acb, exprFun, colNum, pred, optTable, rowField, false);
            colNum++;
        }
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(colNum == numberOfStopPredicates, "Number of stop predicates does not match");
        }
        finishKey(acb, mb, exprFun, rowField);
        return;
    }
    mb.pushNull(ClassName.GeneratedMethod);
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder) LocalField(org.apache.derby.iapi.services.compiler.LocalField) OptimizablePredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate)

Example 4 with LocalField

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

the class InListOperatorNode method generateExpression.

/**
 * Do code generation for this IN list operator.
 *
 * @param acb	The ExpressionClassBuilder for the class we're generating
 * @param mb The MethodBuilder the expression will go into
 *
 * @exception StandardException		Thrown on error
 */
@Override
void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException {
    int listSize = rightOperandList.size();
    String resultTypeName;
    String receiverType = ClassName.DataValueDescriptor;
    String leftInterfaceType = ClassName.DataValueDescriptor;
    String rightInterfaceType = ClassName.DataValueDescriptor + "[]";
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(listSize > 0, "listSize is expected to be > 0");
    }
    /*
		** There are 2 parts to the code generation for an IN list -
		** the code in the constructor and the code for the expression evaluation.
		** The code that gets generated for the constructor is:
		**		DataValueDescriptor[] field = new DataValueDescriptor[size];
		**	For each element in the IN list that is a constant, we also generate:
		**		field[i] = rightOperandList[i];
		**	
		** If the IN list is composed entirely of constants, then we generate the
		** the following:
		**		leftOperand.in(rightOperandList, leftOperand, isNullable(), ordered, result);
		**
		** Otherwise, we create a new method.  This method contains the 
		** assignment of the non-constant elements into the array and the call to the in()
		** method, which is in the new method's return statement.  We then return a call
		** to the new method.
		*/
    /* Figure out the result type name */
    resultTypeName = getTypeCompiler().interfaceName();
    // Generate the code to build the array
    LocalField arrayField = generateListAsArray(acb, mb);
    /*
		** Call the method for this operator.
		*/
    /*
		** Generate (field = <left expression>).  This assignment is
		** used as the receiver of the method call for this operator,
		** and the field is used as the left operand:
		**
		**	(field = <left expression>).method(field, <right expression>...)
		*/
    // LocalField receiverField =
    // acb.newFieldDeclaration(Modifier.PRIVATE, receiverType);
    leftOperand.generateExpression(acb, mb);
    mb.dup();
    // mb.putField(receiverField); // instance for method call
    /*mb.getField(receiverField);*/
    // first arg
    mb.upCast(leftInterfaceType);
    // second arg
    mb.getField(arrayField);
    // third arg
    mb.push(isOrdered);
    mb.callMethod(VMOpcode.INVOKEINTERFACE, receiverType, methodName, resultTypeName, 3);
}
Also used : LocalField(org.apache.derby.iapi.services.compiler.LocalField)

Example 5 with LocalField

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

the class InListOperatorNode method generateListAsArray.

/**
 * Generate the code to create an array of DataValueDescriptors that
 * will hold the IN-list values at execution time.  The array gets
 * created in the constructor.  All constant elements in the array
 * are initialized in the constructor.  All non-constant elements,
 * if any, are initialized each time the IN list is evaluated.
 *
 * @param acb The ExpressionClassBuilder for the class we're generating
 * @param mb The MethodBuilder the expression will go into
 */
protected LocalField generateListAsArray(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException {
    int listSize = rightOperandList.size();
    LocalField arrayField = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.DataValueDescriptor + "[]");
    /* Assign the initializer to the DataValueDescriptor[] field */
    MethodBuilder cb = acb.getConstructor();
    cb.pushNewArray(ClassName.DataValueDescriptor, listSize);
    cb.setField(arrayField);
    /* Set the array elements that are constant */
    int numConstants = 0;
    MethodBuilder nonConstantMethod = null;
    MethodBuilder currentConstMethod = cb;
    for (int index = 0; index < listSize; index++) {
        MethodBuilder setArrayMethod;
        if (rightOperandList.elementAt(index) instanceof ConstantNode) {
            numConstants++;
            /*if too many statements are added  to a  method, 
				*size of method can hit  65k limit, which will
				*lead to the class format errors at load time.
				*To avoid this problem, when number of statements added 
				*to a method is > 2048, remaing statements are added to  a new function
				*and called from the function which created the function.
				*See Beetle 5135 or 4293 for further details on this type of problem.
				*/
            if (currentConstMethod.statementNumHitLimit(1)) {
                MethodBuilder genConstantMethod = acb.newGeneratedFun("void", Modifier.PRIVATE);
                currentConstMethod.pushThis();
                currentConstMethod.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null, genConstantMethod.getName(), "void", 0);
                // if it is a generate function, close the metod.
                if (currentConstMethod != cb) {
                    currentConstMethod.methodReturn();
                    currentConstMethod.complete();
                }
                currentConstMethod = genConstantMethod;
            }
            setArrayMethod = currentConstMethod;
        } else {
            if (nonConstantMethod == null)
                nonConstantMethod = acb.newGeneratedFun("void", Modifier.PROTECTED);
            setArrayMethod = nonConstantMethod;
        }
        // first arg
        setArrayMethod.getField(arrayField);
        rightOperandList.elementAt(index).generateExpression(acb, setArrayMethod);
        // second arg
        setArrayMethod.upCast(ClassName.DataValueDescriptor);
        setArrayMethod.setArrayElement(index);
    }
    // if a generated function was created to reduce the size of the methods close the functions.
    if (currentConstMethod != cb) {
        currentConstMethod.methodReturn();
        currentConstMethod.complete();
    }
    if (nonConstantMethod != null) {
        nonConstantMethod.methodReturn();
        nonConstantMethod.complete();
        mb.pushThis();
        mb.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null, nonConstantMethod.getName(), "void", 0);
    }
    return arrayField;
}
Also used : LocalField(org.apache.derby.iapi.services.compiler.LocalField) MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Aggregations

LocalField (org.apache.derby.iapi.services.compiler.LocalField)32 MethodBuilder (org.apache.derby.iapi.services.compiler.MethodBuilder)18 OptimizablePredicate (org.apache.derby.iapi.sql.compile.OptimizablePredicate)3 TypeCompiler (org.apache.derby.iapi.sql.compile.TypeCompiler)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)1 CostEstimate (org.apache.derby.iapi.sql.compile.CostEstimate)1 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)1 SqlXmlUtil (org.apache.derby.iapi.types.SqlXmlUtil)1 TypeId (org.apache.derby.iapi.types.TypeId)1