private ProcessPerTxBoxesTransaction speculatePerTxBoxes(int maxVersion) { if (this.perTxValues == EMPTY_MAP) { return ProcessPerTxBoxesTransaction.EMPTY_COMMIT_TX; } ProcessPerTxBoxesTransaction commitTx = new ProcessPerTxBoxesTransaction(maxVersion, this); for (Map.Entry<PerTxBox, Object> entry : this.perTxValues.entrySet()) { entry.getKey().commit(entry.getValue()); } commitTx.finishExecution(); return commitTx; }
protected void consolidateElementsIfLoaded() { if (elementsToAdd.get().size() + elementsToRemove.get().size() > 0) { VBox<FunctionalSet<E2>> box = getElementsBox(); if (box.hasValue()) { consolidateElements(); } else { // here we write the NOT_LOADED_VALUE to force the box to go to the write-set box.putNotLoadedValue(); } } }
@Override protected void doCommit() { // the commit is already done, so create a new ActiveTransactionsRecord for (Map.Entry<PerTxBox, Object> entry : this.perTxValues.entrySet()) { entry.getKey().commit(entry.getValue()); } ActiveTransactionsRecord newRecord = new ActiveTransactionsRecord(getNumber(), WriteSet.empty()); newRecord.setCommitted(); setMostRecentCommittedRecord(newRecord); if (!this.activeTxRecord.trySetNext(newRecord)) { throw new Error("Unacceptable: UnsafeSingleThreadedTransaction in a concurrent environment"); } // we must update the activeRecords accordingly context().oldestRequiredVersion = newRecord; this.activeTxRecord = newRecord; }
@Override public boolean justRemove(E2 obj) { TransactionSupport.logAttrChange(listHolder, attributeName); elementsToRemove.put(elementsToRemove.get().cons(obj)); elementsToAdd.put(elementsToAdd.get().removeAll(obj)); // HACK!!! This is to be fixed upon migration to RelationAwareSet // I wouldn't like to force a load of the list to be able to return the correct boolean value return true; }
@Override public boolean justAdd(E2 obj) { TransactionSupport.logAttrChange(listHolder, attributeName); elementsToAdd.put(elementsToAdd.get().cons(obj)); elementsToRemove.put(elementsToRemove.get().removeAll(obj)); // HACK!!! This is to be fixed upon migration to RelationAwareSet // I wouldn't like to force a load of the list to be able to return the correct boolean value return true; }
private void consolidateElements() { VBox<FunctionalSet<E2>> box = getElementsBox(); FunctionalSet<E2> origSet = box.get(listHolder, attributeName); FunctionalSet<E2> newSet = origSet; if (elementsToRemove.get().size() > 0) { Iterator<E2> iter = elementsToRemove.get().iterator(); while (iter.hasNext()) { newSet = newSet.remove(iter.next()); } elementsToRemove.put(Cons.<E2> empty()); } if (elementsToAdd.get().size() > 0) { Iterator<E2> iter = elementsToAdd.get().iterator(); while (iter.hasNext()) { newSet = newSet.add(iter.next()); } elementsToAdd.put(Cons.<E2> empty()); } if (newSet != origSet) { // Because a nested FenixConsistencyCheckTransaction cannot perform writes, but may need to // consolidate the elements of a relation changed by the parent transaction box.putInParent(newSet); } }