Ejemplo n.º 1
0
  void doInsertAt(long rowIndex, Value[] values) throws DriverException {
    // Check value count
    int fc = getFieldCount();
    if (values.length != fc) {
      throw new IllegalArgumentException("Wrong number of values. Expected: " + fc);
    }

    // Convert value
    for (int i = 0; i < values.length; i++) {
      Type type = getMetadata().getFieldType(i);
      values[i] = castValue(type, values[i]);
    }

    // Check constraints
    for (int i = 0; i < values.length; i++) {
      // Check uniqueness
      checkConstraints(values[i], i);
    }

    // Perform modifications
    dirty = true;
    insertInIndex(values, (int) rowIndex);
    PhysicalRowAddress dir = internalBuffer.insertRow(null, values);
    rowsAddresses.add((int) rowIndex, dir);
    InsertEditionInfo iei = new InsertEditionInfo(dir);
    editionActions.add((int) rowIndex, iei);
    cachedScope = null;

    editionListenerSupport.callInsert(rowIndex, undoRedo);
  }
Ejemplo n.º 2
0
  ModifyCommand.ModifyInfo doSetFieldValue(long row, int fieldId, Value value)
      throws DriverException {
    // convert value
    Value val = value;
    if (val == null) {
      val = ValueFactory.createNullValue();
    }

    // write check
    checkConstraints(val, fieldId);

    // Do modification
    ModifyCommand.ModifyInfo ret;
    PhysicalRowAddress dir = rowsAddresses.get((int) row);
    dirty = true;
    setFieldValueInIndex((int) row, fieldId, getFieldValue(row, fieldId), val);
    if (dir instanceof OriginalRowAddress) {
      Value[] original = getOriginalRow(dir);
      Value previousValue = original[fieldId];
      original[fieldId] = val;
      PhysicalRowAddress newAddress = internalBuffer.insertRow(dir.getPK(), original);
      rowsAddresses.set((int) row, newAddress);
      UpdateEditionInfo info = new UpdateEditionInfo(dir.getPK(), rowsAddresses.get((int) row));
      EditionInfo ei = editionActions.set((int) row, info);
      ret =
          new ModifyCommand.ModifyInfo(
              (OriginalRowAddress) dir,
              ei,
              (InternalBufferRowAddress) newAddress,
              previousValue,
              row,
              fieldId);
    } else {
      Value previousValue = dir.getFieldValue(fieldId);
      ((InternalBufferRowAddress) dir).setFieldValue(fieldId, val);
      /*
       * We don't modify the EditionInfo because is an insertion that
       * already points to the internal buffer
       */
      ret =
          new ModifyCommand.ModifyInfo(
              null, null, (InternalBufferRowAddress) dir, previousValue, row, fieldId);
    }
    cachedScope = null;

    editionListenerSupport.callSetFieldValue(row, fieldId, undoRedo);

    return ret;
  }