/**
   * 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);
    }
  }
示例#2
0
 private ObjectInputStream getIn() throws IOException {
   final FileInputStream fis = new FileInputStream(storeImpl.getStore());
   getReadLock(fis.getChannel());
   if (fis.available() > 0) {
     return new ObjectInputStream(fis);
   } else {
     fis.close();
     return null;
   }
 }
  public synchronized CachedObject get(int i, PersistentStore store, boolean keep)
      throws HsqlException {

    if (i < 0) {
      return null;
    }

    try {
      CachedObject object = cache.get(i);

      if (object == null) {
        RowInputInterface rowInput = readObject(i);

        if (rowInput == null) {
          return null;
        }

        object = store.get(rowInput);

        // for text tables with empty rows at the beginning,
        // pos may move forward in readObject
        i = object.getPos();

        cache.put(i, object);
      }

      if (keep) {
        object.keepInMemory(true);
      }

      return object;
    } catch (IOException e) {
      database.logger.appLog.logContext(SimpleLog.LOG_ERROR, fileName + " get pos: " + i);
      database.logger.appLog.logContext(e);

      throw Trace.error(
          Trace.DATA_FILE_ERROR, Trace.DataFileCache_makeRow, new Object[] {e, fileName});
    }
  }
  public synchronized CachedObject get(int i, PersistentStore store, boolean keep)
      throws HsqlException {

    if (i < 0) {
      return null;
    }

    try {
      CachedObject value = cache.get(i);

      if (value == null) {
        boolean result = readObject(i);

        if (!result) {
          return null;
        }

        value = store.get(rowIn);

        value.setPos(i);
        cache.put(i, value);
      }

      if (keep) {
        value.keepInMemory(true);
      }

      return value;
    } catch (IOException e) {
      database.logger.appLog.logContext("" + cache + " pos: " + i);
      database.logger.appLog.logContext(e);

      throw Trace.error(
          Trace.DATA_FILE_ERROR, Trace.DataFileCache_makeRow, new Object[] {e, fileName});
    }
  }
示例#5
0
 public void lock() throws TimeoutException, IOException {
   final RandomAccessFile raf = new RandomAccessFile(storeImpl.getLock(), "rws");
   getWriteLock(raf.getChannel());
   storeImpl.setState(new Locked(storeImpl, raf));
 }