Exemple #1
0
 /**
  * Set the value of the given variable for this session.
  *
  * @param name the name of the variable (may not be null)
  * @param value the new value (may not be null)
  */
 public void setVariable(String name, Value value) {
   initVariables();
   modificationId++;
   Value old;
   if (value == ValueNull.INSTANCE) {
     old = variables.remove(name);
   } else {
     // link LOB values, to make sure we have our own object
     value = value.copy(database, LobStorageFrontend.TABLE_ID_SESSION_VARIABLE);
     old = variables.put(name, value);
   }
   if (old != null) {
     // remove the old value (in case it is a lob)
     old.remove();
   }
 }
  @Override
  public void add(Session session, Row row) {
    if (mainIndexColumn == -1) {
      if (row.getKey() == 0) {
        row.setKey(++lastKey);
      }
    } else {
      long c = row.getValue(mainIndexColumn).getLong();
      row.setKey(c);
    }

    if (mvTable.getContainsLargeObject()) {
      for (int i = 0, len = row.getColumnCount(); i < len; i++) {
        Value v = row.getValue(i);
        Value v2 = v.copy(database, getId());
        if (v2.isLinkedToTable()) {
          session.removeAtCommitStop(v2);
        }
        if (v != v2) {
          row.setValue(i, v2);
        }
      }
    }

    TransactionMap<Value, Value> map = getMap(session);
    Value key = ValueLong.get(row.getKey());
    Value old = map.getLatest(key);
    if (old != null) {
      String sql = "PRIMARY KEY ON " + table.getSQL();
      if (mainIndexColumn >= 0 && mainIndexColumn < indexColumns.length) {
        sql += "(" + indexColumns[mainIndexColumn].getSQL() + ")";
      }
      DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, sql);
      e.setSource(this);
      throw e;
    }
    try {
      map.put(key, ValueArray.get(row.getValueList()));
    } catch (IllegalStateException e) {
      throw mvTable.convertException(e);
    }
    lastKey = Math.max(lastKey, row.getKey());
  }