boolean changed = false; if (val == null) { newVal = new TransactionalValue<T>(_currTx, updater.update(null)); changed = true; } else { if (_currTx != null && _currTx.equals(val.getTxid()) && !retval.cached) { newVal = val; } else { newVal = new TransactionalValue<T>(_currTx, updater.update(val.getVal())); changed = true; ret.add(newVal.getVal()); if (changed) { newVals.add(newVal);
@Override public TransactionalValue deserialize(byte[] b) { try { String s = new String(b, "UTF-8"); List deser = (List) JSONValue.parseWithException(s); return new TransactionalValue((Long) deser.get(0), deser.get(1)); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }
@Override public List<T> multiGet(List<List<Object>> keys) { List<CachedBatchReadsMap.RetVal<TransactionalValue>> vals = _backing.multiGet(keys); List<T> ret = new ArrayList<T>(vals.size()); for (CachedBatchReadsMap.RetVal<TransactionalValue> retval : vals) { TransactionalValue v = retval.val; if (v != null) { ret.add((T) v.getVal()); } else { ret.add(null); } } return ret; }
@Override public Values toValues(TransactionalValue<ITuple> tuple) { Values values = new Values(); values.add(tuple.getTxid()); for (String valueField : tupleFields) { if (tuple.getVal() != null) { values.add(tuple.getVal().getValueByField(valueField)); } else { values.add(null); } } return values; }
@Override public void multiPut(List<List<Object>> keys, List<T> vals) { List<TransactionalValue> newVals = new ArrayList<TransactionalValue>(vals.size()); for (T val : vals) { newVals.add(new TransactionalValue<T>(_currTx, val)); } _backing.multiPut(keys, newVals); }
@Override public List<T> multiGet(List<List<Object>> keys) { List<CachedBatchReadsMap.RetVal<TransactionalValue>> vals = _backing.multiGet(keys); List<T> ret = new ArrayList<T>(vals.size()); for(CachedBatchReadsMap.RetVal<TransactionalValue> retval: vals) { TransactionalValue v = retval.val; if(v!=null) { ret.add((T) v.getVal()); } else { ret.add(null); } } return ret; }
boolean changed = false; if(val==null) { newVal = new TransactionalValue<T>(_currTx, updater.update(null)); changed = true; } else { if(_currTx!=null && _currTx.equals(val.getTxid()) && !retval.cached) { newVal = val; } else { newVal = new TransactionalValue<T>(_currTx, updater.update(val.getVal())); changed = true; ret.add(newVal.getVal()); if(changed) { newVals.add(newVal);
@Override public Values toValues(T value) { if (value == null) { return null; } switch (stateType) { case NON_TRANSACTIONAL: return new Values(value); case TRANSACTIONAL: TransactionalValue transactional = (TransactionalValue) value; return new Values(transactional.getTxid(), transactional.getVal()); case OPAQUE: OpaqueValue opaque = (OpaqueValue) value; return new Values(opaque.getCurrTxid(), opaque.getCurr(), opaque.getPrev()); default: throw new IllegalStateException("Unknown state type " + stateType); } }
@Override @SuppressWarnings("unchecked") public T fromValues(List<Values> valuesSet) { if (valuesSet == null || valuesSet.size() == 0) { return null; } else if (valuesSet.size() == 1) { Values values = valuesSet.get(0); if (values == null) { return null; } switch (stateType) { case NON_TRANSACTIONAL: return (T) values.get(0); case TRANSACTIONAL: return (T) new TransactionalValue((Long) values.get(0), values.get(1)); case OPAQUE: return (T) new OpaqueValue((Long) values.get(0), values.get(1), values.get(2)); default: throw new IllegalStateException("Unknown state type " + stateType); } } throw new IllegalStateException("State query returned multiple results."); }
@Override public TransactionalValue<ITuple> fromValues(List<Values> valuesList) { if (valuesList == null || valuesList.size() == 0) { return null; } Values values = valuesList.get(0); int index = 0; Long txId = (Long) values.get(index++); SimpleTuple curr = new SimpleTuple(tupleFields); for (String valueField : tupleFields) { curr.put(valueField, values.get(index++)); } boolean isAllNull = true; for (Object value : curr.getValues()) { if (value != null) { isAllNull = false; break; } } if (isAllNull) { curr = null; } return new TransactionalValue<ITuple>(txId, curr); }
@Override public void multiPut(List<List<Object>> keys, List<T> vals) { List<TransactionalValue> newVals = new ArrayList<TransactionalValue>(vals.size()); for(T val: vals) { newVals.add(new TransactionalValue<T>(_currTx, val)); } _backing.multiPut(keys, newVals); }
@Override public TransactionalValue deserialize(byte[] b) { try { String s = new String(b, "UTF-8"); List deser = (List) JSONValue.parseWithException(s); return new TransactionalValue((Long) deser.get(0), deser.get(1)); } catch (UnsupportedEncodingException | ParseException e) { throw new RuntimeException(e); } }