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

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


   *
   * @exception StandardException    Thrown on error
   */
  public QueryTreeNode bind() throws StandardException
  {
    CompilerContext        cc = getCompilerContext();
    DataDictionary        dataDictionary = getDataDictionary();
    ResultColumnList      qeRCL;
    String            duplicateColName;

    // bind the query expression
View Full Code Here


    indexConglomerateNumbers = indexLister.getDistinctIndexConglomerateNumbers();
    indexNames = indexLister.getDistinctIndexNames();

    /* Add dependencies on all indexes in the list */
    ConglomerateDescriptor[]  cds = td.getConglomerateDescriptors();
    CompilerContext cc = getCompilerContext();

     for (int index = 0; index < cds.length; index++)
    {
      cc.createDependency(cds[index]);
    }
  }
View Full Code Here

    /*
    ** Get a new compiler context, so the parsing of the select statement
    ** doesn't mess up anything in the current context (it could clobber
    ** the ParameterValueSet, for example).
    */
    CompilerContext newCC = lcc.pushCompilerContext();

    p = newCC.getParser();

   
    /* Finally, we can call the parser */
    // Since this is always nested inside another SQL statement, so topLevel flag
    // should be false
View Full Code Here

   * @exception StandardException    Thrown on error
   */

  public void bindStatement() throws StandardException
  {
    CompilerContext      cc = getCompilerContext();

    td = getTableDescriptor();

    conglomerateNumber = td.getHeapConglomerateId();

    /* Get the base conglomerate descriptor */
    ConglomerateDescriptor cd = td.getConglomerateDescriptor(conglomerateNumber);

    /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
    cc.createDependency(td);
    cc.createDependency(cd);
  }
 
View Full Code Here

    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);
        }
 
        cvn = (CreateViewNode)
                  parseStatement(vd.getViewText(), false);

        rsn = cvn.getParsedQueryExpression();
 
        /* If the view contains a '*' then we mark the views derived column list
         * so that the view will still work, and return the expected results,
         * if any of the tables referenced in the view have columns added to
         * them via ALTER TABLE.  The expected results means that the view
         * will always return the same # of columns.
         */
        if (rsn.getResultColumns().containsAllResultColumn())
        {
          resultColumns.setCountMismatchAllowed(true);
        }
        //Views execute with definer's privileges and if any one of
        //those privileges' are revoked from the definer, the view gets
        //dropped. So, a view can exist in Derby only if it's owner has
        //all the privileges needed to create one. In order to do a
        //select from a view, a user only needs select privilege on the
        //view and doesn't need any privilege for objects accessed by
        //the view. Hence, when collecting privilege requirement for a
        //sql accessing a view, we only need to look for select privilege
        //on the actual view and that is what the following code is
        //checking.
        for (int i = 0; i < resultColumns.size(); i++) {
          ResultColumn rc = (ResultColumn) resultColumns.elementAt(i);
          if (rc.isPrivilegeCollectionRequired())
            compilerContext.addRequiredColumnPriv( rc.getTableColumnDescriptor());
        }

        fsq = (FromTable) getNodeFactory().getNode(
          C_NodeTypes.FROM_SUBQUERY,
          rsn,
          (correlationName != null) ?
                        correlationName : getOrigTableName().getTableName(),
          resultColumns,
          tableProperties,
          getContextManager());
        // Transfer the nesting level to the new FromSubquery
        fsq.setLevel(level);
        //We are getting ready to bind the query underneath the view. Since
        //that query is going to run with definer's privileges, we do not
        //need to collect any privilege requirement for that query.
        //Following call is marking the query to run with definer
        //privileges. This marking will make sure that we do not collect
        //any privilege requirement for it.
        fsq.disablePrivilegeCollection();
        fsq.setOrigTableName(this.getOrigTableName());
        return fsq.bindNonVTITables(dataDictionary, fromListParam);
      }
      finally
      {
        compilerContext.setCompilationSchema(prevCompSchema);
      }
    }
    else
    {
      /* This represents a table - query is dependent on the TableDescriptor */
      compilerContext.createDependency(tableDescriptor);

      /* Get the base conglomerate descriptor */
      baseConglomerateDescriptor =
        tableDescriptor.getConglomerateDescriptor(
          tableDescriptor.getHeapConglomerateId()
          );

      /* Build the 0-based array of base column names. */
      columnNames = resultColumns.getColumnNames();

      /* Do error checking on derived column list and update "exposed"
       * column names if valid.
       */
      if (derivedRCL != null)
      {
         resultColumns.propagateDCLInfo(derivedRCL,
                          origTableName.getFullTableName());
      }

      /* Assign the tableNumber */
      if (tableNumber == -1// allow re-bind, in which case use old number
        tableNumber = compilerContext.getNextTableNumber();
    }

    return this;
  }
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

   * @exception StandardException    Thrown on error
   */

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

    sd = getSchemaDescriptor();
