コード例 #1
0
 public MVPrimaryIndex(
     Database db, MVTable table, int id, IndexColumn[] columns, IndexType indexType) {
   this.mvTable = table;
   initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType);
   int[] sortTypes = new int[columns.length];
   for (int i = 0; i < columns.length; i++) {
     sortTypes[i] = SortOrder.ASCENDING;
   }
   ValueDataType keyType = new ValueDataType(null, null, null);
   ValueDataType valueType = new ValueDataType(db.getCompareMode(), db, sortTypes);
   mapName = "table." + getId();
   dataMap = mvTable.getTransaction(null).openMap(mapName, keyType, valueType);
   Value k = dataMap.lastKey();
   lastKey = k == null ? 0 : k.getLong();
 }
コード例 #2
0
 /**
  * Get the map to store the data.
  *
  * @param session the session
  * @return the map
  */
 TransactionMap<Value, Value> getMap(Session session) {
   if (session == null) {
     return dataMap;
   }
   Transaction t = mvTable.getTransaction(session);
   return dataMap.getInstance(t, Long.MAX_VALUE);
 }
コード例 #3
0
 @Override
 public void truncate(Session session) {
   TransactionMap<Value, Value> map = getMap(session);
   if (mvTable.getContainsLargeObject()) {
     database.getLobStorage().removeAllForTable(table.getId());
   }
   map.clear();
 }
コード例 #4
0
 @Override
 public void remove(Session session) {
   TransactionMap<Value, Value> map = getMap(session);
   if (!map.isClosed()) {
     Transaction t = mvTable.getTransaction(session);
     t.removeMap(map);
   }
 }
コード例 #5
0
 public MVDelegateIndex(
     MVTable table, int id, String name, MVPrimaryIndex mainIndex, IndexType indexType) {
   IndexColumn[] cols =
       IndexColumn.wrap(new Column[] {table.getColumn(mainIndex.getMainIndexColumn())});
   this.initBaseIndex(table, id, name, cols, indexType);
   this.mainIndex = mainIndex;
   if (id < 0) {
     throw DbException.throwInternalError("" + name);
   }
 }
コード例 #6
0
  @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());
  }
コード例 #7
0
 @Override
 public void remove(Session session, Row row) {
   if (mvTable.getContainsLargeObject()) {
     for (int i = 0, len = row.getColumnCount(); i < len; i++) {
       Value v = row.getValue(i);
       if (v.isLinkedToTable()) {
         session.removeAtCommit(v);
       }
     }
   }
   TransactionMap<Value, Value> map = getMap(session);
   try {
     Value old = map.remove(ValueLong.get(row.getKey()));
     if (old == null) {
       throw DbException.get(
           ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, getSQL() + ": " + row.getKey());
     }
   } catch (IllegalStateException e) {
     throw mvTable.convertException(e);
   }
 }