public Object replace(Object key, Object value) {
checkTransactionState();
TxnValueWrapper wrapper = txMap.get(key);
boolean haveTxnPast = wrapper != null;
MapService service = getService();
if (haveTxnPast) {
if (wrapper.type == TxnValueWrapper.Type.REMOVED) {
return null;
}
putInternal(service.toData(key, partitionStrategy), service.toData(value));
txMap.put(key, new TxnValueWrapper(value, TxnValueWrapper.Type.UPDATED));
return wrapper.value;
} else {
Data oldValue = replaceInternal(service.toData(key, partitionStrategy), service.toData(value));
if (oldValue != null) {
txMap.put(key, new TxnValueWrapper(value, TxnValueWrapper.Type.UPDATED));
}
return service.toObject(oldValue);
}
}