Package org.apache.derby.iapi.sql.compile

Examples of org.apache.derby.iapi.sql.compile.CompilerContext


    baseTableRestrictionList = (PredicateList) getNodeFactory().getNode(
                      C_NodeTypes.PREDICATE_LIST,
                      getContextManager());


    CompilerContext compilerContext = getCompilerContext();

    /* Generate the ResultColumnList */
    resultColumns = genResultColList();
    templateColumns = resultColumns;

    /* Resolve the view, if this is a view */
    if (tableDescriptor.getTableType() == TableDescriptor.VIEW_TYPE)
    {
      FromTable          fsq;
      ResultSetNode        rsn;
      ViewDescriptor        vd;
      CreateViewNode        cvn;
      SchemaDescriptor      compSchema;
      SchemaDescriptor      prevCompSchema;

      /* Get the associated ViewDescriptor so that we can get
       * the view definition text.
       */
      vd = dataDictionary.getViewDescriptor(tableDescriptor);

      /*
      ** Set the default compilation schema to be whatever
      ** this schema this view was originally compiled against.
      ** That way we pick up the same tables no matter what
      ** schema we are running against.
      */
      compSchema = dataDictionary.getSchemaDescriptor(vd.getCompSchemaId(), null);

      prevCompSchema = compilerContext.setCompilationSchema(compSchema);
 
      try
      {
   
        /* This represents a view - query is dependent on the ViewDescriptor */
        compilerContext.createDependency(vd);
 
        if (SanityManager.DEBUG)
        {
          SanityManager.ASSERT(vd != null,
            "vd not expected to be null for " + tableName);
        }
 
        /*
        ** Push a compiler context to parse the query text so that
        ** it won't clobber the current context.
        */
        LanguageConnectionContext lcc = getLanguageConnectionContext();
        CompilerContext newCC = lcc.pushCompilerContext();
        cvn = (CreateViewNode)
                    QueryTreeNode.parseQueryText(
                        newCC,
                        vd.getViewText(),
                        (DataValueDescriptor[])null,  // default params
View Full Code Here


   *
   * @exception StandardException    Thrown on error
   */
  public QueryTreeNode bind() throws StandardException
  {
    CompilerContext compilerContext = getCompilerContext();
    DataDictionary  dd = getDataDictionary();
    /*
    ** Grab the current schema.  We will use that for
    ** sps compilation
    */
    LanguageConnectionContext lcc = getLanguageConnectionContext();
    compSchemaDescriptor = lcc.getDefaultSchema();

    /*
    ** Get and check the schema descriptor for this
    ** trigger.  This check will throw the proper exception
    ** if someone tries to create a trigger in the SYS
    ** schema.
    */
    triggerSchemaDescriptor = getSchemaDescriptor();

    /*
    ** Get the trigger table.
    */
    triggerTableDescriptor = getTableDescriptor(tableName);

    //throw an exception if user is attempting to create a trigger on a temporary table
    if (isSessionSchema(triggerTableDescriptor.getSchemaDescriptor()))
    {
        throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
    }
    if (isPrivilegeCollectionRequired())
    {
      compilerContext.pushCurrentPrivType(Authorizer.TRIGGER_PRIV);
      compilerContext.addRequiredTablePriv(triggerTableDescriptor);
      compilerContext.popCurrentPrivType();     
    }

    /*
    ** Regenerates the actionText and actionNode if necessary.
    */
    boolean needInternalSQL = bindReferencesClause(dd);

    lcc.pushTriggerTable(triggerTableDescriptor);
    try
   
      /*
      ** Bind the trigger action and the trigger
      ** when clause to make sure that they are
      ** ok.  Note that we have already substituted
      ** in various replacements for OLD/NEW transition
      ** tables/variables and reparsed if necessary.
      */
      if (needInternalSQL)
        compilerContext.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);
     
      // For before triggers, the action statement cannot contain calls
      // to procedures that modify SQL data. If the action statement
      // contains a procedure call, this reliability will be used during
      // bind of the call statement node.
      if(isBefore)
        compilerContext.setReliability(CompilerContext.MODIFIES_SQL_DATA_PROCEDURE_ILLEGAL);
         
      actionNode.bind();

      if (whenClause != null)
      {
        whenClause.bind();
      }
    }
    finally
    {
      lcc.popTriggerTable(triggerTableDescriptor);
    }

    /*
    ** Statement is dependent on the TableDescriptor
    */
    compilerContext.createDependency(triggerTableDescriptor);

    /*
    ** If there is a list of columns, then no duplicate columns,
    ** and all columns must be found.
    */
 
View Full Code Here

    ** replaced ourselves.
    */
    if (generatedRef == null)
    {
      String          generatedColName;
      CompilerContext     cc = getCompilerContext();
      generatedColName ="SQLCol" + cc.getNextColumnNumber();
      generatedRC = (ResultColumn) getNodeFactory().getNode(
                      C_NodeTypes.RESULT_COLUMN,
                      generatedColName,
                      this,
                      getContextManager());
View Full Code Here

    */
 
  public QueryTreeNode bind() throws StandardException
  {
    DataDictionary dd = getDataDictionary();
    CompilerContext cc = getCompilerContext();
       
    TableDescriptor td = dd.getTableDescriptor(getRelativeName(),
          getSchemaDescriptor());
 
    /*
     * Statement is dependent on the TableDescriptor
     * If td is null, let execution throw the error like
     * it is before.
     */
    if (td != null)
    {
      cc.createDependency(td);
    }
     
    return this;
  }
View Full Code Here

   * @exception StandardException    Thrown on error
   */

  public QueryTreeNode bind() throws StandardException
  {
    CompilerContext      cc = getCompilerContext();
    DataDictionary      dd = getDataDictionary();
    SchemaDescriptor    sd;
    int            columnCount;

    sd = getSchemaDescriptor();
View Full Code Here

     * is an alias and we must go to sysmethods to
     * get the real method and java class names for this alias.
     */
    if (javaClassName == null)
    {
      CompilerContext cc = getCompilerContext();

      // look for a routine
      if (ad == null) {

        String schemaName = procedureName != null ?
                  procedureName.getSchemaName() : null;
                 
        boolean noSchema = schemaName == null;

        SchemaDescriptor sd = getSchemaDescriptor(schemaName, schemaName != null);


        resolveRoutine(fromList, subqueryList, aggregateVector, sd);
       
        if (ad == null && noSchema && !forCallStatement)
        {
          // Resolve to a built-in SYSFUN function but only
          // if this is a function call and the call
          // was not qualified. E.g. COS(angle). The
          // SYSFUN functions are not in SYSALIASES but
          // an in-memory table, set up in DataDictioanryImpl.
          sd = getSchemaDescriptor("SYSFUN", true);
         
          resolveRoutine(fromList, subqueryList, aggregateVector, sd);
        }
 
      }

      /* Throw exception if no alias found */
      if (ad == null)
      {
        Object errName;
        if (procedureName == null)
          errName = methodName;
        else
          errName = procedureName;

        throw StandardException.newException(SQLState.LANG_NO_SUCH_METHOD_ALIAS, errName);
      }
 


      /* Query is dependent on the AliasDescriptor */
      cc.createDependency(ad);


      methodName = ad.getAliasInfo().getMethodName();
      javaClassName = ad.getJavaClassName();
    }
View Full Code Here

   */
  public QueryTreeNode bind() throws StandardException
  {
    super.bind();

    CompilerContext cc = getCompilerContext();
    if (isPrivilegeCollectionRequired())
      cc.addRequiredSchemaPriv(name, aid, Authorizer.CREATE_SCHEMA_PRIV);

    return this;
  }
View Full Code Here

   * @exception StandardException    Thrown on error
   */
  void bindAndValidateCheckConstraints(FromList fromList)
    throws StandardException
  {
    CompilerContext cc;
    FromBaseTable        table = (FromBaseTable) fromList.elementAt(0);
    int              size = size();

    cc = getCompilerContext();

    Vector aggregateVector = new Vector();

    for (int index = 0; index < size; index++)
    {
      ConstraintDefinitionNode cdn;
      TableElementNode element = (TableElementNode) elementAt(index);
      ValueNode  checkTree;

      if (! (element instanceof ConstraintDefinitionNode))
      {
        continue;
      }

      cdn = (ConstraintDefinitionNode) element;

      if (cdn.getConstraintType() != DataDictionary.CHECK_CONSTRAINT)
      {
        continue;
      }

      checkTree = cdn.getCheckCondition();

      // bind the check condition
      // verify that it evaluates to a boolean
      final int previousReliability = cc.getReliability();
      try
      {
        /* Each check constraint can have its own set of dependencies.
         * These dependencies need to be shared with the prepared
         * statement as well.  We create a new auxiliary provider list
         * for the check constraint, "push" it on the compiler context
         * by swapping it with the current auxiliary provider list
         * and the "pop" it when we're done by restoring the old
         * auxiliary provider list.
         */
        ProviderList apl = new ProviderList();

        ProviderList prevAPL = cc.getCurrentAuxiliaryProviderList();
        cc.setCurrentAuxiliaryProviderList(apl);

        // Tell the compiler context to only allow deterministic nodes
        cc.setReliability( CompilerContext.CHECK_CONSTRAINT );
        checkTree = checkTree.bindExpression(fromList, (SubqueryList) null,
                     aggregateVector);

        // no aggregates, please
        if (aggregateVector.size() != 0)
        {
          throw StandardException.newException(SQLState.LANG_INVALID_CHECK_CONSTRAINT, cdn.getConstraintText());
        }
       
        checkTree = checkTree.checkIsBoolean();
        cdn.setCheckCondition(checkTree);

        /* Save the APL off in the constraint node */
        if (apl.size() > 0)
        {
          cdn.setAuxiliaryProviderList(apl);
        }

        // Restore the previous AuxiliaryProviderList
        cc.setCurrentAuxiliaryProviderList(prevAPL);
      }
      finally
      {
        cc.setReliability(previousReliability);
      }
 
      /* We have a valid check constraint, now build an array of
       * 1-based columnIds that the constraint references.
       */
 
View Full Code Here

    /* We need to bind the tables before we can bind the target list
     * (for exists subqueries).  However, we need to wait until after
     * any *'s have been replaced, so that they don't get expanded.
     */
    CompilerContext cc = getCompilerContext();

    resultSet = resultSet.bindNonVTITables(getDataDictionary(), fromList);
    resultSet = resultSet.bindVTITables(fromList);

    /* Set the subquery # for this SubqueryNode */
    if (subqueryNumber == -1)
      subqueryNumber = cc.getNextSubqueryNumber();

    /* reject ? parameters in the select list of subqueries */
    resultSet.rejectParameters();

    if (subqueryType == EXISTS_SUBQUERY)
View Full Code Here

  public void generateExpression(
                  ExpressionClassBuilder expressionBuilder,
                  MethodBuilder mbex)
                throws StandardException
  {
    CompilerContext  cc = getCompilerContext();
    String      resultSetString;

    ///////////////////////////////////////////////////////////////////////////
    //
    //  Subqueries should not appear in Filter expressions. We should get here
    //  only if we're compiling a query. That means that our class builder
    //  is an activation builder. If we ever allow subqueries in filters, we'll
    //  have to revisit this code.
    //
    ///////////////////////////////////////////////////////////////////////////
   
    if (SanityManager.DEBUG)
    {
      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
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.compile.CompilerContext

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.