Examples of MethodBuilder


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

    // This method is an implementation of the interface method
    // Activation - ResultSet execute()

    // create an empty execute method
    MethodBuilder mb = cb.newMethodBuilder(Modifier.PUBLIC,
      ClassName.ResultSet, "execute");
    mb.addThrownException(ClassName.StandardException);

    // put a 'throwIfClosed("execute");' statement into the execute method.
    mb.pushThis(); // instance
    mb.push("execute");
    mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "throwIfClosed", "void", 1);

    // call this.startExecution(), so the parent class can know an execution
    // has begun.

    mb.pushThis(); // instance
    mb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "startExecution", "void", 0);

    return  mb;
  }
View Full Code Here

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

    return  mb;
  }

  MethodBuilder startResetMethod() {
    MethodBuilder mb = cb.newMethodBuilder(Modifier.PUBLIC,
      "void", "reset");

    mb.addThrownException(ClassName.StandardException);
    mb.pushThis();
    mb.callMethod(VMOpcode.INVOKESPECIAL, ClassName.BaseActivation, "reset", "void", 0);


    return mb;
  }
View Full Code Here

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

  void addCursorPositionCode() {

    // the getter
    // This method is an implementation of the interface method
    // CursorActivation - CursorResultSet getTargetResultSet()
    MethodBuilder getter = cb.newMethodBuilder(Modifier.PUBLIC,
      ClassName.CursorResultSet, "getTargetResultSet");

    getter.getField(targetResultSetField);
    getter.methodReturn();
    getter.complete();

    // This method is an implementation of the interface method
    // CursorActivation - CursorResultSet getCursorResultSet()

    getter = cb.newMethodBuilder(Modifier.PUBLIC,
      ClassName.CursorResultSet, "getCursorResultSet");

    getter.getField(cursorResultSetField);
    getter.methodReturn();
    getter.complete();
  }
