|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
28 | 28 | import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
29 | 29 | import org.springframework.jdbc.support.incrementer.HanaSequenceMaxValueIncrementer;
|
30 | 30 | import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer;
|
| 31 | +import org.springframework.jdbc.support.incrementer.MariaDBSequenceMaxValueIncrementer; |
31 | 32 | import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer;
|
32 | 33 | import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
|
33 | 34 | import org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer;
|
|
43 | 44 | *
|
44 | 45 | * @author Juergen Hoeller
|
45 | 46 | * @author Sam Brannen
|
| 47 | + * @author Mahmoud Ben Hassine |
46 | 48 | * @since 27.02.2004
|
47 | 49 | */
|
48 | 50 | class DataFieldMaxValueIncrementerTests {
|
@@ -210,4 +212,26 @@ void postgresSequenceMaxValueIncrementer() throws SQLException {
|
210 | 212 | verify(connection, times(2)).close();
|
211 | 213 | }
|
212 | 214 |
|
| 215 | + @Test |
| 216 | + void mariaDBSequenceMaxValueIncrementer() throws SQLException { |
| 217 | + given(dataSource.getConnection()).willReturn(connection); |
| 218 | + given(connection.createStatement()).willReturn(statement); |
| 219 | + given(statement.executeQuery("select next value for myseq")).willReturn(resultSet); |
| 220 | + given(resultSet.next()).willReturn(true); |
| 221 | + given(resultSet.getLong(1)).willReturn(10L, 12L); |
| 222 | + |
| 223 | + MariaDBSequenceMaxValueIncrementer incrementer = new MariaDBSequenceMaxValueIncrementer(); |
| 224 | + incrementer.setDataSource(dataSource); |
| 225 | + incrementer.setIncrementerName("myseq"); |
| 226 | + incrementer.setPaddingLength(5); |
| 227 | + incrementer.afterPropertiesSet(); |
| 228 | + |
| 229 | + assertThat(incrementer.nextStringValue()).isEqualTo("00010"); |
| 230 | + assertThat(incrementer.nextIntValue()).isEqualTo(12); |
| 231 | + |
| 232 | + verify(resultSet, times(2)).close(); |
| 233 | + verify(statement, times(2)).close(); |
| 234 | + verify(connection, times(2)).close(); |
| 235 | + } |
| 236 | + |
213 | 237 | }
|
0 commit comments