Package org.apache.derby.iapi.services.compiler

Examples of org.apache.derby.iapi.services.compiler.MethodBuilder


    throws StandardException
  {
    // Create the row in the constructor
    //   fieldX = getExecutionFactory().getValueRow(# cols);

    MethodBuilder cb = acb.getConstructor();

    acb.pushGetExecutionFactoryExpression(cb); // instance
    cb.push(numCols);
    cb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null,
              rowAllocatorMethod, rowAllocatorType, 1);
    cb.setField(field);
    /* Increase the statement counter in constructor.  Code size in
     * constructor can become too big (more than 64K) for Java compiler
     * to handle (beetle 4293).  We set constant columns in other
     * methods if constructor has too many statements already.
     */
    cb.statementNumHitLimit(1);    // ignore return value
  }
View Full Code Here


  ///////////////////////////////////////////////////////////////////////

  private  final void  beginConstructor()
  {
    // create a constructor that just calls super. 
    MethodBuilder realConstructor =
      cb.newConstructorBuilder(Modifier.PUBLIC);
    realConstructor.callSuper();
    realConstructor.methodReturn();
    realConstructor.complete();

    constructor = cb.newMethodBuilder(Modifier.PUBLIC, "void", "postConstructor");
    constructor.addThrownException(ClassName.StandardException);
  }
View Full Code Here

    //
    // 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;
  }
View Full Code Here

   *
   * @return  A new MethodBuilder
   */
  MethodBuilder newUserExprFun() {

    MethodBuilder mb = newExprFun();
    mb.addThrownException("java.lang.Exception");
    return mb;
  }
View Full Code Here

        String vtiType = version2 ?
                "java.sql.PreparedStatement" : "java.sql.ResultSet";
    // this sets up the method and the static field.
    // generates:
    //   java.sql.ResultSet userExprFun { }
    MethodBuilder userExprFun = acb.newGeneratedFun(
                vtiType, Modifier.PUBLIC);
    userExprFun.addThrownException("java.lang.Exception");


    // If it's a re-useable PreparedStatement then hold onto it.
    LocalField psHolder = reuseablePs ? acb.newFieldDeclaration(Modifier.PRIVATE, "java.sql.PreparedStatement") : null;

    if (reuseablePs) {

      userExprFun.getField(psHolder);
      userExprFun.conditionalIfNull();
    }

    newInvocation.generateExpression(acb, userExprFun);
        userExprFun.upCast(vtiType);

    if (reuseablePs) {

      userExprFun.putField(psHolder);

      userExprFun.startElseCode();

      userExprFun.getField(psHolder);

      userExprFun.completeConditional();
    }

    userExprFun.methodReturn();



    // newInvocation knows it is returning its value;

    /* generates:
     *    return <newInvocation.generate(acb)>;
     */
    // we are done modifying userExprFun, complete it.
    userExprFun.complete();

       // constructor 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);


    // now add in code to close the reusable PreparedStatement when
    // the activation is closed.
    if (reuseablePs) {
      MethodBuilder closeActivationMethod = acb.getCloseActivationMethod();

      closeActivationMethod.getField(psHolder);
      closeActivationMethod.conditionalIfNull();
        // do nothing
        closeActivationMethod.push(0); // work around for no support for real if statements
      closeActivationMethod.startElseCode();
        closeActivationMethod.getField(psHolder);
        closeActivationMethod.callMethod(VMOpcode.INVOKEINTERFACE, "java.sql.Statement",
          "close", "void", 0);
        closeActivationMethod.push(0);

      closeActivationMethod.completeConditional();
      closeActivationMethod.endStatement();
    }

  }