View Full Code Here

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

    /* The array gets created in the constructor.
     * All constant elements in the array are initialized
     * in the constructor. 
     */
    /* Assign the initializer to the DataValueDescriptor[] field */
    MethodBuilder cb = acb.getConstructor();
    cb.pushNewArray(ClassName.DataValueDescriptor, argumentsListSize);
    cb.setField(arrayField);

    /* Set the array elements that are constant */
    int numConstants = 0;
    MethodBuilder nonConstantMethod = null;
    MethodBuilder currentConstMethod = cb;
    for (int index = 0; index < argumentsListSize; index++)
    {
      MethodBuilder setArrayMethod;
 
      if (argumentsList.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();
View Full Code Here

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

  public void generate(ActivationClassBuilder acb,
                MethodBuilder mb) throws StandardException
  {
    if (indexOfSessionTableNamesInSavedObjects != -1 ) //if this cursor references session schema tables, do following
    {
      MethodBuilder constructor = acb.getConstructor();
      constructor.pushThis();
      constructor.push(indexOfSessionTableNamesInSavedObjects);
      constructor.putField(org.apache.derby.iapi.reference.ClassName.BaseActivation, "indexOfSessionTableNamesInSavedObjects", "int");
      constructor.endStatement();
    }

    // generate the parameters
    generateParameterValueSet(acb);
View Full Code Here

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

    {
         mb.pushNull(ClassName.GeneratedMethod);
    }
    else
    {
      MethodBuilder  userExprFun = generateCheckConstraints(checkConstraints, ecb);

         // check constraint 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);
View Full Code Here

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

    throws StandardException
  {
    // this sets up the method and the static field.
    // generates:
    //   java.lang.Object userExprFun { }
    MethodBuilder userExprFun = ecb.newUserExprFun();
   
    // check constraint knows it is returning its value;
   
    /* generates:
     *    return <checkExpress.generate(ecb)>;
     * and adds it to userExprFun
     */

    checkConstraints.generateExpression(ecb, userExprFun);
    userExprFun.methodReturn();
   
    // we are done modifying userExprFun, complete it.
    userExprFun.complete();

    return userExprFun;
  }
View Full Code Here

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

    else
    {
      // this sets up the method and the static field.
      // generates:
      //   Object userExprFun { }
      MethodBuilder userExprFun = acb.newUserExprFun();

      // join clause knows it is returning its value;

      /* generates:
       *    return <joinClause.generate(acb)>;
       * and adds it to userExprFun
       */
      joinClause.generate(acb, userExprFun);
      userExprFun.methodReturn();

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

         // join clause 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

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

       //   return fieldX;
       // }
       // static Method exprN = method pointer to exprN;

       // this sets up the method and the static field.
       MethodBuilder userExprFun = acb.newUserExprFun();

    /* Declare the field */
    LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.ExecRow);

    // Generate the code to create the row in the constructor
    genCreateRow(acb, field, "getValueRow", ClassName.ExecRow, size());

    ResultColumn rc;
    int size = size();

    MethodBuilder cb = acb.getConstructor();

    for (int index = 0; index < size; index++)
    {
        // generate statements of the form
      // fieldX.setColumn(columnNumber, (DataValueDescriptor) columnExpr);
      // and add them to exprFun.
      rc = (ResultColumn) elementAt(index);

      /* If we are not generating nulls, then we can skip this RC if
       * it is simply propagating a column from the source result set.
       */
      if (!genNulls)
      {
        ValueNode sourceExpr = rc.getExpression();

        if (sourceExpr instanceof VirtualColumnNode && ! ( ((VirtualColumnNode) sourceExpr).getCorrelated()))
        {
          continue;
        }

        if (sourceExpr instanceof ColumnReference && ! ( ((ColumnReference) sourceExpr).getCorrelated()))
        {
          continue;
        }
      }


            // row add is 1-based, and iterator index is 0-based
      if (SanityManager.DEBUG)
      {
        if (index + 1 != rc.getVirtualColumnId())
        {
          SanityManager.THROWASSERT(
            "VirtualColumnId (" +
            rc.getVirtualColumnId() +
            ") does not agree with position within Vector (" +
            (index + 1) +
            ")");
        }
      }

      // we need the expressions to be Columns exactly.

      /* SPECIAL CASE:  Expression is a non-null constant.
       *  Generate the setColumn() call in the constructor
       *  so that it will only be executed once per instantiation.
       *
        * 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.
        */
      if ( (! genNulls) &&
         (rc.getExpression() instanceof ConstantNode) &&
         ! ((ConstantNode) rc.getExpression()).isNull() &&
         ! cb.statementNumHitLimit(1))
      {


        cb.getField(field); // instance
        cb.push(index + 1); // first arg;

        rc.generateExpression(acb, cb);
        cb.cast(ClassName.DataValueDescriptor); // second arg
        cb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Row, "setColumn", "void", 2);
        continue;
      }

      userExprFun.getField(field); // instance
      userExprFun.push(index + 1); // arg1
View Full Code Here

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

       //   return fieldX;
       // }
       // static Method exprN = method pointer to exprN;

       // this sets up the method and the static field
       MethodBuilder exprFun = acb.newExprFun();

    // Allocate the right type of row, depending on
    // whether we're scanning an index or a heap.
    if (indexRow)
    {
      rowAllocatorMethod = "getIndexableRow";
      rowAllocatorType = ClassName.ExecIndexRow;
    }
    else
    {
      rowAllocatorMethod = "getValueRow";
      rowAllocatorType = ClassName.ExecRow;
    }
    numCols = size();

    /* Declare the field */
    LocalField lf = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.ExecRow);
    // Generate the code to create the row in the constructor
    genCreateRow(acb, lf, rowAllocatorMethod, rowAllocatorType, highestColumnNumber + 1);

    // now we fill in the body of the function

    int colNum;

    // If there is a referenced column map, the first column to fill
    // in is the first one in the bit map - otherwise, it is
    // column 0.
    if (referencedCols != null)
      colNum = referencedCols.anySetBit();
    else
      colNum = 0;

    for (int index = 0; index < numCols; index++)
    {
      ResultColumn rc = ((ResultColumn) elementAt(index));

      /* Special code generation for RID since expression is CurrentRowLocationNode.
       * Really need yet another node type that does its own code generation.
       */
      if (rc.getExpression() instanceof CurrentRowLocationNode)
      {
        ConglomerateController cc = null;
        int savedItem;
        RowLocation rl;
       
        cc = getLanguageConnectionContext().
            getTransactionCompile().openConglomerate(
              conglomerateId,
                            false,
              0,
              TransactionController.MODE_RECORD,
              TransactionController.ISOLATION_READ_COMMITTED);
        try
        {
          rl = cc.newRowLocationTemplate();
        }
        finally
        {
          if (cc != null)
          {
            cc.close();
          }
        }

        savedItem = acb.addItem(rl);
               
        // get the RowLocation template
        exprFun.getField(lf); // instance for setColumn
        exprFun.push(highestColumnNumber + 1); // first arg

        exprFun.pushThis(); // instance for getRowLocationTemplate
        exprFun.push(savedItem); // first arg
        exprFun.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getRowLocationTemplate",
                  ClassName.RowLocation, 1);

        exprFun.upCast(ClassName.DataValueDescriptor);
        exprFun.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Row, "setColumn",
                      "void", 2);
        continue;
      }

      /* Skip over those columns whose source is the immediate
       * child result set.  (No need to generate a wrapper
       * for a SQL NULL when we are smart enough not to pass
       * that wrapper to the store.)
       * NOTE: Believe it or not, we have to check for the case
       * where referencedCols 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.
       */
      if (propagatedCols != null &&
        propagatedCols.getNumBitsSet() != 0)
      {
        /* We can skip this RC if it is simply propagating
         * a column from the source result set.
         */
        ValueNode sourceExpr = rc.getExpression();

        if (sourceExpr instanceof VirtualColumnNode)
        {
          // There is a referenced columns bit set, so use
          // it to figure out what the next column number is.
          // colNum = referencedCols.anySetBit(colNum);
          continue;
        }
      }

      // generate the column space creation call
           // generate statements of the form
        // r.setColumn(columnNumber, columnShape);
        //
        // This assumes that there are no "holes" in the column positions,
        // and that column positions reflect the stored format/order
      exprFun.getField(lf); // instance
      exprFun.push(colNum + 1); // first arg
      rc.generateHolder(acb, exprFun);

      exprFun.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Row, "setColumn", "void", 2);

      // If there is a bit map of referenced columns, use it to
      // figure out what the next column is, otherwise just go
      // to the next column.
      if (referencedCols != null)
        colNum = referencedCols.anySetBit(colNum);
      else
        colNum++;
      }
     
    // generate:
    // return fieldX;
    // and add to the end of exprFun's body.
    exprFun.getField(lf);
    exprFun.methodReturn();

    // we are done putting stuff in exprFun:
    exprFun.complete();

    return exprFun;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.