Package org.apache.derby.impl.sql.compile

Examples of org.apache.derby.impl.sql.compile.ActivationClassBuilder


    default :
      throw StandardException.newException(SQLState.LANG_UNAVAILABLE_ACTIVATION_NEED,
          String.valueOf(nodeChoice));
    }

    ActivationClassBuilder generatingClass = new ActivationClassBuilder(
                    superClass,
                    getCompilerContext());

        /*
         * Generate the code to execute this statement.
         * Two methods are generated here: execute() and
         * fillResultSet().
         * <BR>
         * execute is called for every execution of the
         * Activation. Nodes may add code to this using
         * ActivationClassBuilder.getExecuteMethod().
         * This code will be executed every execution.
         * <BR>
         * fillResultSet is called by execute if the BaseActivation's
         * resultSet field is null and the returned ResultSet is
         * set into the the resultSet field.
         * <P>
         * The generated code is equivalent to:
         * <code>
         * public ResultSet execute() {
         *
         *    // these two added by ActivationClassBuilder
         *    throwIfClosed("execute");
         *    startExecution();
         *   
         *    [per-execution code added by nodes]
         *   
         *    if (resultSet == null)
         *        resultSet = fillResultSet();
         *   
         *    return resultSet;
         * }
         * </code>
         */

        MethodBuilder executeMethod = generatingClass.getExecuteMethod();

        MethodBuilder mbWorker = generatingClass.getClassBuilder().newMethodBuilder(
                Modifier.PRIVATE,
                ClassName.ResultSet,
                "fillResultSet");
        mbWorker.addThrownException(ClassName.StandardException);
       
        // Generate the complete ResultSet tree for this statement.
        // This step may add statements into the execute method
        // for per-execution actions.
        generate(generatingClass, mbWorker);
        mbWorker.methodReturn();
        mbWorker.complete();

    executeMethod.pushThis();
    executeMethod.getField(ClassName.BaseActivation, "resultSet",
                ClassName.ResultSet);
       
    executeMethod.conditionalIfNull();
       
            // Generate the result set tree and store the
            // resulting top-level result set into the resultSet
            // field, as well as returning it from the execute method.
     
      executeMethod.pushThis();
      executeMethod.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null,
                   "fillResultSet", ClassName.ResultSet, 0);
            executeMethod.pushThis();
            executeMethod.swap();
            executeMethod.putField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet);
           
    executeMethod.startElseCode(); // this is here as the compiler only supports ? :
      executeMethod.pushThis();
      executeMethod.getField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet);
    executeMethod.completeConditional();

       // wrap up the activation class definition
    // generate on the tree gave us back the newExpr
    // for getting a result set on the tree.
    // we put it in a return statement and stuff
    // it in the execute method of the activation.
    // The generated statement is the expression:
    // the activation class builder takes care of constructing it
    // for us, given the resultSetExpr to use.
    //   return (this.resultSet = #resultSetExpr);
    generatingClass.finishExecuteMethod(this instanceof CursorNode);

    // wrap up the constructor by putting a return at the end of it
    generatingClass.finishConstructor();

    try {
      // cook the completed class into a real class
      // and stuff it into activationClass
      GeneratedClass activationClass = generatingClass.getGeneratedClass(byteCode);

      return activationClass;
    } catch (StandardException e) {
     
      String msgId = e.getMessageId();
View Full Code Here


    {
      SanityManager.ASSERT(expressionBuilder instanceof ActivationClassBuilder,
        "Expecting an ActivationClassBuilder");
    }

    ActivationClassBuilder  acb = (ActivationClassBuilder) expressionBuilder;
    /* Reuse generated code, where possible */

    /* Generate the appropriate (Any or Once) ResultSet */
    if (subqueryType == EXPRESSION_SUBQUERY)
    {
      resultSetString = "getOnceResultSet";
    }
    else
    {
      resultSetString = "getAnyResultSet";
    }

    // Get cost estimate for underlying subquery
    CostEstimate costEstimate = resultSet.getFinalCostEstimate();

    /* Generate a new method.  It's only used within the other
     * exprFuns, so it could be private. but since we don't
     * generate the right bytecodes to invoke private methods,
     * we just make it protected.  This generated class won't
     * have any subclasses, certainly! (nat 12/97)
     */
    String subqueryTypeString =
              getTypeCompiler().interfaceName();
    MethodBuilder  mb = acb.newGeneratedFun(subqueryTypeString, Modifier.PROTECTED);

    /* Declare the field to hold the suquery's ResultSet tree */
    LocalField rsFieldLF = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.NoPutResultSet);

    ResultSetNode subNode = null;

    if (!isMaterializable())
    {
            MethodBuilder executeMB = acb.getExecuteMethod();
      if (pushedNewPredicate && (! hasCorrelatedCRs()))
      {
        /* We try to materialize the subquery if it can fit in the memory.  We
         * evaluate the subquery first.  If the result set fits in the memory,
         * we replace the resultset with in-memory unions of row result sets.
         * We do this trick by replacing the child result with a new node --
         * MaterializeSubqueryNode, which essentially generates the suitable
         * code to materialize the subquery if possible.  This may have big
         * performance improvement.  See beetle 4373.
         */
        if (SanityManager.DEBUG)
        {
          SanityManager.ASSERT(resultSet instanceof ProjectRestrictNode,
            "resultSet expected to be a ProjectRestrictNode!");
        }
        subNode = ((ProjectRestrictNode) resultSet).getChildResult();
        LocalField subRS = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.NoPutResultSet);
        mb.getField(subRS);
        mb.conditionalIfNull();

        ResultSetNode materialSubNode = new MaterializeSubqueryNode(subRS);

        // Propagate the resultSet's cost estimate to the new node.
        materialSubNode.costEstimate = resultSet.getFinalCostEstimate();

        ((ProjectRestrictNode) resultSet).setChildResult(materialSubNode);

        /* Evaluate subquery resultset here first.  Next time when we come to
         * this subquery it may be replaced by a bunch of unions of rows.
         */
        subNode.generate(acb, mb);
        mb.startElseCode();
        mb.getField(subRS);
        mb.completeConditional();
   
        mb.setField(subRS);

                executeMB.pushNull( ClassName.NoPutResultSet);
                executeMB.setField(subRS);
      }

            executeMB.pushNull( ClassName.NoPutResultSet);
            executeMB.setField(rsFieldLF);
      // now we fill in the body of the conditional
      mb.getField(rsFieldLF);
      mb.conditionalIfNull();
    }

    acb.pushGetResultSetFactoryExpression(mb);

    // start of args
    int nargs;

    /* Inside here is where subquery could already have been materialized. 4373
View Full Code Here

    default :
      throw StandardException.newException(SQLState.LANG_UNAVAILABLE_ACTIVATION_NEED,
          String.valueOf(nodeChoice));
    }

    ActivationClassBuilder generatingClass = new ActivationClassBuilder(
                    superClass,
                    getCompilerContext());
    MethodBuilder executeMethod = generatingClass.getExecuteMethod();


    /*
    ** the resultSet variable is cached.
    **
    **   resultSet = (resultSet == null) ? ... : resultSet
    */

    executeMethod.pushThis();
    executeMethod.getField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet);
    executeMethod.conditionalIfNull();

      /* We should generate the result set here.  However, the generated
       * code size may be too big to fit in a conditional statement for
       * Java compiler to handle (it has a jump/branch step limit).  For
       * example, a extremely huge insert is issued with many many rows
       * (beetle 4293).  We fork a worker method here to get the
       * generated result set, pass our parameter to it and call it.
       */
      MethodBuilder mbWorker = generatingClass.getClassBuilder().newMethodBuilder(
                            Modifier.PROTECTED,
                            ClassName.ResultSet,
                            "fillResultSet");
      mbWorker.addThrownException(ClassName.StandardException);

      // we expect to get back an expression that will give a resultSet
      // the nodes use the generatingClass: they add expression functions
      // to it, and then use those functions in their expressions.
      generate(generatingClass, mbWorker);

      mbWorker.methodReturn();
      mbWorker.complete();
      executeMethod.pushThis();
      executeMethod.callMethod(VMOpcode.INVOKEVIRTUAL, (String) null,
                   "fillResultSet", ClassName.ResultSet, 0);

    executeMethod.startElseCode(); // this is here as the compiler only supports ? :
      executeMethod.pushThis();
      executeMethod.getField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet);
    executeMethod.completeConditional();

    executeMethod.pushThis();
    executeMethod.swap();
    executeMethod.putField(ClassName.BaseActivation, "resultSet", ClassName.ResultSet);

    executeMethod.endStatement();

       // wrap up the activation class definition
    // generate on the tree gave us back the newExpr
    // for getting a result set on the tree.
    // we put it in a return statement and stuff
    // it in the execute method of the activation.
    // The generated statement is the expression:
    // the activation class builder takes care of constructing it
    // for us, given the resultSetExpr to use.
    //   return (this.resultSet = #resultSetExpr);
    generatingClass.finishExecuteMethod(this instanceof CursorNode);

    // wrap up the constructor by putting a return at the end of it
    generatingClass.finishConstructor();

    // cook the completed class into a real class
    // and stuff it into activationClass
    GeneratedClass activationClass = generatingClass.getGeneratedClass(byteCode);

    return activationClass;
   }
