Java Code Examples for org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer

The following examples show how to use org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testPostgreSQLSequenceMaxValueIncrementer() throws SQLException {
	given(dataSource.getConnection()).willReturn(connection);
	given(connection.createStatement()).willReturn(statement);
	given(statement.executeQuery("select nextval('myseq')")).willReturn(resultSet);
	given(resultSet.next()).willReturn(true);
	given(resultSet.getLong(1)).willReturn(10L, 12L);

	PostgreSQLSequenceMaxValueIncrementer incrementer = new PostgreSQLSequenceMaxValueIncrementer();
	incrementer.setDataSource(dataSource);
	incrementer.setIncrementerName("myseq");
	incrementer.setPaddingLength(5);
	incrementer.afterPropertiesSet();

	assertEquals("00010", incrementer.nextStringValue());
	assertEquals(12, incrementer.nextIntValue());

	verify(resultSet, times(2)).close();
	verify(statement, times(2)).close();
	verify(connection, times(2)).close();
}
 
Example 2
@Test
public void testPostgreSQLSequenceMaxValueIncrementer() throws SQLException {
	given(dataSource.getConnection()).willReturn(connection);
	given(connection.createStatement()).willReturn(statement);
	given(statement.executeQuery("select nextval('myseq')")).willReturn(resultSet);
	given(resultSet.next()).willReturn(true);
	given(resultSet.getLong(1)).willReturn(10L, 12L);

	PostgreSQLSequenceMaxValueIncrementer incrementer = new PostgreSQLSequenceMaxValueIncrementer();
	incrementer.setDataSource(dataSource);
	incrementer.setIncrementerName("myseq");
	incrementer.setPaddingLength(5);
	incrementer.afterPropertiesSet();

	assertEquals("00010", incrementer.nextStringValue());
	assertEquals(12, incrementer.nextIntValue());

	verify(resultSet, times(2)).close();
	verify(statement, times(2)).close();
	verify(connection, times(2)).close();
}