View Full Code Here

  private void generateMinion(ExpressionClassBuilder acb,
                   MethodBuilder mb, boolean genChildResultSet)
                  throws StandardException
  {
    MethodBuilder  userExprFun;
    ValueNode  searchClause = null;
    ValueNode  equijoinClause = null;


    /* The tableProperties, if non-null, must be correct to get this far.
     * We simply call verifyProperties to set initialCapacity and
     * loadFactor.
     */
    verifyProperties(getDataDictionary());

    // build up the tree.

    /* Put the predicates back into the tree */
    if (searchPredicateList != null)
    {
      // Remove any redundant predicates before restoring
      searchPredicateList.removeRedundantPredicates();
      searchClause = searchPredicateList.restorePredicates();
      /* Allow the searchPredicateList to get garbage collected now
       * that we're done with it.
       */
      searchPredicateList = null;
    }

    // for the single table predicates, 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 <<searchClause.generate(ps)>>;
       // }
       // static Method exprN = method pointer to exprN;





    // Map the result columns to the source columns
    int[] mapArray = resultColumns.mapSourceColumns();
    int mapArrayItem = acb.addItem(new ReferencedColumnsDescriptorImpl(mapArray));

    // Save the hash key columns

    FormatableIntHolder[] fihArray =
        FormatableIntHolder.getFormatableIntHolders(hashKeyColumns());
    FormatableArrayHolder hashKeyHolder = new FormatableArrayHolder(fihArray);
    int hashKeyItem = acb.addItem(hashKeyHolder);

    /* Generate the HashTableResultSet:
     *  arg1: childExpress - Expression for childResultSet
     *  arg2: searchExpress - Expression for single table predicates
     *  arg3  : equijoinExpress - Qualifier[] for hash table look up
     *  arg4: projectExpress - Expression for projection, if any
     *  arg5: resultSetNumber
     *  arg6: mapArrayItem - item # for mapping of source columns
     *  arg7: reuseResult - whether or not the result row can be reused
     *            (ie, will it always be the same)
     *  arg8: hashKeyItem - item # for int[] of hash column #s
     *  arg9: removeDuplicates - don't remove duplicates in hash table (for now)
     *  arg10: maxInMemoryRowCount - max row size for in-memory hash table
     *  arg11: initialCapacity - initialCapacity for java.util.Hashtable
     *  arg12  : loadFactor - loadFactor for java.util.Hashtable
     *  arg13: estimated row count
     *  arg14: estimated cost
     *  arg15: close method
     */

    acb.pushGetResultSetFactoryExpression(mb);

    if (genChildResultSet)
      childResult.generateResultSet(acb, mb);
    else
      childResult.generate((ActivationClassBuilder) acb, mb);

    /* Get the next ResultSet #, so that we can number this ResultSetNode, its
     * ResultColumnList and ResultSet.
     */
    assignResultSetNumber();

    /* Set the point of attachment in all subqueries attached
     * to this node.
     */
    if (pSubqueryList != null && pSubqueryList.size() > 0)
    {
      pSubqueryList.setPointOfAttachment(resultSetNumber);
      if (SanityManager.DEBUG)
      {
        SanityManager.ASSERT(pSubqueryList.size() == 0,
          "pSubqueryList.size() expected to be 0");
      }
    }
    if (rSubqueryList != null && rSubqueryList.size() > 0)
    {
      rSubqueryList.setPointOfAttachment(resultSetNumber);
      if (SanityManager.DEBUG)
      {
        SanityManager.ASSERT(rSubqueryList.size() == 0,
          "rSubqueryList.size() expected to be 0");
      }
    }

    // Get the final cost estimate based on child's cost.
    costEstimate = childResult.getFinalCostEstimate();

    // if there is no searchClause, we just want to pass null.
    if (searchClause == null)
    {
         mb.pushNull(ClassName.GeneratedMethod);
    }
    else
    {
      // this sets up the method and the static field.
      // generates:
      //   DataValueDescriptor userExprFun { }
      userExprFun = acb.newUserExprFun();

      // searchClause knows it is returning its value;

      /* generates:
       *    return <searchClause.generate(acb)>;
       * and adds it to userExprFun
       * NOTE: The explicit cast to DataValueDescriptor is required
       * since the searchClause may simply be a boolean column or subquery
       * which returns a boolean.  For example:
       *    where booleanColumn
       */

      searchClause.generateExpression(acb, userExprFun);
      userExprFun.methodReturn();


      /* PUSHCOMPILER
      userSB.newReturnStatement(searchClause.generateExpression(acb, userSB));
      */

      // we are done modifying userExprFun, complete it.
      userExprFun.complete();

         // searchClause 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
View Full Code Here

    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
View Full Code Here

    //
    //  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);
    acb.pushMethodReference(mb, userExprFun); // first arg
    acb.pushThisAsActivation(mb); // arg 2
    mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getCallStatementResultSet", ClassName.ResultSet, 2);
View Full Code Here

  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(destCTI));
    acbConstructor.setField(field);


    /*
      For most types generate

View Full Code Here

    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.generateExpression(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);
    }

    /* Determine whether or not reflection is needed for the projection.
     * Reflection is not needed if all of the columns map directly to source
     * columns.
     */
    if (reflectionNeededForProjection())
    {
      // for the resultColumns, we generate a userExprFun
      // that creates a new row from expressions against
      // the current row of the child's result.
      // (Generate optimization: see if we can simply
      // return the current row -- we could, but don't, optimize
      // the function call out and have execution understand
      // that a null function pointer means take the current row
      // as-is, with the performance trade-off as discussed above.)

      /* Generate the Row function for the projection */
      resultColumns.generateCore(acb, mb, false);
    }
    else
    {
         mb.pushNull(ClassName.GeneratedMethod);
    }
   
    mb.push(resultSetNumber);

    // if there is no constant restriction, we just want to pass null.
    if (constantRestriction == null)
    {
         mb.pushNull(ClassName.GeneratedMethod);
    }
    else
    {
      // this sets up the method and the static field.
      // generates:
      //   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
       */
      constantRestriction.generateExpression(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
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.services.compiler.MethodBuilder

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.