Ejemplo n.º 1
0
 void checkReferencedRows(Session paramSession, Table paramTable) {
   RowIterator localRowIterator = paramTable.rowIterator(paramSession);
   while (true) {
     Row localRow = localRowIterator.getNextRow();
     if (localRow == null) break;
     Object[] arrayOfObject = localRow.getData();
     checkInsert(paramSession, paramTable, arrayOfObject, false);
   }
 }
  /** for result tables */
  void reindex(Session session, Index index) {

    setAccessor(index, null);

    RowIterator it = table.rowIterator(this);

    while (it.hasNext()) {
      Row row = it.getNextRow();

      // may need to clear the node before insert
      index.insert(session, this, row);
    }
  }
Ejemplo n.º 3
0
  public Object[] getValues(Session session) {

    RowIterator it = table.rowIterator(session);

    if (it.hasNext()) {
      Row row = it.getNextRow();

      if (it.hasNext()) {
        throw Error.error(ErrorCode.X_21000);
      }

      return row.getData();
    } else {
      return new Object[table.getColumnCount()];
    }
  }
  void dropIndexFromRows(Index primaryIndex, Index oldIndex) {

    RowIterator it = primaryIndex.firstRow(this, false);
    int position = oldIndex.getPosition() - 1;

    while (it.hasNext()) {
      Row row = it.getNextRow();
      int i = position - 1;
      NodeAVL backnode = ((RowAVL) row).getNode(0);

      while (i-- > 0) {
        backnode = backnode.nNext;
      }

      backnode.nNext = backnode.nNext.nNext;
    }
  }
  public final void indexRows() {

    RowIterator it = rowIterator();

    for (int i = 1; i < indexList.length; i++) {
      setAccessor(indexList[i], null);
    }

    while (it.hasNext()) {
      Row row = it.getNextRow();

      ((RowAVL) row).clearNonPrimaryNodes();

      for (int i = 1; i < indexList.length; i++) {
        indexList[i].insert(null, this, row);
      }
    }
  }
  boolean insertIndexNodes(Index primaryIndex, Index newIndex) {

    int position = newIndex.getPosition();
    RowIterator it = primaryIndex.firstRow(this, false);
    int rowCount = 0;
    HsqlException error = null;

    try {
      while (it.hasNext()) {
        Row row = it.getNextRow();

        ((RowAVL) row).insertNode(position);

        // count before inserting
        rowCount++;

        newIndex.insert(null, this, row);
      }

      return true;
    } catch (java.lang.OutOfMemoryError e) {
      error = Error.error(ErrorCode.OUT_OF_MEMORY);
    } catch (HsqlException e) {
      error = e;
    }

    // backtrack on error
    // rowCount rows have been modified
    it = primaryIndex.firstRow(this, false);

    for (int i = 0; i < rowCount; i++) {
      Row row = it.getNextRow();
      NodeAVL backnode = ((RowAVL) row).getNode(0);
      int j = position;

      while (--j > 0) {
        backnode = backnode.nNext;
      }

      backnode.nNext = backnode.nNext.nNext;
    }

    throw error;
  }
  /**
   * Moves the data from an old store to new after changes to table The colindex argument is the
   * index of the column that was added or removed. The adjust argument is {-1 | 0 | +1}
   */
  public final void moveData(Session session, PersistentStore other, int colindex, int adjust) {

    Object colvalue = null;
    Type oldtype = null;
    Type newtype = null;

    if (adjust >= 0 && colindex != -1) {
      ColumnSchema column = ((Table) table).getColumn(colindex);

      colvalue = column.getDefaultValue(session);

      if (adjust == 0) {
        oldtype = ((Table) other.getTable()).getColumnTypes()[colindex];
        newtype = ((Table) table).getColumnTypes()[colindex];
      }
    }

    RowIterator it = other.rowIterator();
    Table table = (Table) this.table;

    try {
      while (it.hasNext()) {
        Row row = it.getNextRow();
        Object[] o = row.getData();
        Object[] data = table.getEmptyRowData();

        if (adjust == 0 && colindex != -1) {
          colvalue = newtype.convertToType(session, o[colindex], oldtype);
        }

        ArrayUtil.copyAdjustArray(o, data, colvalue, colindex, adjust);
        table.systemSetIdentityColumn(session, data);
        table.enforceTypeLimits(session, data);
        table.enforceRowConstraints(session, data);

        // get object without RowAction
        Row newrow = (Row) getNewCachedObject(null, data);

        indexRow(null, newrow);
      }
    } catch (java.lang.OutOfMemoryError e) {
      throw Error.error(ErrorCode.OUT_OF_MEMORY);
    }
  }
    public void reset() {

      if (it != null) {
        it.release();
      }

      it = null;
      currentRow = null;
      isBeforeFirst = true;
    }
