Search in sources :

Example 46 with MethodBuilder

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

the class IndexToBaseRowNode method generate.

/**
 * Generation of an IndexToBaseRowNode creates an
 * IndexRowToBaseRowResultSet, which uses the RowLocation in the last
 * column of an index row to get the row from the base conglomerate (heap).
 *
 * @param acb	The ActivationClassBuilder for the class being built
 * @param mb the method  for the method to be built
 *
 * @exception StandardException		Thrown on error
 */
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
    ValueNode restriction = null;
    /*
		** Get the next ResultSet #, so that we can number this ResultSetNode,
		** its ResultColumnList and ResultSet.
		*/
    assignResultSetNumber();
    // Get the CostEstimate info for the underlying scan
    setCostEstimate(getFinalCostEstimate());
    /* Put the predicates back into the tree */
    if (restrictionList != null) {
        restriction = restrictionList.restorePredicates();
        /* Allow the restrictionList to get garbage collected now
			 * that we're done with it.
			 */
        restrictionList = null;
    }
    // for the restriction, we generate an exprFun
    // that evaluates the expression of the clause
    // against the current row of the child's result.
    // if the restriction is empty, simply pass null
    // to optimize for run time performance.
    // generate the function and initializer:
    // Note: Boolean lets us return nulls (boolean would not)
    // private Boolean exprN()
    // {
    // return <<restriction.generate(ps)>>;
    // }
    // static Method exprN = method pointer to exprN;
    int heapColRefItem = -1;
    if (heapReferencedCols != null) {
        heapColRefItem = acb.addItem(heapReferencedCols);
    }
    int allColRefItem = -1;
    if (allReferencedCols != null) {
        allColRefItem = acb.addItem(allReferencedCols);
    }
    int heapOnlyColRefItem = -1;
    if (heapOnlyReferencedCols != null) {
        heapOnlyColRefItem = acb.addItem(heapOnlyReferencedCols);
    }
    /* Create the ReferencedColumnsDescriptorImpl which tells which columns
		 * come from the index.
		 */
    int indexColMapItem = acb.addItem(new ReferencedColumnsDescriptorImpl(getIndexColMapping()));
    long heapConglomNumber = baseCD.getConglomerateNumber();
    StaticCompiledOpenConglomInfo scoci = getLanguageConnectionContext().getTransactionCompile().getStaticCompiledConglomInfo(heapConglomNumber);
    acb.pushGetResultSetFactoryExpression(mb);
    mb.push(heapConglomNumber);
    mb.push(acb.addItem(scoci));
    source.generate(acb, mb);
    mb.upCast(ClassName.NoPutResultSet);
    // Skip over the index columns that are propagated from the source
    // result set, if there are such columns. We won't pass the SQL NULL
    // wrappers down to store for those columns anyways, so no need to
    // generate them in the row template.
    // NOTE: We have to check for the case where indexReferencedCols is
    // not null, but no bits are set. This can happen when we need to get
    // all of the columns from the heap due to a check constraint.
    boolean skipPropagatedCols = indexReferencedCols != null && indexReferencedCols.getNumBitsSet() != 0;
    mb.push(acb.addItem(getResultColumns().buildRowTemplate(heapReferencedCols, skipPropagatedCols)));
    mb.push(getResultSetNumber());
    mb.push(source.getBaseTableName());
    mb.push(heapColRefItem);
    mb.push(allColRefItem);
    mb.push(heapOnlyColRefItem);
    mb.push(indexColMapItem);
    // if there is no restriction, we just want to pass null.
    if (restriction == null) {
        mb.pushNull(ClassName.GeneratedMethod);
    } else {
        // this sets up the method and the static field.
        // generates:
        // Object userExprFun { }
        MethodBuilder userExprFun = acb.newUserExprFun();
        // restriction knows it is returning its value;
        /* generates:
			 *    return <restriction.generate(acb)>;
			 * and adds it to userExprFun
			 * NOTE: The explicit cast to DataValueDescriptor is required
			 * since the restriction may simply be a boolean column or subquery
			 * which returns a boolean.  For example:
			 *		where booleanColumn
			 */
        restriction.generate(acb, userExprFun);
        userExprFun.methodReturn();
        // we are done modifying userExprFun, complete it.
        userExprFun.complete();
        // restriction is used in the final result set as an access of the new static
        // field holding a reference to this new method.
        // generates:
        // ActivationClass.userExprFun
        // which is the static field that "points" to the userExprFun
        // that evaluates the where clause.
        acb.pushMethodReference(mb, userExprFun);
    }
    mb.push(forUpdate);
    mb.push(getCostEstimate().rowCount());
    mb.push(getCostEstimate().getEstimatedCost());
    mb.push(source.getTableDescriptor().getNumberOfColumns());
    mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getIndexRowToBaseRowResultSet", ClassName.NoPutResultSet, 15);
    /*
		** Remember if this result set is the cursor target table, so we
		** can know which table to use when doing positioned update and delete.
		*/
    if (cursorTargetTable) {
        acb.rememberCursorTarget(mb);
    }
}
Also used : ReferencedColumnsDescriptorImpl(org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl) StaticCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo) MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 47 with MethodBuilder

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

the class ExpressionClassBuilder method newUserExprFun.

/**
 * Start a user expression.  The difference between a normal expression
 * (returned by newExprFun)
 * and a user expression is that a user expression catches all exceptions
 * (because we don't want random exceptions thrown from user methods to
 * propagate to the rest of the system.
 *
 * @return	A new MethodBuilder
 */
MethodBuilder newUserExprFun() {
    MethodBuilder mb = newExprFun();
    mb.addThrownException("java.lang.Exception");
    return mb;
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

Example 48 with MethodBuilder

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

the class ExpressionClassBuilder method newGeneratedFun.

private MethodBuilder newGeneratedFun(String exprName, String returnType, int modifiers, String[] params) {
    // 
    // create a new method supplying the given modifiers and return Type
    // Java: #modifiers #returnType #exprName { }
    // 
    MethodBuilder exprMethod;
    if (params == null) {
        exprMethod = cb.newMethodBuilder(modifiers, returnType, exprName);
    } else {
        exprMethod = cb.newMethodBuilder(modifiers, returnType, exprName, params);
    }
    // 
    // declare it to throw StandardException
    // Java: #modifiers #returnType #exprName throws StandardException { }
    // 
    exprMethod.addThrownException(ClassName.StandardException);
    return exprMethod;
}
Also used : MethodBuilder(org.apache.derby.iapi.services.compiler.MethodBuilder)

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