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

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


    */

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

View Full Code Here


        throws StandardException
  {
    ExpressionClassBuilder  acb         = (ExpressionClassBuilder) acbi;

    String                  retvalType  = ClassName.Qualifier + "[][]";
    MethodBuilder           consMB      = acb.getConstructor();
    MethodBuilder           executeMB   = acb.getExecuteMethod();

    /* Create and initialize the array of Qualifiers */
    LocalField qualField =
            acb.newFieldDeclaration(Modifier.PRIVATE, retvalType);


    /*
    ** Stick a reinitialize of the Qualifier array in execute().
    ** Done because although we call Exec/Qualifier.clearOrderableCache()
    ** before each query, we only clear the cache for VARIANT and
    ** SCAN_INVARIANT qualifiers.  However, each time the same
    ** statement is executed, even the QUERY_INVARIANT qualifiers
    ** need to be flushed.  For example:
    **  prepare select c1 from t where c1 = (select max(c1) from t) as p;
    **  execute p; -- we now have the materialized subquery result (1)
    **         -- in our predicate
    **  insert into t values 666;
    **  execute p; -- we need to clear out 1 and recache the subq result
    */

    // PUSHCOMPILER
//    if (mb == executeMB) {
//      System.out.println("adding code to method in two places");
//      new Throwable().printStackTrace();
//    }
//

        // generate code to reinitializeQualifiers(Qualifier[][] qualifiers)
    executeMB.getField(qualField); // first arg to reinitializeQualifiers()
    executeMB.callMethod(
            VMOpcode.INVOKESTATIC,
            acb.getBaseClassName(), "reinitializeQualifiers", "void", 1);

    /*
    ** Initialize the Qualifier array to a new Qualifier[][] if
View Full Code Here

    */

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

   *
   * @return  The field that holds the indexable row
   */
  private LocalField generateIndexableRow(ExpressionClassBuilder acb, int numberOfColumns)
  {
    MethodBuilder mb = acb.getConstructor();
    /*
    ** Generate a call to get an indexable row
    ** with the given number of columns
    */
    acb.pushGetExecutionFactoryExpression(mb); // instance
    mb.push(numberOfColumns);
    mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.ExecutionFactory, "getIndexableRow", ClassName.ExecIndexRow, 1);

    /*
    ** Assign the indexable row to a field, and put this assignment into
    ** the constructor for the activation class.  This way, we only have
    ** to get the row once.
    */
    LocalField field =
      acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.ExecIndexRow);
   
    mb.setField(field);

    return field;
  }
View Full Code Here

  private int getScanArguments(ExpressionClassBuilder acb,
                      MethodBuilder mb)
    throws StandardException
  {
        // get a function to allocate scan rows of the right shape and size
         MethodBuilder resultRowAllocator =
            resultColumns.generateHolderMethod(acb,
                          referencedCols,
                          (FormatableBitSet) null);

    // pass in the referenced columns on the saved objects
View Full Code Here

                   MethodBuilder mb,
                   Optimizable optTable)
            throws StandardException
  {
    /* Generate a method that returns the expression */
    MethodBuilder qualMethod = acb.newUserExprFun();

    /*
    ** Generate the expression that's on the opposite side
    ** of the key column
    */
    if (keyColumnOnLeft(optTable))
    {
      rightOperand.generateExpression(acb, qualMethod);
    }
    else
    {
      leftOperand.generateExpression(acb, qualMethod);
    }

    qualMethod.methodReturn();
    qualMethod.complete();

    /* push an expression that evaluates to the GeneratedMethod */
    acb.pushMethodReference(mb, qualMethod);
  }
