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

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


  {
    DataDictionary dd = getDataDictionary();
    String nextSynonymTable = tabName.getTableName();
    String nextSynonymSchema = tabName.getSchemaName();
    boolean found = false;
    CompilerContext cc = getCompilerContext();

    // Circular synonym references should have been detected at the DDL time, so
    // the following loop shouldn't loop forever.
    for (;;)
    {
      SchemaDescriptor nextSD = getSchemaDescriptor(nextSynonymSchema, false);
      if (nextSD == null || nextSD.getUUID() == null)
        break;
 
      AliasDescriptor nextAD = dd.getAliasDescriptor(nextSD.getUUID().toString(),
             nextSynonymTable, AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR);
      if (nextAD == null)
        break;

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

      found = true;
      SynonymAliasInfo info = ((SynonymAliasInfo)nextAD.getAliasInfo());
      nextSynonymTable = info.getSynonymTable();
      nextSynonymSchema = info.getSynonymSchema();
View Full Code Here


  {
    String schemaName = objectName.getSchemaName();
    //boolean needError = !(implicitCreateSchema || (schemaName == null));
    boolean needError = !implicitCreateSchema;
    SchemaDescriptor sd = getSchemaDescriptor(schemaName, needError);
    CompilerContext cc = getCompilerContext();

    if (sd == null) {
      /* Disable creating schemas starting with SYS */
      if (schemaName.startsWith("SYS"))
        throw StandardException.newException(
          SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA,
          statementToString(),
          schemaName);

      sd  = new SchemaDescriptor(getDataDictionary(), schemaName,
        (String) null, (UUID)null, false);

      if (isPrivilegeCollectionRequired())
        cc.addRequiredSchemaPriv(schemaName, null, Authorizer.CREATE_SCHEMA_PRIV);
    }

    if (ownerCheck && isPrivilegeCollectionRequired())
      cc.addRequiredSchemaPriv(sd.getSchemaName(), null,
            Authorizer.MODIFY_SCHEMA_PRIV);

    /*
    ** Catch the system schema here.
    */  
View Full Code Here

   *
   * @exception StandardException    Thrown on error
   */
  public void bindStatement() 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

     * 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    Thrown on error
   */

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

    sd = getSchemaDescriptor();
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

    */
 
  public void bindStatement() 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);
    }
  }
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

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.