Examples of CompilerContext


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

      // Here we get the trigger action sql and use the parser to build
      // the parse tree for it.
      SchemaDescriptor compSchema;
      compSchema = dd.getSchemaDescriptor(trd.getSchemaDescriptor().getUUID(), null);
      CompilerContext newCC = lcc.pushCompilerContext(compSchema);
      Parser  pa = newCC.getParser();
      StatementNode stmtnode = (StatementNode)pa.parseStatement(trd.getTriggerDefinition());
      lcc.popCompilerContext(newCC);
      // Do not delete following. We use this in finally clause to
      // determine if the CompilerContext needs to be popped.
      newCC = null;
     
      try {
        // We are interested in ColumnReference classes in the parse tree
        CollectNodesVisitor visitor = new CollectNodesVisitor(ColumnReference.class);
        stmtnode.accept(visitor);
        Vector refs = visitor.getList();
       
        // Regenerate the internal representation for the trigger action
        // sql using the ColumnReference classes in the parse tree. It
        // will catch dropped column getting used in trigger action sql
        // through the REFERENCING clause(this can happen only for the
        // the triggers created prior to 10.7. Trigger created with
        // 10.7 and higher keep track of trigger action column used
        // through the REFERENCING clause in system table and hence
        // use of dropped column will be detected earlier in this
        // method for such triggers).
        //
        // We might catch errors like following during this step.
        // Say that following pre-10.7 trigger exists in the system and
        // user is dropping column c11. During the regeneration of the
        // internal trigger action sql format, we will catch that
        // column oldt.c11 does not exist anymore
        // CREATE TRIGGER DERBY4998_SOFT_UPGRADE_RESTRICT_tr1
        //    AFTER UPDATE OF c12
        //    ON DERBY4998_SOFT_UPGRADE_RESTRICT REFERENCING OLD AS oldt
        //    FOR EACH ROW
        //    SELECT oldt.c11 from DERBY4998_SOFT_UPGRADE_RESTRICT

        SPSDescriptor triggerActionSPSD = trd.getActionSPS(lcc);
        int[] referencedColsInTriggerAction = new int[td.getNumberOfColumns()];
        java.util.Arrays.fill(referencedColsInTriggerAction, -1);
        triggerActionSPSD.setText(dd.getTriggerActionString(stmtnode,
          trd.getOldReferencingName(),
          trd.getNewReferencingName(),
          trd.getTriggerDefinition(),
          trd.getReferencedCols(),
          referencedColsInTriggerAction,
          0,
          trd.getTableDescriptor(),
          trd.getTriggerEventMask(),
          true
          ));
       
        // Now that we have the internal format of the trigger action sql,
        // bind that sql to make sure that we are not using colunm being
        // dropped in the trigger action sql directly (ie not through
        // REFERENCING clause.
        // eg
        // create table atdc_12 (a integer, b integer);
        // create trigger atdc_12_trigger_1 after update of a
        //     on atdc_12 for each row select a,b from atdc_12
        // Drop one of the columns used in the trigger action
        //   alter table atdc_12 drop column b
        // Following rebinding of the trigger action sql will catch the use
        // of column b in trigger atdc_12_trigger_1
        compSchema = dd.getSchemaDescriptor(trd.getSchemaDescriptor().getUUID(), null);
        newCC = lcc.pushCompilerContext(compSchema);
          newCC.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);
        pa = newCC.getParser();
        stmtnode = (StatementNode)pa.parseStatement(triggerActionSPSD.getText());
        // need a current dependent for bind
        newCC.setCurrentDependent(triggerActionSPSD.getPreparedStatement());
        stmtnode.bindStatement();
        //Register the dependency between trigger table and trigger
        // action SPS
        dm.addDependency(triggerActionSPSD, td, lcc.getContextManager());
      } catch (StandardException se)