Ejemplo n.º 9
0
  /**
   * Check used before creating a new foreign key cosntraint, this method checks all rows of a table
   * to ensure they all have a corresponding row in the main table.
   */
  void checkReferencedRows(Session session, Table table, int[] rowColArray) {

    Index mainIndex = getMainIndex();
    PersistentStore store = session.sessionData.getRowStore(table);
    RowIterator it = table.rowIterator(session);

    while (true) {
      Row row = it.getNextRow();

      if (row == null) {
        break;
      }

      Object[] rowData = row.getData();

      if (ArrayUtil.hasNull(rowData, rowColArray)) {
        if (core.matchType == OpTypes.MATCH_SIMPLE) {
          continue;
        }
      } else if (mainIndex.exists(session, store, rowData, rowColArray)) {
        continue;
      }

      if (ArrayUtil.hasAllNull(rowData, rowColArray)) {
        continue;
      }

      String colValues = "";

      for (int i = 0; i < rowColArray.length; i++) {
        Object o = rowData[rowColArray[i]];

        colValues += table.getColumnTypes()[i].convertToString(o);
        colValues += ",";
      }

      String[] info = new String[] {getName().name, getMain().getName().name};

      throw Error.error(ErrorCode.X_23502, ErrorCode.CONSTRAINT, info);
    }
  }
    public boolean next() {

      if (isBeforeFirst) {
        isBeforeFirst = false;
      } else {
        if (it == null) {
          return false;
        }
      }

      currentRow = it.getNextRow();

      if (currentRow == null) {
        return false;
      } else {
        currentData = currentRow.getData();

        return true;
      }
    }
    public void release() {

      if (it != null) {
        it.release();
      }
    }
  int[] writeTableToDataFile(Table table) throws IOException {

    Session session = database.getSessionManager().getSysSession();
    PersistentStore store = session.sessionData.getRowStore(table);
    RowOutputInterface rowOut = new RowOutputBinary(1024, scale);
    DoubleIntIndex pointerLookup =
        new DoubleIntIndex(table.getPrimaryIndex().sizeEstimate(store), false);
    int[] rootsArray = table.getIndexRootsArray();
    long pos = fileOffset;
    int count = 0;

    pointerLookup.setKeysSearchTarget();
    Error.printSystemOut("lookup begins: " + stopw.elapsedTime());

    RowIterator it = table.rowIterator(session);

    for (; it.hasNext(); count++) {
      CachedObject row = it.getNextRow();

      pointerLookup.addUnsorted(row.getPos(), (int) (pos / scale));

      if (count % 50000 == 0) {
        Error.printSystemOut("pointer pair for row " + count + " " + row.getPos() + " " + pos);
      }

      pos += row.getStorageSize();
    }

    Error.printSystemOut(table.getName().name + " list done: " + stopw.elapsedTime());

    count = 0;
    it = table.rowIterator(session);

    for (; it.hasNext(); count++) {
      CachedObject row = it.getNextRow();

      rowOut.reset();
      row.write(rowOut, pointerLookup);
      fileStreamOut.write(rowOut.getOutputStream().getBuffer(), 0, rowOut.size());

      fileOffset += row.getStorageSize();

      if ((count) % 50000 == 0) {
        Error.printSystemOut(count + " rows " + stopw.elapsedTime());
      }
    }

    for (int i = 0; i < rootsArray.length; i++) {
      if (rootsArray[i] == -1) {
        continue;
      }

      int lookupIndex = pointerLookup.findFirstEqualKeyIndex(rootsArray[i]);

      if (lookupIndex == -1) {
        throw Error.error(ErrorCode.DATA_FILE_ERROR);
      }

      rootsArray[i] = pointerLookup.getValue(lookupIndex);
    }

    setTransactionRowLookups(pointerLookup);
    Error.printSystemOut(table.getName().name + " : table converted");

    return rootsArray;
  }