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

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


        boolean                 forUpdate,
        ResultSetNode       updateResultSet
    )
    throws StandardException
  {
    CompilerContext       compilerContext = getCompilerContext();
        int  count = targetRCL.size();

        for ( int i = 0; i < count; i++ )
        {
            ResultColumn    rc = (ResultColumn) targetRCL.elementAt( i );

            //
            // For updates, there are two copies of the column in the row: a
            // before image and the actual value which will be set when we
            // update the row. We only want to compile a generation clause for
            // the value which will be updated.
            //
            if ( forUpdate && !rc.updated() ) { continue; }
           
            if ( rc.hasGenerationClause() )
            {
                ColumnDescriptor    colDesc = rc.getTableColumnDescriptor();
                DataTypeDescriptor  dtd = colDesc.getType();
                DefaultInfo             di = colDesc.getDefaultInfo();
                ValueNode   generationClause = parseGenerationClause( di.getDefaultText(), targetTableDescriptor );

                // insert CAST in case column data type is not same as the
                // resolved type of the generation clause
                generationClause = (ValueNode) getNodeFactory().getNode
                    (
                     C_NodeTypes.CAST_NODE,
                     generationClause,
                     dtd,
                     getContextManager()
                     );

                //
                // Unqualified function references should resolve to the
                // current schema at the time that the table was
                // created/altered. See DERBY-3945.
                //
                SchemaDescriptor    originalCurrentSchema = getSchemaDescriptor( di.getOriginalCurrentSchema(), true );
                compilerContext.pushCompilationSchema( originalCurrentSchema );

        try {
                    bindRowScopedExpression( getNodeFactory(), getContextManager(), targetTableDescriptor, sourceRCL, generationClause );
                }
                finally
                {
                    compilerContext.popCompilationSchema();
                }

                ResultColumn    newRC =  (ResultColumn) getNodeFactory().getNode
                    ( C_NodeTypes.RESULT_COLUMN, generationClause.getTypeServices(), generationClause, getContextManager());
View Full Code Here


    throws StandardException
  {
    Parser            p;
    ValueNode          clauseTree;
    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 compilable SQL statement
     * before we can parse -  So, we goober up a VALUES defaultText.
     */
    String select = "SELECT " + clauseText + " FROM " + td.getQualifiedName();
   
    /*
    ** 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

    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

    )
    throws StandardException
  {
    ConglomerateDescriptor  cd;
    int            indexCount = affectedConglomerates.size();
    CompilerContext      cc = getCompilerContext();

    indicesToMaintain = new IndexRowGenerator[ indexCount ];
    indexConglomerateNumbers = new long[ indexCount ];
    indexNames = new String[indexCount];

    for ( int ictr = 0; ictr < indexCount; ictr++ )
    {
      cd = (ConglomerateDescriptor) affectedConglomerates.elementAt( ictr );

      indicesToMaintain[ ictr ] = cd.getIndexDescriptor();
      indexConglomerateNumbers[ ictr ] = cd.getConglomerateNumber();
      indexNames[ictr] =
        ((cd.isConstraint()) ? null : cd.getConglomerateName());

      cc.createDependency(cd);
    }

  }
View Full Code Here

   * @exception StandardException    Thrown on error
   */

  public QueryTreeNode bind() 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);

    return this;
  }
View Full Code Here

    @exception StandardException current mode does not support statement
  */
        private void checkInternalFeature(String feature) throws StandardException
        {
                CompilerContext cc = getCompilerContext();
                if ((cc.getReliability() & CompilerContext.INTERNAL_SQL_ILLEGAL) != 0)
                        throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, feature);
        }
View Full Code Here

   @exception  StandardException
   */
         private void setUpAndLinkParameters()
                        throws StandardException
         {
                CompilerContext cc = getCompilerContext();
                cc.setParameterList(parameterList);
                /* Link the untyped parameters to the array of parameter descriptors */

                DataTypeDescriptor[] descriptors = cc.getParameterTypes();

                ParameterNode                           newNode;
                ParameterNode                           oldNode;
                int                                                     paramCount;

View Full Code Here

   *
   * @exception StandardException    Thrown on error
   */
  public QueryTreeNode bind() throws StandardException
  {
    CompilerContext      cc = getCompilerContext();
    DataDictionary      dd = getDataDictionary();
    SchemaDescriptor    sd;

    sd = getSchemaDescriptor();

    if (sd.getUUID() != null)
      cd = dd.getConglomerateDescriptor(getRelativeName(), sd, false);

    if (cd == null)
    {
      throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND, getFullName());
    }

    /* Get the table descriptor */
    td = getTableDescriptor(cd.getTableID());

    /* Drop index is not allowed on an index backing a constraint -
     * user must drop the constraint, which will drop the index.
     * Drop constraint drops the constraint before the index,
     * so it's okay to drop a backing index if we can't find its
     * ConstraintDescriptor.
     */
    if (cd.isConstraint())
    {
      ConstraintDescriptor conDesc;
      String constraintName;

      conDesc = dd.getConstraintDescriptor(td, cd.getUUID());
      if (conDesc != null)
      {
        constraintName = conDesc.getConstraintName();
        throw StandardException.newException(SQLState.LANG_CANT_DROP_BACKING_INDEX,
                    getFullName(), constraintName);
      }
    }

    /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
    cc.createDependency(td);
    cc.createDependency(cd);

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