提交 f66a645a authored 作者: Andrei Tokar's avatar Andrei Tokar

subclass Value from VersionedValue and eliminate wrapping of committed values

上级 a7a36189
......@@ -290,7 +290,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
// and any non-null value will do
@SuppressWarnings("unchecked")
K k = (K) key;
result = map.put(k, VersionedValue.VV_NULL, decisionMaker);
result = map.put(k, VersionedValue.DUMMY, decisionMaker);
MVMap.Decision decision = decisionMaker.getDecision();
assert decision != null;
......
......@@ -453,7 +453,7 @@ public class TransactionStore {
// used by CommitDecisionMaker, MVRTreeMap has weird
// traversal logic based on it, and any non-null
// value will do, to signify update, not removal
map.operate(key, VersionedValue.VV_NULL, commitDecisionMaker);
map.operate(key, VersionedValue.DUMMY, commitDecisionMaker);
}
}
undoLog.clear();
......
......@@ -9,7 +9,6 @@ import org.h2.engine.Constants;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.WriteBuffer;
import org.h2.mvstore.type.DataType;
import org.h2.value.ValueNull;
import java.nio.ByteBuffer;
/**
......@@ -20,18 +19,18 @@ import java.nio.ByteBuffer;
*/
public class VersionedValue {
static final VersionedValue VV_NULL = new VersionedValue();
static final VersionedValue DUMMY = new VersionedValue();
static VersionedValue getInstance(Object value) {
assert value != null;
return value == ValueNull.INSTANCE ? VV_NULL : new Committed(value);
return value instanceof VersionedValue ? (VersionedValue)value : new Committed(value);
}
public static VersionedValue getInstance(long operationId, Object value, Object committedValue) {
return new Uncommitted(operationId, value, committedValue);
}
private VersionedValue() {}
protected VersionedValue() {}
public boolean isCommitted() {
return true;
......@@ -42,11 +41,11 @@ public class VersionedValue {
}
public Object getCurrentValue() {
return ValueNull.INSTANCE;
return this;
}
public Object getCommittedValue() {
return ValueNull.INSTANCE;
return this;
}
private static class Committed extends VersionedValue
......@@ -159,7 +158,7 @@ public class VersionedValue {
if (buff.get() == 0) {
// fast path (no op ids or null entries)
for (int i = 0; i < len; i++) {
obj[i] = new Committed(valueType.read(buff));
obj[i] = getInstance(valueType.read(buff));
}
} else {
// slow path (some entries may be null)
......@@ -173,7 +172,7 @@ public class VersionedValue {
public Object read(ByteBuffer buff) {
long operationId = DataUtils.readVarLong(buff);
if (operationId == 0) {
return new Committed(valueType.read(buff));
return getInstance(valueType.read(buff));
} else {
byte flags = buff.get();
Object value = (flags & 1) != 0 ? valueType.read(buff) : null;
......
......@@ -23,6 +23,7 @@ import org.h2.api.IntervalQualifier;
import org.h2.engine.Mode;
import org.h2.engine.SysProperties;
import org.h2.message.DbException;
import org.h2.mvstore.tx.VersionedValue;
import org.h2.result.ResultInterface;
import org.h2.result.SimpleResult;
import org.h2.store.DataHandler;
......@@ -40,7 +41,7 @@ import org.h2.util.StringUtils;
* @author Noel Grandin
* @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
*/
public abstract class Value {
public abstract class Value extends VersionedValue {
/**
* The data type is unknown at this time.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论