Package org.apache.derby.iapi.sql.execute

Examples of org.apache.derby.iapi.sql.execute.ExecRow


   *
   * @exception StandardException thrown on failure to get next row
   */
  public ExecRow getNextRowCore() throws StandardException
  {
      ExecRow result = null;
    DataValueDescriptor[] columns = null;

    beginTime = getCurrentTimeMillis();
      if ( isOpen && hashtableBuilt)
      {
View Full Code Here


   */
  private ExecRow cloneRow(ExecRow inputRow)
  {
    DataValueDescriptor[] cols = inputRow.getRowArray();
    int ncols = cols.length;
    ExecRow cloned = ((ValueRow) inputRow).cloneMe();
    for (int i = 0; i < ncols; i++)
    {
      if (cols[i] != null)
      {
        /* Rows are 1-based, cols[] is 0-based */
        cloned.setColumn(i + 1, (DataValueDescriptor)((CloneableObject) cols[i]).cloneObject());
      }
    }
    if (inputRow instanceof IndexValueRow)
      return new IndexValueRow(cloned);
    else
View Full Code Here

    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 */
 
View Full Code Here

   */
  public  ExecRow  buildEmptyRow()
    throws StandardException
  {
    int          columnCount = size();
    ExecRow        row = getExecutionFactory().getValueRow( columnCount );
    int          position = 1;

    for (int index = 0; index < columnCount; index++)
    {
        ResultColumn rc = (ResultColumn) elementAt(index);
      DataTypeDescriptor dataType = rc.getTypeServices();
      DataValueDescriptor dataValue = dataType.getNull();

      row.setColumn( position++, dataValue );
    }

    return  row;
  }
View Full Code Here

        SanityManager.THROWASSERT("ConglomerateDescriptor expected to be for index: " + cd);
      }
    }

    int[] baseCols = cd.getIndexDescriptor().baseColumnPositions();
    ExecRow row = getExecutionFactory().getValueRow(baseCols.length + 1);

    for (int i = 0; i < baseCols.length; i++)
    {
      ColumnDescriptor coldes = td.getColumnDescriptor(baseCols[i]);
      DataTypeDescriptor dataType = coldes.getType();

      // rc = getResultColumn(baseCols[i]);
        // rc = (ResultColumn) at(baseCols[i] - 1);
      // dataType = rc.getTypeServices();
      DataValueDescriptor dataValue = dataType.getNull();

      row.setColumn(i + 1, dataValue );
    }

    RowLocation rlTemplate = scc.newRowLocationTemplate();

    row.setColumn(baseCols.length + 1, rlTemplate);

    return  row;
  }
View Full Code Here

      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
View Full Code Here

    synchronized (getConnectionSynchronization()) {

          setupContextStack();
        try {
        LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
        final ExecRow newRow;
        try {

        /* Push and pop a StatementContext around a next call
         * so that the ResultSet will get correctly closed down
         * on an error.
View Full Code Here

   */
  public ExecRow getEmptyExecRow()
     throws StandardException
  {
    int              columnCount = getNumberOfColumns();
    ExecRow result =
            getDataDictionary().getExecutionFactory().getValueRow(columnCount);

    for (int index = 0; index < columnCount; index++)
    {
      ColumnDescriptor cd = (ColumnDescriptor) columnDescriptorList.elementAt(index);
      //String name = column.getColumnName();
      DataValueDescriptor dataValue = cd.getType().getNull();
      result.setColumn(index + 1, dataValue);
    }
    return result;
  }
View Full Code Here

    boolean        compileMe,
    SPSDescriptor    spsDescriptor
  ) throws StandardException
  {
    DataTypeDescriptor    dtd;
    ExecRow            row;
    DataValueDescriptor    col;
    String          name = null;
    UUID          uuid = null;
    String          uuidStr = null
    String          suuidStr = null// schema 
    String          compUuidStr = null// compilation schema 
    String          text = null;
    String          usingText = null;
    ExecPreparedStatement  preparedStatement = null;
    String          typeStr = null;
    boolean          valid = true;
    Timestamp        time = null;
    boolean          initiallyCompilable = true;

    if (spsDescriptor != null)
    {
      name = spsDescriptor.getName();
      uuid = spsDescriptor.getUUID();
      suuidStr = spsDescriptor.getSchemaDescriptor().getUUID().toString();
      uuidStr = uuid.toString();
      text = spsDescriptor.getText();     
      valid = spsDescriptor.isValid();
      time = spsDescriptor.getCompileTime();
      typeStr = spsDescriptor.getTypeAsString();
      initiallyCompilable = spsDescriptor.initiallyCompilable();
      preparedStatement = spsDescriptor.getPreparedStatement(compileMe);
      compUuidStr = (spsDescriptor.getCompSchemaId() != null)?
          spsDescriptor.getCompSchemaId().toString():null;
      usingText = spsDescriptor.getUsingText();
    }

    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSSTATEMENTS_COLUMN_COUNT);

    /* 1st column is STMTID */
    row.setColumn(1, new SQLChar(uuidStr));

    /* 2nd column is STMTNAME */
    row.setColumn(2, new SQLVarchar(name));

    /* 3rd column is SCHEMAID */
    row.setColumn(3, new SQLChar(suuidStr));

    /* 4th column is TYPE */
    row.setColumn(4, new SQLChar(typeStr));

    /* 5th column is VALID */
    row.setColumn(5, new SQLBoolean(valid));

    /* 6th column is TEXT */
    row.setColumn(6, dvf.getLongvarcharDataValue(text));

    /* 7th column is LASTCOMPILED */
    row.setColumn(7, new SQLTimestamp(time));

    /* 8th column is COMPILATIONSCHEMAID */
    row.setColumn(8, new SQLChar(compUuidStr));

    /* 9th column is USINGTEXT */
    row.setColumn(9, dvf.getLongvarcharDataValue(usingText));

    /*
    ** 10th column is CONSTANTSTATE
    **
    ** CONSTANTSTATE is really a formatable StorablePreparedStatement.
    */
    row.setColumn(10, new UserType(preparedStatement));

    /* 11th column is INITIALLY_COMPILABLE */
    row.setColumn(11, new SQLBoolean(initiallyCompilable));

    return row;
  }
View Full Code Here

    */
    if (! cd.isIndex())
      return templateColumns.buildEmptyRow().getRowArray();

    /* It's an index scan, so get all the columns in the index */
    ExecRow emptyIndexRow = templateColumns.buildEmptyIndexRow(
                            tableDescriptor,
                            cd,
                            scc,
                            getDataDictionary());

    return emptyIndexRow.getRowArray();
  }
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.execute.ExecRow

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.