Ejemplo n.º 1
0
  @Override
  public void updateMaxCounterForClass(DomainClassInfo domainClassInfo, int newCounterValue) {
    Transaction current = FenixFramework.getTransaction();

    Set<DomainClassInfo> infos = current.getFromContext(KEY_INSTANTIATED_CLASSES);
    if (infos == null) {
      infos = new HashSet<DomainClassInfo>();
      current.putInContext(KEY_INSTANTIATED_CLASSES, infos);
    }

    if (infos.add(domainClassInfo)) {
      logger.debug(
          "Will update counter for instances of {} upon commit.", domainClassInfo.domainClassName);
    }
  }
Ejemplo n.º 2
0
  // only correct if invoked within a backing transaction.  Also this code
  // assumes a single global commit lock. Otherwise the counter might be set
  // backwards by a late-running thread.
  private void updatePersistentInstanceCounters() {
    Transaction current = FenixFramework.getTransaction();

    Set<DomainClassInfo> infos = current.getFromContext(KEY_INSTANTIATED_CLASSES);

    if (infos != null) {
      for (DomainClassInfo info : infos) {
        String key = makeKeyForMaxCounter(info);
        Integer max = (Integer) dataGrid.get(key);

        int newCounterValue = info.getLastKey();

        if (max == null || max < newCounterValue) {
          dataGrid.put(key, newCounterValue);
          logger.debug(
              "Update persistent counter for class {}: {}", info.domainClassName, newCounterValue);
        }
      }
    }
  }