@Override
  public void nextValue(RowKey key, IntegralDataTypeHolder value, int increment, int initialValue) {
    final AdvancedCache<RowKey, Object> identifierCache =
        provider.getCache(IDENTIFIER_STORE).getAdvancedCache();
    boolean done = false;
    do {
      // read value
      // skip locking proposed by Sanne
      Object valueFromDb = identifierCache.withFlags(Flag.SKIP_LOCKING).get(key);
      if (valueFromDb == null) {
        // if not there, insert initial value
        value.initialize(initialValue);
        // TODO should we use GridTypes here?
        valueFromDb = new Long(value.makeValue().longValue());
        final Object oldValue = identifierCache.putIfAbsent(key, valueFromDb);
        // check in case somebody has inserted it behind our back
        if (oldValue != null) {
          value.initialize(((Number) oldValue).longValue());
          valueFromDb = oldValue;
        }
      } else {
        // read the value from the table
        value.initialize(((Number) valueFromDb).longValue());
      }

      // update value
      final IntegralDataTypeHolder updateValue = value.copy();
      // increment value
      updateValue.add(increment);
      // TODO should we use GridTypes here?
      final Object newValueFromDb = updateValue.makeValue().longValue();
      done = identifierCache.replace(key, valueFromDb, newValueFromDb);
    } while (!done);
  }
 @Override
 public Association getAssociation(AssociationKey key) {
   Cache<AssociationKey, Map<RowKey, Map<String, Object>>> cache =
       provider.getCache(ASSOCIATION_STORE);
   Map<RowKey, Map<String, Object>> atomicMap =
       AtomicMapLookup.getFineGrainedAtomicMap(cache, key, false);
   return atomicMap == null ? null : new Association(new MapAssociationSnapshot(atomicMap));
 }
 @Override
 public Tuple createTuple(EntityKey key) {
   // TODO we don't verify that it does not yet exist assuming that this has been done before by
   // the calling code
   // should we improve?
   Cache<EntityKey, Map<String, Object>> cache = provider.getCache(ENTITY_STORE);
   FineGrainedAtomicMap<String, Object> atomicMap =
       AtomicMapLookup.getFineGrainedAtomicMap(cache, key, true);
   return new Tuple(new InfinispanTupleSnapshot(atomicMap));
 }
 @Override
 public Tuple getTuple(EntityKey key) {
   Cache<EntityKey, Map<String, Object>> cache = provider.getCache(ENTITY_STORE);
   FineGrainedAtomicMap<String, Object> atomicMap =
       AtomicMapLookup.getFineGrainedAtomicMap(cache, key, false);
   if (atomicMap == null) {
     return null;
   } else {
     return new Tuple(new InfinispanTupleSnapshot(atomicMap));
   }
 }
 @Override
 public Association createAssociation(AssociationKey key) {
   // TODO we don't verify that it does not yet exist assuming that this ahs been done before by
   // the calling code
   // should we improve?
   Cache<AssociationKey, Map<RowKey, Map<String, Object>>> cache =
       provider.getCache(ASSOCIATION_STORE);
   Map<RowKey, Map<String, Object>> atomicMap =
       AtomicMapLookup.getFineGrainedAtomicMap(cache, key, true);
   return new Association(new MapAssociationSnapshot(atomicMap));
 }
 @Override
 public void removeAssociation(AssociationKey key) {
   Cache<AssociationKey, Map<RowKey, Map<String, Object>>> cache =
       provider.getCache(ASSOCIATION_STORE);
   AtomicMapLookup.removeAtomicMap(cache, key);
 }
 @Override
 public void removeTuple(EntityKey key) {
   Cache<EntityKey, Map<String, Object>> cache = provider.getCache(ENTITY_STORE);
   AtomicMapLookup.removeAtomicMap(cache, key);
 }