HibernateSequentialNumberCounterStore implements SequentialNumberCounterStore { @Override public List<Integer> getNextValues( String uid, String key, int length ) { int count = (int) sessionFactory.getCurrentSession() .createNativeQuery( "SELECT * FROM incrementSequentialCounter(?0, ?1, ?2)" ) .setParameter( 0, uid ) .setParameter( 1, key ) .setParameter( 2, length ) .uniqueResult(); return IntStream.range( count - length, length + (count - length) ).boxed().collect( Collectors.toList() ); } HibernateSequentialNumberCounterStore( SessionFactory sessionFactory ); @Override List<Integer> getNextValues( String uid, String key, int length ); @Override void deleteCounter( String uid );  }
@Test public void getNextValues() { List<Integer> result = dummyService.getNextValues( "ABC", "ABC-#", 3 ); assertEquals( 3, result.size() ); assertTrue( result.contains( 1 ) ); assertTrue( result.contains( 2 ) ); assertTrue( result.contains( 3 ) ); result = dummyService.getNextValues( "ABC", "ABC-#", 50 ); assertEquals( 50, result.size() ); assertTrue( result.contains( 4 ) ); assertTrue( result.contains( 5 ) ); assertTrue( result.contains( 52 ) ); assertTrue( result.contains( 53 ) ); }