本文整理汇总了Java中org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer.setDataSource方法的典型用法代码示例。如果您正苦于以下问题:Java MySQLMaxValueIncrementer.setDataSource方法的具体用法?Java MySQLMaxValueIncrementer.setDataSource怎么用?Java MySQLMaxValueIncrementer.setDataSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer
的用法示例。
在下文中一共展示了MySQLMaxValueIncrementer.setDataSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMySQLMaxValueIncrementer
import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer; //导入方法依赖的package包/类
@Test
public void testMySQLMaxValueIncrementer() throws SQLException {
given(dataSource.getConnection()).willReturn(connection);
given(connection.createStatement()).willReturn(statement);
given(statement.executeQuery("select last_insert_id()")).willReturn(resultSet);
given(resultSet.next()).willReturn(true);
given(resultSet.getLong(1)).willReturn(2L, 4L);
MySQLMaxValueIncrementer incrementer = new MySQLMaxValueIncrementer();
incrementer.setDataSource(dataSource);
incrementer.setIncrementerName("myseq");
incrementer.setColumnName("seq");
incrementer.setCacheSize(2);
incrementer.setPaddingLength(1);
incrementer.afterPropertiesSet();
assertEquals(1, incrementer.nextIntValue());
assertEquals(2, incrementer.nextLongValue());
assertEquals("3", incrementer.nextStringValue());
assertEquals(4, incrementer.nextLongValue());
verify(statement, times(2)).executeUpdate("update myseq set seq = last_insert_id(seq + 2)");
verify(resultSet, times(2)).close();
verify(statement, times(2)).close();
verify(connection, times(2)).close();
}
示例2: testMySQLMaxValueIncrementer
import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer; //导入方法依赖的package包/类
@Test
public void testMySQLMaxValueIncrementer() throws SQLException {
given(dataSource.getConnection()).willReturn(connection);
given(connection.createStatement()).willReturn(statement);
given(statement.executeUpdate("update myseq set seq = last_insert_id(seq + 2)")).willReturn(1);
given(statement.executeQuery("select last_insert_id()")).willReturn(resultSet);
given(resultSet.next()).willReturn(true);
given(resultSet.getLong(1)).willReturn(2L, 4L);
MySQLMaxValueIncrementer incrementer = new MySQLMaxValueIncrementer();
incrementer.setDataSource(dataSource);
incrementer.setIncrementerName("myseq");
incrementer.setColumnName("seq");
incrementer.setCacheSize(2);
incrementer.setPaddingLength(1);
incrementer.afterPropertiesSet();
assertEquals(1, incrementer.nextIntValue());
assertEquals(2, incrementer.nextLongValue());
assertEquals("3", incrementer.nextStringValue());
assertEquals(4, incrementer.nextLongValue());
verify(resultSet, times(2)).close();
verify(statement, times(2)).close();
verify(connection, times(2)).close();
}