View Full Code Here

                  Optimizable optTable,
                  LocalField rowField,
                  boolean isStartKey)
      throws StandardException
  {
    MethodBuilder mb;
   
    /* Code gets generated in constructor if comparison against
     * a constant, otherwise gets generated in the current
     * statement block.
     */
    boolean withKnownConstant = false;
    if (pred.compareWithKnownConstant(optTable, false))
    {
      withKnownConstant = true;
      mb = acb.getConstructor();
    }
    else
    {
      mb = exprFun;
    }

    int[]  baseColumns = optTable.getTrulyTheBestAccessPath().
                getConglomerateDescriptor().
                  getIndexDescriptor().baseColumnPositions();
    boolean[]  isAscending = optTable.getTrulyTheBestAccessPath().
                getConglomerateDescriptor().
                  getIndexDescriptor().isAscending();

    /* If the predicate is an IN-list probe predicate then we are
     * using it as a start/stop key "placeholder", to be over-ridden
     * at execution time.  Put differently, we want to generate
     * "column = ?" as a start/stop key and then use the "?" value
     * as a placeholder into which we'll plug the various IN values
     * at execution time.
     *
     * In that case "isIn" will be false here, which is fine: there's
     * no need to generate dynamic start/stop keys like we do for
     * "normal" IN lists because we're just using the key as a place-
     * holder.  So by generating the probe predicate ("column = ?")
     * as a normal one-sided start/stop key, we get our requisite
     * execution-time placeholder and that's that.  For more on how
     * we use this "placeholder", see MultiProbeTableScanResultSet.
     *
     * Note that we generate the corresponding IN-list values
     * separately (see generateInListValues() in this class).
     */
    boolean isIn = pred.getAndNode().getLeftOperand() instanceof InListOperatorNode;

    /*
    ** Generate statements of the form
    **
    ** r.setColumn(columnNumber, columnExpression);
    **
    ** and put the generated statement in the allocator function.
    */
    mb.getField(rowField);
    mb.push(columnNumber + 1);

    // second arg
    if (isIn)
    {
      pred.getSourceInList().generateStartStopKey(
        isAscending[columnNumber], isStartKey, acb, mb);
    }
    else
      pred.generateExpressionOperand(optTable, baseColumns[columnNumber], acb, mb);

    mb.upCast(ClassName.DataValueDescriptor);

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

    /* Also tell the row if this column uses ordered null semantics */
    if (!isIn)
    {
      RelationalOperator relop = pred.getRelop();
      boolean setOrderedNulls = relop.orderedNulls();

      /* beetle 4464, performance work.  If index column is not nullable
             * (which is frequent), we should treat it as though nulls are
             * ordered (indeed because they don't exist) so that we do not have
             * to check null at scan time for each row, each column.  This is
             * an overload to "is null" operator, so that we have less overhead,
             * provided that they don't interfere.  It doesn't interfere if it
             * doesn't overload if key is null.  If key is null, but operator
       * is not orderedNull type (is null), skipScan will use this flag
             * (false) to skip scan.
       */
      if ((! setOrderedNulls) &&
                 ! relop.getColumnOperand(optTable).getTypeServices().isNullable())
      {
        if (withKnownConstant)
          setOrderedNulls = true;
        else
        {
          ValueNode keyExp =
                        relop.getExpressionOperand(
                            optTable.getTableNumber(),
                            baseColumns[columnNumber],
                            (FromTable)optTable);

          if (keyExp instanceof ColumnReference)
            setOrderedNulls =
                            ! ((ColumnReference) keyExp).getTypeServices().isNullable();
        }
      }
      if (setOrderedNulls)
      {
        mb.getField(rowField);
        mb.push(columnNumber);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.ExecIndexRow, "orderedNulls", "void", 1);
      }
    }
  }
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

    mb.cast(ClassName.NoPutResultSet);

    // add a check at activation reset time to see if the cursor has
    // changed underneath us. Doing it in the constructor allows the
    // compilation to happen
    MethodBuilder rmb = acb.startResetMethod();

    rmb.pushThis();
    rmb.push(cursorName);
    rmb.push(preStmt.getObjectName());
    rmb.callMethod(VMOpcode.INVOKEVIRTUAL, ClassName.BaseActivation, "checkPositionedStatement",
            "void", 2);

    rmb.methodReturn();
    rmb.complete();
  }
View Full Code Here

  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

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.