View Full Code Here

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

            if (dep instanceof ViewDescriptor)
            {
              ViewDescriptor vd = (ViewDescriptor) dep;
              SchemaDescriptor compSchema;
              compSchema = dd.getSchemaDescriptor(vd.getCompSchemaId(), null);
              CompilerContext newCC = lcc.pushCompilerContext(compSchema);
              Parser  pa = newCC.getParser();

              // Since this is always nested inside another SQL
              // statement, so topLevel flag should be false
              CreateViewNode cvn = (CreateViewNode)pa.parseStatement(
                        vd.getViewText());

              // need a current dependent for bind
              newCC.setCurrentDependent(dep);
              cvn.bindStatement();
              ProviderInfo[] providerInfos = cvn.getProviderInfo();
              lcc.popCompilerContext(newCC);

              boolean    interferent = false;
View Full Code Here

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

    throws StandardException
  {
    Parser            p;
    ValueNode          defaultTree;
    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 values = "VALUES " + defaultText;
   
    /*
    ** 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(values);
View Full Code Here

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

     * The compiler context's compilation schema will be set accordingly based
     * on the given input above.  
     */
    public  CompilerContext pushCompilerContext(SchemaDescriptor sd)
    {
        CompilerContext cc;
        boolean         firstCompilerContext = false;

        //  DEBUG   END

        cc = (CompilerContext) (getContextManager().getContext(CompilerContext.CONTEXT_ID));

        /*
        ** If there is no compiler context, this is the first one on the
        ** stack, so don't pop it when we're done (saves time).
        */
        if (cc == null) { firstCompilerContext = true; }

        if (cc == null || cc.getInUse())
        {
            cc = new CompilerContextImpl(getContextManager(), this, tcf);
            if (firstCompilerContext) { cc.firstOnStack(); }
        }
        else
        {
            /* Reset the next column,table, subquery and ResultSet numbers at
            * the beginning of each statement
            */
            cc.resetContext();
        }

        cc.setInUse(true);

        StatementContext sc = getStatementContext();
        if (sc.getSystemCode())
            cc.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);

        /*
         * Set the compilation schema when its UUID is available.
         * i.e.:  Schema may not have been physically created yet, so
         *        its UUID will be null.
         *
         * o For trigger SPS recompilation, the system must use its
         *   compilation schema to recompile the statement.
         *
         * o For view recompilation, we set the compilation schema
         *   for this compiler context if its UUID is available.
         *   Otherwise, the compilation schema will be determined
         *   at execution time of view creation.
         */
        if (sd != null && sd.getUUID() != null)
        {
            cc.setCompilationSchema(sd);
        }
       
        return  cc;
    }
View Full Code Here

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

      orderByList.pullUpOrderByColumns(subquery);
    }

    nestedFromList = emptyFromList;

    CompilerContext compilerContext = getCompilerContext();

    if (origCompilationSchema != null) {
      // View expansion needs the definition time schema
      compilerContext.pushCompilationSchema(origCompilationSchema);
    }

    try {
      subquery.bindExpressions(nestedFromList);
      subquery.bindResultColumns(nestedFromList);
    } finally {
      if (origCompilationSchema != null) {
        compilerContext.popCompilationSchema();
      }
    }

    if (orderByList != null) {
      orderByList.bindOrderByColumns(subquery);
View Full Code Here

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

      ** RESOLVE: we may ultimately wish to pass in
      ** whether we are a jdbc metadata query or not to
      ** get the CompilerContext to make the createDependency()
      ** call a noop.
      */
      CompilerContext cc = lcc.pushCompilerContext(compilationSchema);
     
      if (prepareIsolationLevel !=
        ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL)
      {
        cc.setScanIsolationLevel(prepareIsolationLevel);
      }


      // Look for stored statements that are in a system schema
      // and with a match compilation schema. If so, allow them
      // to compile using internal SQL constructs.

      if (internalSQL ||
        (spsSchema != null) && (spsSchema.isSystemSchema()) &&
          (spsSchema.equals(compilationSchema))) {
            cc.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);
      }

      try
      {
        // Statement logging if lcc.getLogStatementText() is true
        if (istream != null)
        {
          String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
          istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                        xactId +
                        "), " +
                        LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                        "), " +
                        LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                        "), " +
                        LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                        "), Begin compiling prepared statement: " +
                        getSource() +
                        " :End prepared statement");
        }

        Parser p = cc.getParser();

        cc.setCurrentDependent(preparedStmt);

        //Only top level statements go through here, nested statement
        //will invoke this method from other places
        StatementNode qt = p.parseStatement(statementText, paramDefaults);

        parseTime = getCurrentTimeMillis(lcc);

        if (SanityManager.DEBUG)
        {
          if (SanityManager.DEBUG_ON("DumpParseTree"))
          {
            qt.treePrint();
          }

          if (SanityManager.DEBUG_ON("StopAfterParsing"))
          {
            throw StandardException.newException(SQLState.LANG_STOP_AFTER_PARSING);
          }
        }

        /*
        ** Tell the data dictionary that we are about to do
        ** a bunch of "get" operations that must be consistent with
        ** each other.
        */
       
        DataDictionary dataDictionary = lcc.getDataDictionary();

        int ddMode = dataDictionary == null ? 0 : dataDictionary.startReading(lcc);

        try
        {
          // start a nested transaction -- all locks acquired by bind
          // and optimize will be released when we end the nested
          // transaction.
          lcc.beginNestedTransaction(true);

          qt.bindStatement();
          bindTime = getCurrentTimeMillis(lcc);

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("DumpBindTree"))
            {
              qt.treePrint();
            }

            if (SanityManager.DEBUG_ON("StopAfterBinding")) {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_BINDING);
            }
          }

          //Derby424 - In order to avoid caching select statements referencing
          // any SESSION schema objects (including statements referencing views
          // in SESSION schema), we need to do the SESSION schema object check
          // here. 
          //a specific eg for statement referencing a view in SESSION schema
          //CREATE TABLE t28A (c28 int)
          //INSERT INTO t28A VALUES (280),(281)
          //CREATE VIEW SESSION.t28v1 as select * from t28A
          //SELECT * from SESSION.t28v1 should show contents of view and we
          // should not cache this statement because a user can later define
          // a global temporary table with the same name as the view name.
          //Following demonstrates that
          //DECLARE GLOBAL TEMPORARY TABLE SESSION.t28v1(c21 int, c22 int) not
          //     logged
          //INSERT INTO SESSION.t28v1 VALUES (280,1),(281,2)
          //SELECT * from SESSION.t28v1 should show contents of global temporary
          //table and not the view.  Since this select statement was not cached
          // earlier, it will be compiled again and will go to global temporary
          // table to fetch data. This plan will not be cached either because
          // select statement is using SESSION schema object.
          //
          //Following if statement makes sure that if the statement is
          // referencing SESSION schema objects, then we do not want to cache it.
          // We will remove the entry that was made into the cache for
          //this statement at the beginning of the compile phase.
          //The reason we do this check here rather than later in the compile
          // phase is because for a view, later on, we loose the information that
          // it was referencing SESSION schema because the reference
          //view gets replaced with the actual view definition. Right after
          // binding, we still have the information on the view and that is why
          // we do the check here.
          if (preparedStmt.referencesSessionSchema(qt)) {
            if (foundInCache)
              ((GenericLanguageConnectionContext)lcc).removeStatement(this);
          }
         
          qt.optimizeStatement();

          optimizeTime = getCurrentTimeMillis(lcc);

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), End compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
        }

        catch (StandardException se)
        {
          lcc.commitNestedTransaction();

          // Statement logging if lcc.getLogStatementText() is true
          if (istream != null)
          {
            String xactId = lcc.getTransactionExecute().getActiveStateTxIdString();
            istream.printlnWithHeader(LanguageConnectionContext.xidStr +
                          xactId +
                          "), " +
                          LanguageConnectionContext.lccStr +
                          lcc.getInstanceNumber() +
                          "), " +
                          LanguageConnectionContext.dbnameStr +
                          lcc.getDbname() +
                          "), " +
                          LanguageConnectionContext.drdaStr +
                          lcc.getDrdaID() +
                          "), Error compiling prepared statement: " +
                          getSource() +
                          " :End prepared statement");
          }
          throw se;
        }

        finally
        {
          /* Tell the data dictionary that we are done reading */
          if (dataDictionary != null)
          dataDictionary.doneReading(ddMode, lcc);
        }

        /* we need to move the commit of nested sub-transaction
         * after we mark PS valid, during compilation, we might need
         * to get some lock to synchronize with another thread's DDL
         * execution, in particular, the compilation of insert/update/
         * delete vs. create index/constraint (see Beetle 3976).  We
         * can't release such lock until after we mark the PS valid.
         * Otherwise we would just erase the DDL's invalidation when
         * we mark it valid.
         */
        try    // put in try block, commit sub-transaction if bad
        {
          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("DumpOptimizedTree"))
            {
              qt.treePrint();
            }

            if (SanityManager.DEBUG_ON("StopAfterOptimizing"))
            {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_OPTIMIZING);
            }
          }

          GeneratedClass ac = qt.generate(preparedStmt.getByteCodeSaver());

          generateTime = getCurrentTimeMillis(lcc);
          /* endTimestamp only meaningful if generateTime is meaningful.
           * generateTime is meaningful if STATISTICS TIMING is ON.
           */
          if (generateTime != 0)
          {
            endTimestamp = new Timestamp(generateTime);
          }

          if (SanityManager.DEBUG)
          {
            if (SanityManager.DEBUG_ON("StopAfterGenerating"))
            {
              throw StandardException.newException(SQLState.LANG_STOP_AFTER_GENERATING);
            }
          }

          /*
            copy over the compile-time created objects
            to the prepared statement.  This always happens
            at the end of a compile, so there is no need
            to erase the previous entries on a re-compile --
            this erases as it replaces.  Set the activation
            class in case it came from a StorablePreparedStatement
          */
          preparedStmt.setConstantAction( qt.makeConstantAction() );
          preparedStmt.setSavedObjects( cc.getSavedObjects() );
          preparedStmt.setRequiredPermissionsList(cc.getRequiredPermissionsList());
          preparedStmt.setActivationClass(ac);
          preparedStmt.setNeedsSavepoint(qt.needsSavepoint());
          preparedStmt.setCursorInfo((CursorInfo)cc.getCursorInfo());
          preparedStmt.setIsAtomic(qt.isAtomic());
          preparedStmt.setExecuteStatementNameAndSchema(
                        qt.executeStatementName(),
                        qt.executeSchemaName()
                        );
          preparedStmt.setSPSName(qt.getSPSName());
          preparedStmt.completeCompile(qt);
          preparedStmt.setCompileTimeWarnings(cc.getWarnings());
        }
        catch (StandardException e)   // hold it, throw it
        {
          lcc.commitNestedTransaction();
          throw e;
View Full Code Here

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

         (actionSPS.getPreparedStatement() == null)) &&
         isRow && (referencingOld || referencingNew))
    {
      SchemaDescriptor compSchema;
      compSchema = getDataDictionary().getSchemaDescriptor(triggerSchemaId, null);
      CompilerContext newCC = lcc.pushCompilerContext(compSchema);
      Parser  pa = newCC.getParser();
      StatementNode stmtnode = (StatementNode)pa.parseStatement(triggerDefinition);
      lcc.popCompilerContext(newCC);
         
      actionSPS.setText(getDataDictionary().getTriggerActionString(stmtnode,
          oldReferencingName,
View Full Code Here

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

    }
   
   
    //Judged as default value is constant value.
   
    CompilerContext cc = getCompilerContext();

    ValueNode defaultTree = defaultNode.getDefaultTree();

    /* bind the default.
     * Verify that it does not contain any ColumnReferences or subqueries
     * and that it is type compatable with the column.
     */
    final int previousReliability = cc.getReliability();
    try
    {
      /*
        Defaults cannot have dependencies as they
        should just be constants. Code used to exist
        to handle dependencies in defaults, now this
        is under sanity to ensure no dependencies exist.
       */
      ProviderList apl = null;
      ProviderList prevAPL = null;

      if (SanityManager.DEBUG) {
        apl = new ProviderList();
        prevAPL = cc.getCurrentAuxiliaryProviderList();
        cc.setCurrentAuxiliaryProviderList(apl);
      }
     
      // Tell the compiler context to only allow deterministic nodes
      cc.setReliability( CompilerContext.DEFAULT_RESTRICTION );
      defaultTree = defaultTree.bindExpression(
              (FromList) getNodeFactory().getNode(
                C_NodeTypes.FROM_LIST,
                getNodeFactory().doJoinOrderOptimization(),
                getContextManager()),
              (SubqueryList) null,
              (Vector) null);

      TypeId columnTypeId = getType().getTypeId();
      TypeId defaultTypeId = defaultTree.getTypeId();

      // Check for 'invalid default' errors (42894)
      // before checking for 'not storable' errors (42821).
      if (!defaultTypeIsValid(columnTypeId, getType(),
          defaultTypeId, defaultTree, defaultNode.getDefaultText()))
      {
          throw StandardException.newException(
            SQLState.LANG_DB2_INVALID_DEFAULT_VALUE,
            this.name);
      }

      // Now check 'not storable' errors.
      if (! getTypeCompiler(columnTypeId).
                storable(defaultTypeId, getClassFactory()))
      {
        throw StandardException.newException(SQLState.LANG_NOT_STORABLE,
          columnTypeId.getSQLTypeName(),
          defaultTypeId.getSQLTypeName() );
      }

      // Save off the default text
      // RESOLVEDEFAULT - Convert to constant if possible
      defaultInfo = new DefaultInfoImpl(false,
                defaultNode.getDefaultText(),
                defaultValue);

      if (SanityManager.DEBUG)
      {
        /* Save the APL off in the constraint node */
        if (apl.size() > 0)
        {

          SanityManager.THROWASSERT("DEFAULT clause has unexpected dependencies");
        }
        // Restore the previous AuxiliaryProviderList
        cc.setCurrentAuxiliaryProviderList(prevAPL);
      }

    }
    finally
    {
      cc.setReliability(previousReliability);
    }
  }
View Full Code Here

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

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

    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
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.