@Override
  public void execute(DataContainer dataContainer) {
    Data currentData = dataContainer.getData();
    TransactionManager transactionManager = dataContainer.getTransactionManager();

    // get value count
    Integer currentCount = currentData.getValueCount(value);
    if (currentCount == null) {
      currentCount = transactionManager.getOccurrencesForValue(value);
      // cache count value in current transaction
      currentData.setValueCount(value, currentCount);
    }
    System.out.println(currentCount);
  }
Ejemplo n.º 2
0
  @Override
  public void execute(DataContainer dataContainer) {
    Data currentData = dataContainer.getData();
    TransactionManager transactionManager = dataContainer.getTransactionManager();

    // get old value and decrement it's count
    String oldValue = currentData.getKeyValue(name);
    if (oldValue == null) {
      oldValue = transactionManager.getMostRecentValueForKey(name);
    }
    if (oldValue != null) {
      Integer decrementedOccurrenceCount =
          getOccurrenceCountFromAllTransaction(oldValue, dataContainer) - 1;
      currentData.setValueCount(oldValue, decrementedOccurrenceCount);
    }

    // delete and mark key as deleted
    currentData.unsetKey(name);
    System.out.println();
  }