View Full Code Here

    throws StandardException
  {
    Parser            p;
    ValueNode          checkTree;
    LanguageConnectionContext  lcc = getLanguageConnectionContext();
    CompilerContext       compilerContext = getCompilerContext();

    /* Get a Statement to pass to the parser */

    /* We're all set up to parse. We have to build a compile SQL statement
     * before we can parse - we just have a WHERE clause right now.
     * So, we goober up a SELECT * FROM table WHERE checkDefs.
     */
    String select = "SELECT * FROM " +
                  td.getQualifiedName() +
                  " WHERE " +
                  checkConstraintText;
   
    /*
    ** Get a new compiler context, so the parsing of the select statement
    ** doesn't mess up anything in the current context (it could clobber
    ** the ParameterValueSet, for example).
    */
    CompilerContext newCC = lcc.pushCompilerContext();

    p = newCC.getParser();
       
    /* Finally, we can call the parser */
    // Since this is always nested inside another SQL statement, so topLevel flag
    // should be false
    StatementNode qt = p.parseStatement(select);
View Full Code Here

    GenericDescriptorList     tdl,
    Dependent          dependent
  )
    throws StandardException
  {
    CompilerContext       compilerContext = getCompilerContext();

    Enumeration descs = tdl.elements();

    while (descs.hasMoreElements())
    {
      TriggerDescriptor td = (TriggerDescriptor)descs.nextElement();

      /*
      ** The dependent now depends on this trigger.
      ** the default dependent is the statement
      ** being compiled.
      */
      if (dependent == null)
      {
        compilerContext.createDependency(td);
      }
      else
      {
        compilerContext.createDependency(dependent, td);
      }
    }
  }
View Full Code Here

    ConstraintDescriptorList   cdl,
    Dependent          dependent
  )
    throws StandardException
  {
    CompilerContext       compilerContext = getCompilerContext();

    int cdlSize = cdl.size();
    for (int index = 0; index < cdlSize; index++)
    {
      ConstraintDescriptor cd = cdl.elementAt(index);

      /*
      ** The dependent now depends on this constraint.
      ** the default dependent is the statement
      ** being compiled.
      */
      if (dependent == null)
      {
        compilerContext.createDependency(cd);
      }
      else
      {
        compilerContext.createDependency(dependent, cd);
      }

      /*
      ** We are also dependent on all referencing keys --
      ** if one of them is deleted, we'll have to recompile.
      ** Also, if there is a BULK_INSERT on the table
      ** we are going to scan to validate the constraint,
      ** the index number will change, so we'll add a
      ** dependency on all tables we will scan.
      */
      if (cd instanceof ReferencedKeyConstraintDescriptor)
      { 
        ConstraintDescriptorList fkcdl = dd.getActiveConstraintDescriptors
          ( ((ReferencedKeyConstraintDescriptor)cd).getForeignKeyConstraints(ConstraintDescriptor.ENABLED) );
 
        int fklSize = fkcdl.size();
        for (int inner = 0; inner < fklSize; inner++)
        {
          ConstraintDescriptor fkcd = fkcdl.elementAt(inner);
          if (dependent == null)
          {
            compilerContext.createDependency(fkcd);
            compilerContext.createDependency(fkcd.getTableDescriptor());
          }
          else
          {
            compilerContext.createDependency(dependent, fkcd);
            compilerContext.createDependency(dependent, fkcd.getTableDescriptor());
          }
        }
      }
      else if (cd instanceof ForeignKeyConstraintDescriptor)
      {
        ForeignKeyConstraintDescriptor fkcd = (ForeignKeyConstraintDescriptor) cd;
        if (dependent == null)
        {
          compilerContext.createDependency(fkcd.getReferencedConstraint().getTableDescriptor());
        }
        else
        {
          compilerContext.createDependency(dependent,
                  fkcd.getReferencedConstraint().getTableDescriptor());
        }
      }
    }
  }
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.