Examples of TableDescriptor


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

    // get the SchemaDescriptor
    SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
    if ( !isIndex)
    {
      // get the TableDescriptor for the table
      TableDescriptor td = dd.getTableDescriptor(conglomerateName, sd);

      // Return an empty Properties if table does not exist or if it is for a view.
      if ((td == null) || td.getTableType() == TableDescriptor.VIEW_TYPE) { return new Properties(); }

      conglomerateNumber = td.getHeapConglomerateId();
    }
    else
    {
      // get the ConglomerateDescriptor for the index
      ConglomerateDescriptor cd = dd.getConglomerateDescriptor(conglomerateName, sd, false);
View Full Code Here

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

   */
  public static boolean checkTable(String schemaName, String tableName)
            throws SQLException
  {
    DataDictionary      dd;
    TableDescriptor      td;
    long          baseRowCount = -1;
    TransactionController  tc;
    ConglomerateDescriptor  heapCD;
    ConglomerateDescriptor  indexCD;
    ExecRow          baseRow;
    ExecRow          indexRow;
    RowLocation        rl = null;
    RowLocation        scanRL = null;
    ScanController      scan = null;
    int[]          baseColumnPositions;
    int            baseColumns = 0;
    DataValueFactory    dvf;
    long          indexRows;
    ConglomerateController  baseCC = null;
    ConglomerateController  indexCC = null;
    SchemaDescriptor    sd;
    ConstraintDescriptor  constraintDesc;

    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    tc = lcc.getTransactionExecute();

    try {

            dd = lcc.getDataDictionary();

            dvf = lcc.getDataValueFactory();
           
            ExecutionFactory ef = lcc.getLanguageConnectionFactory().getExecutionFactory();

            sd = dd.getSchemaDescriptor(schemaName, tc, true);
            td = dd.getTableDescriptor(tableName, sd);

            if (td == null)
            {
                throw StandardException.newException(
                    SQLState.LANG_TABLE_NOT_FOUND,
                    schemaName + "." + tableName);
            }

            /* Skip views */
            if (td.getTableType() == TableDescriptor.VIEW_TYPE)
            {
                return true;
            }

      /* Open the heap for reading */
      baseCC = tc.openConglomerate(
                  td.getHeapConglomerateId(), false, 0,
                TransactionController.MODE_TABLE,
              TransactionController.ISOLATION_SERIALIZABLE);

      /* Check the consistency of the heap */
      baseCC.checkConsistency();

      heapCD = td.getConglomerateDescriptor(td.getHeapConglomerateId());

      /* Get a row template for the base table */
      baseRow = ef.getValueRow(td.getNumberOfColumns());

      /* Fill the row with nulls of the correct type */
      ColumnDescriptorList cdl = td.getColumnDescriptorList();
      int           cdlSize = cdl.size();

      for (int index = 0; index < cdlSize; index++)
      {
        ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
        baseRow.setColumn(cd.getPosition(),
                    cd.getType().getNull());
      }

      /* Look at all the indexes on the table */
      ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();
      for (int index = 0; index < cds.length; index++)
      {
        indexCD = cds[index];
        /* Skip the heap */
        if ( ! indexCD.isIndex())
          continue;

        /* Check the internal consistency of the index */
        indexCC =
              tc.openConglomerate(
                indexCD.getConglomerateNumber(),
                        false,
              0,
            TransactionController.MODE_TABLE,
                      TransactionController.ISOLATION_SERIALIZABLE);

        indexCC.checkConsistency();
        indexCC.close();
        indexCC = null;

        /* if index is for a constraint check that the constraint exists */

        if (indexCD.isConstraint())
        {
          constraintDesc = dd.getConstraintDescriptor(td, indexCD.getUUID());
          if (constraintDesc == null)
          {
            throw StandardException.newException(
                    SQLState.LANG_OBJECT_NOT_FOUND,
                    "CONSTRAINT for INDEX",
                    indexCD.getConglomerateName());
          }
        }

        /*
        ** Set the base row count when we get to the first index.
        ** We do this here, rather than outside the index loop, so
        ** we won't do the work of counting the rows in the base table
        ** if there are no indexes to check.
        */
        if (baseRowCount < 0)
        {
          scan = tc.openScan(heapCD.getConglomerateNumber(),
                    false,  // hold
                    0,    // not forUpdate
                      TransactionController.MODE_TABLE,
                      TransactionController.ISOLATION_SERIALIZABLE,
                                        RowUtil.EMPTY_ROW_BITSET,
                    null,  // startKeyValue
                    0,    // not used with null start posn.
                    null,  // qualifier
                    null,  // stopKeyValue
                    0);    // not used with null stop posn.

          /* Also, get the row location template for index rows */
          rl = scan.newRowLocationTemplate();
          scanRL = scan.newRowLocationTemplate();

          for (baseRowCount = 0; scan.next(); baseRowCount++)
            /* Empty statement */

          scan.close();
          scan = null;
        }

        baseColumnPositions =
            indexCD.getIndexDescriptor().baseColumnPositions();
        baseColumns = baseColumnPositions.length;

        FormatableBitSet indexColsBitSet = new FormatableBitSet();
        for (int i = 0; i < baseColumns; i++)
        {
          indexColsBitSet.grow(baseColumnPositions[i]);
          indexColsBitSet.set(baseColumnPositions[i] - 1);
        }

        /* Get one row template for the index scan, and one for the fetch */
        indexRow = ef.getValueRow(baseColumns + 1);

        /* Fill the row with nulls of the correct type */
        for (int column = 0; column < baseColumns; column++)
        {
          /* Column positions in the data dictionary are one-based */
           ColumnDescriptor cd = td.getColumnDescriptor(baseColumnPositions[column]);
          indexRow.setColumn(column + 1,
                      cd.getType().getNull());
        }

        /* Set the row location in the last column of the index row */
        indexRow.setColumn(baseColumns + 1, rl);

        /* Do a full scan of the index */
        scan = tc.openScan(indexCD.getConglomerateNumber(),
                  false,  // hold
                  0,    // not forUpdate
                    TransactionController.MODE_TABLE,
                        TransactionController.ISOLATION_SERIALIZABLE,
                  (FormatableBitSet) null,
                  null,  // startKeyValue
                  0,    // not used with null start posn.
                  null,  // qualifier
                  null,  // stopKeyValue
                  0);    // not used with null stop posn.

        DataValueDescriptor[] baseRowIndexOrder =
                    new DataValueDescriptor[baseColumns];
        DataValueDescriptor[] baseObjectArray = baseRow.getRowArray();

        for (int i = 0; i < baseColumns; i++)
        {
          baseRowIndexOrder[i] = baseObjectArray[baseColumnPositions[i] - 1];
        }
     
        /* Get the index rows and count them */
        for (indexRows = 0; scan.fetchNext(indexRow.getRowArray()); indexRows++)
        {
          /*
          ** Get the base row using the RowLocation in the index row,
          ** which is in the last column. 
          */
          RowLocation baseRL = (RowLocation) indexRow.getColumn(baseColumns + 1);

          boolean base_row_exists =
                    baseCC.fetch(
                      baseRL, baseObjectArray, indexColsBitSet);

          /* Throw exception if fetch() returns false */
          if (! base_row_exists)
          {
            String indexName = indexCD.getConglomerateName();
            throw StandardException.newException(SQLState.LANG_INCONSISTENT_ROW_LOCATION,
                  (schemaName + "." + tableName),
                  indexName,
                  baseRL.toString(),
                  indexRow.toString());
          }

          /* Compare all the column values */
          for (int column = 0; column < baseColumns; column++)
          {
            DataValueDescriptor indexColumn =
              indexRow.getColumn(column + 1);
            DataValueDescriptor baseColumn =
              baseRowIndexOrder[column];

            /*
            ** With this form of compare(), null is considered equal
            ** to null.
            */
            if (indexColumn.compare(baseColumn) != 0)
            {
              ColumnDescriptor cd =
                                td.getColumnDescriptor(
                                    baseColumnPositions[column]);

                            /*
                            System.out.println(
                                "SQLState.LANG_INDEX_COLUMN_NOT_EQUAL:" +
                                "indexCD.getConglomerateName()" + indexCD.getConglomerateName() +
                                ";td.getSchemaName() = " + td.getSchemaName() +
                                ";td.getName() = " + td.getName() +
                                ";baseRL.toString() = " + baseRL.toString() +
                                ";cd.getColumnName() = " + cd.getColumnName() +
                                ";indexColumn.toString() = " + indexColumn.toString() +
                                ";baseColumn.toString() = " + baseColumn.toString() +
                                ";indexRow.toString() = " + indexRow.toString());
                            */

              throw StandardException.newException(
                                SQLState.LANG_INDEX_COLUMN_NOT_EQUAL,
                                indexCD.getConglomerateName(),
                                td.getSchemaName(),
                                td.getName(),
                                baseRL.toString(),
                                cd.getColumnName(),
                                indexColumn.toString(),
                                baseColumn.toString(),
                                indexRow.toString());
            }
          }
        }

        /* Clean up after the index scan */
        scan.close();
        scan = null;

        /*
        ** The index is supposed to have the same number of rows as the
        ** base conglomerate.
        */
        if (indexRows != baseRowCount)
        {
          throw StandardException.newException(SQLState.LANG_INDEX_ROW_COUNT_MISMATCH,
                    indexCD.getConglomerateName(),
                    td.getSchemaName(),
                    td.getName(),
                    Long.toString(indexRows),
                    Long.toString(baseRowCount));
        }
      }
      /* check that all constraints have backing index */
      ConstraintDescriptorList constraintDescList =
        dd.getConstraintDescriptors(td);
      for (int index = 0; index < constraintDescList.size(); index++)
      {
        constraintDesc = constraintDescList.elementAt(index);
        if (constraintDesc.hasBackingIndex())
        {
          ConglomerateDescriptor conglomDesc;

          conglomDesc = td.getConglomerateDescriptor(
              constraintDesc.getConglomerateId());
          if (conglomDesc == null)
          {
            throw StandardException.newException(
                    SQLState.LANG_OBJECT_NOT_FOUND,
View Full Code Here

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

    try {

            SchemaDescriptor sd =
                data_dictionary.getSchemaDescriptor(
                    schemaName, nested_tc, true);
            TableDescriptor td =
                data_dictionary.getTableDescriptor(tableName, sd);
            nested_tc =
                tc.startNestedUserTransaction(false);

            if (td == null)
            {
                throw StandardException.newException(
                    SQLState.LANG_TABLE_NOT_FOUND,
                    schemaName + "." + tableName);
            }

            switch (td.getTableType())
            {
            /* Skip views and vti tables */
            case TableDescriptor.VIEW_TYPE:
            case TableDescriptor.VTI_TYPE:
              return;
            // other types give various errors here
            // DERBY-719,DERBY-720
            default:
              break;
            }


      ConglomerateDescriptor heapCD =
                td.getConglomerateDescriptor(td.getHeapConglomerateId());

      /* Get a row template for the base table */
      ExecRow baseRow =
                lcc.getLanguageConnectionFactory().getExecutionFactory().getValueRow(
                    td.getNumberOfColumns());


      /* Fill the row with nulls of the correct type */
      ColumnDescriptorList cdl = td.getColumnDescriptorList();
      int           cdlSize = cdl.size();

      for (int index = 0; index < cdlSize; index++)
      {
        ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
        baseRow.setColumn(cd.getPosition(), cd.getType().getNull());
      }

            DataValueDescriptor[][] row_array = new DataValueDescriptor[100][];
            row_array[0] = baseRow.getRowArray();
            RowLocation[] old_row_location_array = new RowLocation[100];
            RowLocation[] new_row_location_array = new RowLocation[100];

            // Create the following 3 arrays which will be used to update
            // each index as the scan moves rows about the heap as part of
            // the compress:
            //     index_col_map - map location of index cols in the base row,
            //                     ie. index_col_map[0] is column offset of 1st
            //                     key column in base row.  All offsets are 0
            //                     based.
            //     index_scan - open ScanController used to delete old index row
            //     index_cc   - open ConglomerateController used to insert new
            //                  row

            ConglomerateDescriptor[] conglom_descriptors =
                td.getConglomerateDescriptors();

            // conglom_descriptors has an entry for the conglomerate and each
            // one of it's indexes.
            num_indexes = conglom_descriptors.length - 1;

            // if indexes exist, set up data structures to update them
            if (num_indexes > 0)
            {
                // allocate arrays
                index_col_map   = new int[num_indexes][];
                index_scan      = new ScanController[num_indexes];
                index_cc        = new ConglomerateController[num_indexes];
                index_row       = new DataValueDescriptor[num_indexes][];

                setup_indexes(
                    nested_tc,
                    td,
                    index_col_map,
                    index_scan,
                    index_cc,
                    index_row);

            }

      /* Open the heap for reading */
      base_group_fetch_cc =
                nested_tc.defragmentConglomerate(
                    td.getHeapConglomerateId(),
                    false,
                    true,
                    TransactionController.OPENMODE_FORUPDATE,
            TransactionController.MODE_TABLE,
          TransactionController.ISOLATION_SERIALIZABLE);
View Full Code Here

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

    TransactionController   tc)
        throws StandardException
  {
        SchemaDescriptor sd =
            data_dictionary.getSchemaDescriptor(schemaName, tc, true);
        TableDescriptor  td =
            data_dictionary.getTableDescriptor(tableName, sd);

        if (td == null)
        {
            throw StandardException.newException(
                SQLState.LANG_TABLE_NOT_FOUND,
                schemaName + "." + tableName);
        }

        switch (td.getTableType())
        {
        /* Skip views and vti tables */
        case TableDescriptor.VIEW_TYPE:
        case TableDescriptor.VTI_TYPE:
          break;
        // other types give various errors here
        // DERBY-719,DERBY-720
        default:
          {

            ConglomerateDescriptor[] conglom_descriptors =
                td.getConglomerateDescriptors();

            for (int cd_idx = 0; cd_idx < conglom_descriptors.length; cd_idx++)
            {
                ConglomerateDescriptor cd = conglom_descriptors[cd_idx];

View Full Code Here

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

    TransactionController   tc)
        throws StandardException
  {
        SchemaDescriptor sd =
            data_dictionary.getSchemaDescriptor(schemaName, tc, true);
        TableDescriptor  td =
            data_dictionary.getTableDescriptor(tableName, sd);

        if (td == null)
        {
            throw StandardException.newException(
                SQLState.LANG_TABLE_NOT_FOUND,
                schemaName + "." + tableName);
        }

        switch (td.getTableType())
        {
        /* Skip views and vti tables */
        case TableDescriptor.VIEW_TYPE:
        case TableDescriptor.VTI_TYPE:
          break;
        // other types give various errors here
        // DERBY-719,DERBY-720
        default:
          {
          ConglomerateDescriptor[] conglom_descriptors =
                td.getConglomerateDescriptors();

            for (int cd_idx = 0; cd_idx < conglom_descriptors.length; cd_idx++)
            {
                ConglomerateDescriptor cd = conglom_descriptors[cd_idx];

View Full Code Here

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

   */
  public TableDescriptor    getTableDescriptor(String tableName,
          SchemaDescriptor schema, TransactionController tc)
      throws StandardException
  {
    TableDescriptor    retval = null;

    /*
    ** If we didn't get a schema descriptor, we had better
    ** have a system table.
    */
    if (SanityManager.DEBUG)
    {
      if ((schema == null) && !tableName.startsWith("SYS"))
      {
        SanityManager.THROWASSERT("null schema for non system table "+tableName);
      }
    }

    SchemaDescriptor sd = (schema == null) ?
        getSystemSchemaDescriptor()
        : schema;

    UUID schemaUUID = sd.getUUID();
   
    if (SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME.equals(
        sd.getSchemaName()))
    {
      TableDescriptor td =
        new TableDescriptor(this, tableName, sd,
            TableDescriptor.VTI_TYPE,
            TableDescriptor.DEFAULT_LOCK_GRANULARITY);
     
      // ensure a vti class exists
      if (getVTIClass(td, false) != null)
View Full Code Here

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

                    String schemaUUID)
        throws StandardException
  {
    DataValueDescriptor      schemaIDOrderable;
    DataValueDescriptor      tableNameOrderable;
    TableDescriptor        td;
    TabInfoImpl            ti = coreInfo[SYSTABLES_CORE_NUM];

    /* Use tableNameOrderable and schemaIdOrderable in both start
     * and stop position for scan.
     */
 
View Full Code Here

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

   */
  public TableDescriptor    getTableDescriptor(UUID tableID)
      throws StandardException
  {
    OIDTDCacheable    cacheEntry;
    TableDescriptor  retval = null;

    /* Only use the cache if we're in compile-only mode */
    if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE)
    {
      cacheEntry = (OIDTDCacheable) OIDTdCache.find(tableID);
      if (cacheEntry != null)
      {
        retval = cacheEntry.getTableDescriptor();
        // bind in previous command might have set refernced cols
        retval.setReferencedColumnMap(null);
        OIDTdCache.release(cacheEntry);
      }

      return retval;

View Full Code Here

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

  private TableDescriptor getTableDescriptorIndex2Scan(
                    String tableUUID)
        throws StandardException
  {
    DataValueDescriptor      tableIDOrderable;
    TableDescriptor        td;
    TabInfoImpl            ti = coreInfo[SYSTABLES_CORE_NUM];

    /* Use tableIDOrderable in both start and stop position for scan.
     */
    tableIDOrderable = new SQLChar(tableUUID);
View Full Code Here

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

   * @exception StandardException    Thrown on error
   */
  public ViewDescriptor  getViewDescriptor(TableDescriptor td)
    throws StandardException
  {
    TableDescriptor  tdi = (TableDescriptor) td;

    /* See if the view info is cached */
    if (tdi.getViewDescriptor() != null)
    {
      return tdi.getViewDescriptor();
    }

    synchronized(tdi)
    {
      /* See if we were waiting on someone who just filled it in */
      if (tdi.getViewDescriptor() != null)
      {
        return tdi.getViewDescriptor();
      }

      tdi.setViewDescriptor((ViewDescriptor) getViewDescriptorScan(tdi));
    }
    return tdi.getViewDescriptor();
  }
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.