0

我想更新一个 StoredMap 值,我不关心旧值。我找不到避免加载先前值的方法。

StoredMap<Integer, SyntaxDocument> tsCol = new StoredMap<Integer, SyntaxDocument>(tsdb, new IntegerBinding(), new PassageBinding(), true);
tsCol.put(1, doc); // insert value => ok
tsCol.put(1, doc); // <- load previous value but I don't care. I want to avoid the "heavy" PassageBinding process.
tsCol.putAll(Collections.singletonMap(1, doc)); // Even this one load the old value

有没有办法优化我的代码并更新现有值而不加载它(或至少防止绑定以处理旧的 DatabaseEntry 字节)?

注意:调用 remove 然后 put 更慢。

4

1 回答 1

0

解决方案是使用低级数据库 API:

Database tsdb = environment.openDatabase(null, "tsdb", dbconfig);
PassageBinding binding = new PassageBinding();
DatabaseEntry idDbEntry = new DatabaseEntry();

IntegerBinding.intToEntry(id, idDbEntry);
DatabaseEntry dbEntry = new DatabaseEntry();
pb.objectToEntry(data, dbEntry);

tsdb.put(null, idDbEntry, dbEntry); // <-- replace existing value without loading it.
于 2014-04-22T09:17:21.137 回答