org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer Java Examples
The following examples show how to use
org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer.
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
Source File: DataFieldMaxValueIncrementerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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
Source File: DataFieldMaxValueIncrementerTests.java From effectivejava with Apache License 2.0 | 6 votes |
@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(); }