예제 #1
0
  @Override
  // TODO should we use GridTypes here?
  public Number nextValue(NextValueRequest request) {
    final AdvancedCache<ISK, Object> identifierCache =
        getCacheManager().getIdSourceCache(request.getKey().getMetadata()).getAdvancedCache();
    ISK cacheKey = getKeyProvider().getIdSourceCacheKey(request.getKey());
    boolean done;
    Number value;

    do {
      // skip locking proposed by Sanne
      value = (Number) identifierCache.withFlags(Flag.SKIP_LOCKING).get(cacheKey);

      if (value == null) {
        value = Long.valueOf(request.getInitialValue());
        final Number oldValue = (Number) identifierCache.putIfAbsent(cacheKey, value);
        if (oldValue != null) {
          value = oldValue;
        }
      }

      Number newValue = value.longValue() + request.getIncrement();
      done = identifierCache.replace(cacheKey, value, newValue);
    } while (!done);

    return value;
  }
예제 #2
0
  @Override
  public Number nextValue(NextValueRequest request) {
    final Cache<ISK> cache = getCacheManager().getIdSourceCache(request.getKey().getMetadata());
    ISK key = getKeyProvider().getIdSourceCacheKey(request.getKey());

    Element previousValue = cache.get(key);
    if (previousValue == null) {
      previousValue = cache.putIfAbsent(new Element(key, request.getInitialValue()));
    }
    if (previousValue != null) {
      while (!cache.replace(
          previousValue,
          new Element(
              key,
              ((Number) previousValue.getObjectValue()).longValue() + request.getIncrement()))) {
        previousValue = cache.get(key);
      }
      return ((Number) previousValue.getObjectValue()).longValue() + request.getIncrement();
    } else {
      return request.getInitialValue();
    }
  }
예제 #3
0
 @Override
 public Number nextValue(NextValueRequest request) {
   return neo4jSequenceGenerator.nextValue(
       request.getKey(), request.getIncrement(), request.getInitialValue());
 }