Java 类org.hibernate.ogm.dialect.spi.NextValueRequest 实例源码

项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
@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;
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public Number nextValue(NextValueRequest request) {
    throw new UnsupportedOperationException("not yet supported");
}