Ejemplo n.º 1
0
 private Integer getOccurrenceCountFromAllTransaction(String value, DataContainer container) {
   Integer occurrenceCount = container.getData().getValueCount(value);
   if (occurrenceCount == null) {
     occurrenceCount = container.getTransactionManager().getOccurrencesForValue(value);
   }
   return occurrenceCount;
 }
  @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.º 3
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();
  }