parent
39f24f0244
commit
210019cad1
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,11 +19,11 @@ package org.springframework.jdbc.support.incrementer;
|
|||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* {@link DataFieldMaxValueIncrementer} that retrieves the next value
|
||||
* of a given MariaDB sequence.
|
||||
* {@link DataFieldMaxValueIncrementer} that retrieves the next value of a given
|
||||
* MariaDB sequence.
|
||||
*
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 6.0.0
|
||||
* @since 6.0
|
||||
*/
|
||||
public class MariaDBSequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer {
|
||||
|
||||
|
|
|
@ -168,6 +168,28 @@ class DataFieldMaxValueIncrementerTests {
|
|||
verify(connection, times(2)).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void mariaDBSequenceMaxValueIncrementer() throws SQLException {
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
given(connection.createStatement()).willReturn(statement);
|
||||
given(statement.executeQuery("select next value for myseq")).willReturn(resultSet);
|
||||
given(resultSet.next()).willReturn(true);
|
||||
given(resultSet.getLong(1)).willReturn(10L, 12L);
|
||||
|
||||
MariaDBSequenceMaxValueIncrementer incrementer = new MariaDBSequenceMaxValueIncrementer();
|
||||
incrementer.setDataSource(dataSource);
|
||||
incrementer.setIncrementerName("myseq");
|
||||
incrementer.setPaddingLength(5);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("00010");
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(12);
|
||||
|
||||
verify(resultSet, times(2)).close();
|
||||
verify(statement, times(2)).close();
|
||||
verify(connection, times(2)).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void oracleSequenceMaxValueIncrementer() throws SQLException {
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
|
@ -212,26 +234,4 @@ class DataFieldMaxValueIncrementerTests {
|
|||
verify(connection, times(2)).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void mariaDBSequenceMaxValueIncrementer() throws SQLException {
|
||||
given(dataSource.getConnection()).willReturn(connection);
|
||||
given(connection.createStatement()).willReturn(statement);
|
||||
given(statement.executeQuery("select next value for myseq")).willReturn(resultSet);
|
||||
given(resultSet.next()).willReturn(true);
|
||||
given(resultSet.getLong(1)).willReturn(10L, 12L);
|
||||
|
||||
MariaDBSequenceMaxValueIncrementer incrementer = new MariaDBSequenceMaxValueIncrementer();
|
||||
incrementer.setDataSource(dataSource);
|
||||
incrementer.setIncrementerName("myseq");
|
||||
incrementer.setPaddingLength(5);
|
||||
incrementer.afterPropertiesSet();
|
||||
|
||||
assertThat(incrementer.nextStringValue()).isEqualTo("00010");
|
||||
assertThat(incrementer.nextIntValue()).isEqualTo(12);
|
||||
|
||||
verify(resultSet, times(2)).close();
|
||||
verify(statement, times(2)).close();
|
||||
verify(connection, times(2)).close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue