Package org.apache.derby.iapi.sql.dictionary

Examples of org.apache.derby.iapi.sql.dictionary.TableDescriptor


    SystemColumn    theColumn;
    SystemColumn[]    columns = rowFactory.buildColumnList();
    SchemaDescriptor  sd = getSystemSchemaDescriptor();
    String columnName;

    TableDescriptor td = getTableDescriptor(rowFactory.getCatalogName(), sd);

    theColumn = columns[columnNumber - 1]// from 1 to 0 based
    ColumnDescriptor cd = makeColumnDescriptor(theColumn, columnNumber, td );
    columnName = cd.getColumnName();
    cd.getType().setNullability(nullability);
    int[] columnNameColArray = new int[1];
    columnNameColArray[0] = SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMNDATATYPE ;
    updateColumnDescriptor(cd,
                td.getUUID(),
                columnName,
                columnNameColArray,
                tc,
                true);
View Full Code Here


    SystemColumn[]    columns = rowFactory.buildColumnList();
    ExecRow        templateRow = rowFactory.makeEmptyRow();
    int          columnCount = newColumnIDs.length;
    SchemaDescriptor  sd = getSystemSchemaDescriptor();
    TableDescriptor    td;
    long        conglomID;

    // Special case when adding a column to systables or syscolumns,
    // since we can't go to systables/syscolumns to get the
    // table/column descriptor until after we add and populate the new column.
    if (rowFactory instanceof SYSTABLESRowFactory)
    {
      td = dataDescriptorGenerator.newTableDescriptor(
            "SYSTABLES",
            sd,
            TableDescriptor.BASE_TABLE_TYPE,
            TableDescriptor.ROW_LOCK_GRANULARITY);
      td.setUUID(getUUIDForCoreTable("SYSTABLES", sd.getUUID().toString(), tc));
      conglomID = coreInfo[SYSTABLES_CORE_NUM].getHeapConglomerate();
    }
    else if (rowFactory instanceof SYSCOLUMNSRowFactory)
    {
      td = dataDescriptorGenerator.newTableDescriptor(
            "SYSCOLUMNS",
            sd,
            TableDescriptor.BASE_TABLE_TYPE,
            TableDescriptor.ROW_LOCK_GRANULARITY);
      td.setUUID(getUUIDForCoreTable("SYSCOLUMNS", sd.getUUID().toString(), tc));
      conglomID = coreInfo[SYSCOLUMNS_CORE_NUM].getHeapConglomerate();
    }
    else
    {
      td = getTableDescriptor( rowFactory.getCatalogName(), sd );
      conglomID = td.getHeapConglomerateId();
    }

    widenConglomerate( templateRow, newColumnIDs, conglomID, tc );

View Full Code Here

    String        name = ti.getTableName();
    long        conglomId = ti.getHeapConglomerate();
    SystemColumn[]    columnList = crf.buildColumnList();
    UUID        heapUUID = crf.getCanonicalHeapUUID();
    String        heapName = crf.getCanonicalHeapName();
    TableDescriptor    td;
    UUID        toid;
    ColumnDescriptor  cd;
    int          columnCount;
    SystemColumn    column;

    // add table to the data dictionary

    columnCount = columnList.length;
    td = ddg.newTableDescriptor(name, sd, TableDescriptor.SYSTEM_TABLE_TYPE,
                    TableDescriptor.ROW_LOCK_GRANULARITY);
    td.setUUID(crf.getCanonicalTableUUID());
    addDescriptor(td, sd, SYSTABLES_CATALOG_NUM,
            false, tc);
    toid = td.getUUID();
 
    /* Add the conglomerate for the heap */
    ConglomerateDescriptor cgd = ddg.newConglomerateDescriptor(conglomId,
                                  heapName,
                                  false,
                                  null,
                                  false,
                                  heapUUID,
                                    toid,
                                  sd.getUUID());

    addDescriptor(cgd, sd, SYSCONGLOMERATES_CATALOG_NUM, false, tc);

    /* Create the columns */
    ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnCount];

    for (int columnNumber = 0; columnNumber < columnCount; columnNumber++)
    {
      column = columnList[columnNumber];

      if (SanityManager.DEBUG)
      {
        if (column == null)
        {
          SanityManager.THROWASSERT("column "+columnNumber+" for table "+ti.getTableName()+" is null");
        }
      }
      cdlArray[columnNumber] = makeColumnDescriptor( column,
                    columnNumber + 1, td );
    }
    addDescriptorArray(cdlArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc);
   
    // now add the columns to the cdl of the table.
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    for (int i = 0; i < columnCount; i++)
      cdl.add(cdlArray[i]);
  }
View Full Code Here

      if (ti.isComplete())
      {
        return;
      }

      TableDescriptor td = getTableDescriptor(ti.getTableName(),
                          getSystemSchemaDescriptor());

      // It's possible that the system table is not there right
      // now. This can happen, for example, if we're in the
      // process of upgrading a source or target to Xena, in
      // which case SYSSYNCINSTANTS is dropped and re-created.
      // Just return in this case, so we don't get a null pointer
      // exception.
      if (td == null)
      {
        return;
      }

      ConglomerateDescriptor cd = null;
      ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();

      /* Init the heap conglomerate here */
      for (int index = 0; index < cds.length; index++)
      {
        cd = cds[index];
View Full Code Here

    }

    DataValueDescriptor  col;
    ConglomerateDescriptor conglomDesc;
    DataDescriptorGenerator ddg;
    TableDescriptor    td = null;
    int          constraintIType = -1;
    int[]        keyColumns = null;
    UUID        constraintUUID;
    UUID        schemaUUID;
    UUID        tableUUID;
    UUID        referencedConstraintId = null;
    SchemaDescriptor  schema;
    String        tableUUIDString;
    String        constraintName;
    String        constraintSType;
    String        constraintStateStr;
    boolean        constraintEnabled;
    int          referenceCount;
    String        constraintUUIDString;
    String        schemaUUIDString;
    SubConstraintDescriptor scd;

    if (SanityManager.DEBUG)
    {
      if (!(parentTupleDescriptor instanceof SubConstraintDescriptor))
      {
        SanityManager.THROWASSERT(
          "parentTupleDescriptor expected to be instanceof " +
          "SubConstraintDescriptor, not " +
          parentTupleDescriptor.getClass().getName());
      }
    }

    scd = (SubConstraintDescriptor) parentTupleDescriptor;

    ddg = dd.getDataDescriptorGenerator();

    /* 1st column is CONSTRAINTID (UUID - char(36)) */
    col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTID);
    constraintUUIDString = col.getString();
    constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);

    /* 2nd column is TABLEID (UUID - char(36)) */
    col = row.getColumn(SYSCONSTRAINTS_TABLEID);
    tableUUIDString = col.getString();
    tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);

    /* Get the TableDescriptor. 
     * It may be cached in the SCD,
     * otherwise we need to go to the
     * DD.
     */
    if (scd != null)
    {
      td = scd.getTableDescriptor();
    }
    if (td == null)
    {
      td = dd.getTableDescriptor(tableUUID);
    }

    /* 3rd column is NAME (varchar(128)) */
    col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTNAME);
    constraintName = col.getString();

    /* 4th column is TYPE (char(1)) */
    col = row.getColumn(SYSCONSTRAINTS_TYPE);
    constraintSType = col.getString();
    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT(constraintSType.length() == 1,
        "Fourth column type incorrect");
    }

    boolean typeSet = false;
    switch (constraintSType.charAt(0))
    {
      case 'P' :
        constraintIType = DataDictionary.PRIMARYKEY_CONSTRAINT;
        typeSet = true;
        // fall through

      case 'U' :
        if (! typeSet)
        {
          constraintIType = DataDictionary.UNIQUE_CONSTRAINT;
          typeSet = true;
        }
        // fall through

      case 'F' :
        if (! typeSet)
          constraintIType = DataDictionary.FOREIGNKEY_CONSTRAINT;
        if (SanityManager.DEBUG)
        {
          if (!(parentTupleDescriptor instanceof SubKeyConstraintDescriptor))
          {
            SanityManager.THROWASSERT(
            "parentTupleDescriptor expected to be instanceof " +
            "SubKeyConstraintDescriptor, not " +
            parentTupleDescriptor.getClass().getName());
          }
        }
        conglomDesc = td.getConglomerateDescriptor(
                    ((SubKeyConstraintDescriptor)
                      parentTupleDescriptor).getIndexId());
        /* Take care the rare case of conglomDesc being null.  The
         * reason is that our "td" is out of date.  Another thread
         * which was adding a constraint committed between the moment
         * we got the table descriptor (conglomerate list) and the
         * moment we scanned and got the constraint desc list.  Since
         * that thread just added a new row to SYSCONGLOMERATES,
         * SYSCONSTRAINTS, etc.  We wouldn't have wanted to lock the
         * system tables just to prevent other threads from adding new
         * rows.
         */
        if (conglomDesc == null)
        {
          // we can't be getting td from cache because if we are
          // here, we must have been in dd's ddl mode (that's why
          // the ddl thread went through), we are not done yet, the
          // dd ref count is not 0, hence it couldn't have turned
          // into COMPILE_ONLY mode
          td = dd.getTableDescriptor(tableUUID);
          if (scd != null)
            scd.setTableDescriptor(td);
          // try again now
          conglomDesc = td.getConglomerateDescriptor(
                  ((SubKeyConstraintDescriptor)
                    parentTupleDescriptor).getIndexId());
        }

        if (SanityManager.DEBUG)
View Full Code Here

    try
        {
            DataDictionary data_dictionary = lcc.getDataDictionary();
            SchemaDescriptor sd =
                data_dictionary.getSchemaDescriptor(schema, tc, true);
            TableDescriptor  td =
                data_dictionary.getTableDescriptor(tablename, sd, tc);

            if (td != null && td.getTableType() == TableDescriptor.VTI_TYPE)
            {
                return;
            }
        }
    catch (StandardException se)
View Full Code Here

         * table name for the error message.  All we have
         * is the conglomerate number to work with.
         */
        DataDictionary dd = activation.getLanguageConnectionContext().getDataDictionary();
        ConglomerateDescriptor cd = dd.getConglomerateDescriptor( heapConglom );
        TableDescriptor td = dd.getTableDescriptor(cd.getTableID());

        StandardException se = StandardException.newException(SQLState.LANG_CHECK_CONSTRAINT_VIOLATED,
          td.getQualifiedName(), checkName);

        throw se;
      }
    }

View Full Code Here

        fkNames = new String[size];
        conglomNumbers = new long[size];
        isSelfReferencingFK = new boolean[size];
        raRules = new int[size];
        ForeignKeyConstraintDescriptor fkcd = null;
        TableDescriptor fktd;
        ColumnDescriptorList coldl;
        int[] refColumns;
        ColumnDescriptor cold;
        int[] colArray = remapReferencedColumns(cd, rowMap);
        for (int inner = 0; inner < size; inner++)
        {
          fkcd = (ForeignKeyConstraintDescriptor) fkcdl.elementAt(inner);
          fkSetupArrays(dd, fkcd,
                inner, uuids, conglomNumbers, fkNames,
                isSelfReferencingFK, raRules);
          if((raRules[inner] == StatementType.RA_CASCADE) ||
             (raRules[inner] ==StatementType.RA_SETNULL))
          {
            //find  the referencing  table Name
            fktd = fkcd.getTableDescriptor();
            refTableNames.addElement(fktd.getSchemaName() + "." + fktd.getName());
            refActions.addElement(new Integer(raRules[inner]));
            //find the referencing column name required for update null.
            refColumns = fkcd.getReferencedColumns();
            coldl = fktd.getColumnDescriptorList();
            ColumnDescriptorList releventColDes = new ColumnDescriptorList();
            for(int i = 0 ; i < refColumns.length; i++)
            {
              cold =(ColumnDescriptor)coldl.elementAt(refColumns[i]-1);
              releventColDes.add(cold);
            }
            refColDescriptors.addElement(releventColDes);
            refIndexConglomNum.addElement(new Long(conglomNumbers[inner]));
            fkColMap.addElement(colArray);
          }
        }
      }
      else
      {
        continue;
      }

      TableDescriptor  pktd = refcd.getTableDescriptor();
      UUID pkuuid = refcd.getIndexId();
      ConglomerateDescriptor pkIndexConglom = pktd.getConglomerateDescriptor(pkuuid);

      TableDescriptor refTd = cd.getTableDescriptor();
      fkVector.addElement(new FKInfo(
                  fkNames,              // foreign key names
                  refTd.getName(),        // table being modified
                  statementType,            // INSERT|UPDATE|DELETE
                  type,                // FOREIGN_KEY|REFERENCED_KEY
                  pkuuid,                // referenced backing index uuid
                  pkIndexConglom.getConglomerateNumber(), // referened backing index conglom
                  uuids,                // fk backing index uuids
View Full Code Here

        fkNames = new String[size];
        conglomNumbers = new long[size];
        isSelfReferencingFK = new boolean[size];
        raRules = new int[size];
        ForeignKeyConstraintDescriptor fkcd = null;
        TableDescriptor fktd;
        ColumnDescriptorList coldl;
        int[] refColumns;
        ColumnDescriptor cold;
        int[] colArray = remapReferencedColumns(cd, rowMap);
        for (int inner = 0; inner < size; inner++)
        {
          fkcd = (ForeignKeyConstraintDescriptor) fkcdl.elementAt(inner);
          fkSetupArrays(dd, fkcd,
                inner, uuids, conglomNumbers, fkNames,
                isSelfReferencingFK, raRules);
          if((raRules[inner] == StatementType.RA_CASCADE) ||
             (raRules[inner] ==StatementType.RA_SETNULL))
          {
            //find  the referencing  table Name
            fktd = fkcd.getTableDescriptor();
            refTableNames.addElement(fktd.getSchemaName() + "." + fktd.getName());
            refActions.addElement(new Integer(raRules[inner]));
            //find the referencing column name required for update null.
            refColumns = fkcd.getReferencedColumns();
            coldl = fktd.getColumnDescriptorList();
            ColumnDescriptorList releventColDes = new ColumnDescriptorList();
            for(int i = 0 ; i < refColumns.length; i++)
            {
              cold =(ColumnDescriptor)coldl.elementAt(refColumns[i]-1);
              releventColDes.add(cold);
            }
            refColDescriptors.addElement(releventColDes);
            refIndexConglomNum.addElement(new Long(conglomNumbers[inner]));
            fkColMap.addElement(colArray);
          }
        }
      }
      else
      {
        continue;
      }

      TableDescriptor  pktd = refcd.getTableDescriptor();
      UUID pkuuid = refcd.getIndexId();
      ConglomerateDescriptor pkIndexConglom = pktd.getConglomerateDescriptor(pkuuid);

      TableDescriptor refTd = cd.getTableDescriptor();
      fkVector.addElement(new FKInfo(
                  fkNames,              // foreign key names
                  refTd.getName(),        // table being modified
                  statementType,            // INSERT|UPDATE|DELETE
                  type,                // FOREIGN_KEY|REFERENCED_KEY
                  pkuuid,                // referenced backing index uuid
                  pkIndexConglom.getConglomerateNumber(), // referened backing index conglom
                  uuids,                // fk backing index uuids
View Full Code Here

  public ResultSetNode bindNonVTITables(DataDictionary dataDictionary,
               FromList fromListParam)
          throws StandardException
  {
    TableDescriptor tableDescriptor = bindTableDescriptor();

    if (tableDescriptor.getTableType() == TableDescriptor.VTI_TYPE) {
      ResultSetNode vtiNode = getNodeFactory().mapTableAsVTI(
          tableDescriptor,
          getCorrelationName(),
          resultColumns,
          getProperties(),
          getContextManager());
      return vtiNode.bindNonVTITables(dataDictionary, fromListParam);
   
   
    ResultColumnList  derivedRCL = resultColumns;
 
    // make sure there's a restriction list
    restrictionList = (PredicateList) getNodeFactory().getNode(
                      C_NodeTypes.PREDICATE_LIST,
                      getContextManager());
    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)
    {
      FromSubquery                fsq;
      ResultSetNode        rsn;
      ViewDescriptor        vd;
      CreateViewNode        cvn;
      SchemaDescriptor      compSchema;

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

      compilerContext.pushCompilationSchema(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 = (FromSubquery) 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());

        // since we reset the compilation schema when we return, we
        // need to save it for use when we bind expressions:
        fsq.setOrigCompilationSchema(compSchema);

        return fsq.bindNonVTITables(dataDictionary, fromListParam);
      }
      finally
      {
        compilerContext.popCompilationSchema();
      }
    }
    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();

View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.dictionary.TableDescriptor

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.