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

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


        ContextService.getContext(LanguageConnectionContext.CONTEXT_ID);

      DataTypeDescriptor dts = new DataTypeDescriptor( (DataTypeDescriptor)inputType, inputType.isNullable());
      TypeId compType = dts.getTypeId();
   
      CompilerContext cc = (CompilerContext)
        ContextService.getContext(CompilerContext.CONTEXT_ID);
      TypeCompilerFactory tcf = cc.getTypeCompilerFactory();
      TypeCompiler tc = tcf.getTypeCompiler(compType);
   
      /*
      ** If the class implements NumberDataValue, then we
      ** are in business.  Return type is same as input
View Full Code Here


    }
   
   
    //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 = (TypeId) dataTypeServices.getTypeId();
      TypeId defaultTypeId = defaultTree.getTypeId();

      // Check for 'invalid default' errors (42894)
      // before checking for 'not storable' errors (42821).
      if (!defaultTypeIsValid(columnTypeId, dataTypeServices,
          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

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

    // Save off the current isolation level on entry so that it gets restored
    cc.setEntryIsolationLevel( getCurrentIsolationLevel());

    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

     * 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

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

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

            // The field methodName is used by resolveRoutine and
            // is set to the name of the routine (procedureName.getTableName()).
      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 routine found */
      if (ad == null)
      {
        throw StandardException.newException(
                        SQLState.LANG_NO_SUCH_METHOD_ALIAS, procedureName);
      }
 


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


      methodName = ad.getAliasInfo().getMethodName();
      javaClassName = ad.getJavaClassName();
           
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 void bindStatement() 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.bindStatement();

      /* when clause is always null
      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

    /*
    ** Get a new compiler context, so the parsing of the text
    ** doesn't mess up anything in the current context
    */
    LanguageConnectionContext lcc = getLanguageConnectionContext();
    CompilerContext newCC = lcc.pushCompilerContext();
    if (internalSQL)
        newCC.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);

    try
    {
      Parser p = newCC.getParser();
      return p.parseStatement(sql);
    }

    finally
    {
View Full Code Here

    SchemaDescriptor sd = null;
    boolean isCurrent = false;
    boolean isCompilation = false;
    if (schemaName == null) {

      CompilerContext cc = getCompilerContext();
      sd = cc.getCompilationSchema();

      if (sd == null) {
        // Set the compilation schema to be the default,
        // notes that this query has schema dependencies.
        sd = getLanguageConnectionContext().getDefaultSchema();

        isCurrent = true;

        cc.setCompilationSchema(sd);
      }
      else
      {
        isCompilation = true;
      }
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.