View Full Code Here

    {
      SanityManager.ASSERT(expressionBuilder instanceof ActivationClassBuilder,
        "Expecting an ActivationClassBuilder");
    }

    ActivationClassBuilder  acb = (ActivationClassBuilder) expressionBuilder;
    /* Reuse generated code, where possible */

    /* Generate the appropriate (Any or Once) ResultSet */
    if (subqueryType == EXPRESSION_SUBQUERY)
    {
      resultSetString = "getOnceResultSet";
    }
    else
    {
      resultSetString = "getAnyResultSet";
    }

    // Get cost estimate for underlying subquery
    CostEstimate costEstimate = resultSet.getFinalCostEstimate();

    /* Generate a new method.  It's only used within the other
     * exprFuns, so it could be private. but since we don't
     * generate the right bytecodes to invoke private methods,
     * we just make it protected.  This generated class won't
     * have any subclasses, certainly! (nat 12/97)
     */
    String subqueryTypeString =
              getTypeCompiler().interfaceName();
    MethodBuilder  mb = acb.newGeneratedFun(subqueryTypeString, Modifier.PROTECTED);

    /* Declare the field to hold the suquery's ResultSet tree */
    LocalField rsFieldLF = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.NoPutResultSet);

    ResultSetNode subNode = null;

    if (!isMaterializable())
    {
            MethodBuilder executeMB = acb.getExecuteMethod();
      if (pushedNewPredicate && (! hasCorrelatedCRs()))
      {
        /* We try to materialize the subquery if it can fit in the memory.  We
         * evaluate the subquery first.  If the result set fits in the memory,
         * we replace the resultset with in-memory unions of row result sets.
         * We do this trick by replacing the child result with a new node --
         * MaterializeSubqueryNode, which essentially generates the suitable
         * code to materialize the subquery if possible.  This may have big
         * performance improvement.  See beetle 4373.
         */
        if (SanityManager.DEBUG)
        {
          SanityManager.ASSERT(resultSet instanceof ProjectRestrictNode,
            "resultSet expected to be a ProjectRestrictNode!");
        }
        subNode = ((ProjectRestrictNode) resultSet).getChildResult();
        LocalField subRS = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.NoPutResultSet);
        mb.getField(subRS);
        mb.conditionalIfNull();

        ResultSetNode materialSubNode = new MaterializeSubqueryNode(subRS);

        // Propagate the resultSet's cost estimate to the new node.
        materialSubNode.costEstimate = resultSet.getFinalCostEstimate();

        ((ProjectRestrictNode) resultSet).setChildResult(materialSubNode);

        /* Evaluate subquery resultset here first.  Next time when we come to
         * this subquery it may be replaced by a bunch of unions of rows.
         */
        subNode.generate(acb, mb);
        mb.startElseCode();
        mb.getField(subRS);
        mb.completeConditional();
   
        mb.setField(subRS);

                executeMB.pushNull( ClassName.NoPutResultSet);
                executeMB.setField(subRS);
      }

            executeMB.pushNull( ClassName.NoPutResultSet);
            executeMB.setField(rsFieldLF);
      // now we fill in the body of the conditional
      mb.getField(rsFieldLF);
      mb.conditionalIfNull();
    }

    acb.pushGetResultSetFactoryExpression(mb);

    // start of args
    int nargs;

    /* Inside here is where subquery could already have been materialized. 4373
     */
    resultSet.generate(acb, mb);

    /* Get the next ResultSet #, so that we can number the subquery's
     * empty row ResultColumnList and Once/Any ResultSet.
     */
    int subqResultSetNumber = cc.getNextResultSetNumber();

    /* We will be reusing the RCL from the subquery's ResultSet for the
     * empty row function.  We need to reset the resultSetNumber in the
     * RCL, before we generate that function.  Now that we've called
     * generate() on the subquery's ResultSet, we can reset that
     * resultSetNumber.
     */
    resultSet.getResultColumns().setResultSetNumber(subqResultSetNumber);

    acb.pushThisAsActivation(mb);

    /* Generate code for empty row */
    resultSet.getResultColumns().generateNulls(acb, mb);

    /*
 
View Full Code Here

    {
      SanityManager.ASSERT(expressionBuilder instanceof ActivationClassBuilder,
        "Expecting an ActivationClassBuilder");
    }

    ActivationClassBuilder  acb = (ActivationClassBuilder) expressionBuilder;
    /* Reuse generated code, where possible */

    /* Generate the appropriate (Any or Once) ResultSet */
    if (subqueryType == EXPRESSION_SUBQUERY)
    {
      resultSetString = "getOnceResultSet";
    }
    else
    {
      resultSetString = "getAnyResultSet";
    }

    // Get cost estimate for underlying subquery
    CostEstimate costEstimate = resultSet.getFinalCostEstimate();

    /* Generate a new method.  It's only used within the other
     * exprFuns, so it could be private. but since we don't
     * generate the right bytecodes to invoke private methods,
     * we just make it protected.  This generated class won't
     * have any subclasses, certainly! (nat 12/97)
     */
    String subqueryTypeString =
              getTypeCompiler().interfaceName();
    MethodBuilder  mb = acb.newGeneratedFun(subqueryTypeString, Modifier.PROTECTED);

    /* Declare the field to hold the suquery's ResultSet tree */
    LocalField rsFieldLF = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.NoPutResultSet);

    ResultSetNode subNode = null;

    if (!isMaterializable())
    {
            MethodBuilder executeMB = acb.getExecuteMethod();
      if (pushedNewPredicate && (! hasCorrelatedCRs()))
      {
        /* We try to materialize the subquery if it can fit in the memory.  We
         * evaluate the subquery first.  If the result set fits in the memory,
         * we replace the resultset with in-memory unions of row result sets.
         * We do this trick by replacing the child result with a new node --
         * MaterializeSubqueryNode, which essentially generates the suitable
         * code to materialize the subquery if possible.  This may have big
         * performance improvement.  See beetle 4373.
         */
        if (SanityManager.DEBUG)
        {
          SanityManager.ASSERT(resultSet instanceof ProjectRestrictNode,
            "resultSet expected to be a ProjectRestrictNode!");
        }
        subNode = ((ProjectRestrictNode) resultSet).getChildResult();
        LocalField subRS = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.NoPutResultSet);
        mb.getField(subRS);
        mb.conditionalIfNull();

        ResultSetNode materialSubNode = new MaterializeSubqueryNode(subRS);
        ((ProjectRestrictNode) resultSet).setChildResult(materialSubNode);

        /* Evaluate subquery resultset here first.  Next time when we come to
         * this subquery it may be replaced by a bunch of unions of rows.
         */
        subNode.generate(acb, mb);
        mb.startElseCode();
        mb.getField(subRS);
        mb.completeConditional();
   
        mb.setField(subRS);

                executeMB.pushNull( ClassName.NoPutResultSet);
                executeMB.setField(subRS);
      }

            executeMB.pushNull( ClassName.NoPutResultSet);
            executeMB.setField(rsFieldLF);
      // now we fill in the body of the conditional
      mb.getField(rsFieldLF);
      mb.conditionalIfNull();
    }

    acb.pushGetResultSetFactoryExpression(mb);

    // start of args
    int nargs;

    /* Inside here is where subquery could already have been materialized. 4373
     */
    resultSet.generate(acb, mb);

    /* Get the next ResultSet #, so that we can number the subquery's
     * empty row ResultColumnList and Once/Any ResultSet.
     */
    int subqResultSetNumber = cc.getNextResultSetNumber();

    /* We will be reusing the RCL from the subquery's ResultSet for the
     * empty row function.  We need to reset the resultSetNumber in the
     * RCL, before we generate that function.  Now that we've called
     * generate() on the subquery's ResultSet, we can reset that
     * resultSetNumber.
     */
    resultSet.getResultColumns().setResultSetNumber(subqResultSetNumber);

    acb.pushThisAsActivation(mb);

    /* Generate code for empty row */
    resultSet.getResultColumns().generateNulls(acb, mb);

    /*
 
View Full Code Here

TOP

Related Classes of org.apache.derby.impl.sql.compile.ActivationClassBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.