@Override public Number nextValue(NextValueRequest request) { Long result = null; switch ( request.getKey().getMetadata().getType() ) { case TABLE: IgniteCache<String, Long> cache = provider.getIdSourceCache( request.getKey().getMetadata() ); String idSourceKey = request.getKey().getColumnValue(); Long previousValue = cache.get( idSourceKey ); if ( previousValue == null ) { result = (long) request.getInitialValue(); if ( !cache.putIfAbsent( idSourceKey, result ) ) { previousValue = (long) request.getInitialValue(); } } if ( previousValue != null ) { while ( true ) { result = previousValue + request.getIncrement(); if ( cache.replace( idSourceKey, previousValue, result ) ) { break; } else { previousValue = cache.get( idSourceKey ); } } } break; case SEQUENCE: IgniteAtomicSequence seq = provider.atomicSequence( request.getKey().getMetadata().getName(), request.getInitialValue(), false ); result = seq.getAndAdd( request.getIncrement() ); break; } return result; }
@Override public Number nextValue(NextValueRequest request) { throw new UnsupportedOperationException("not yet supported"); }