-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support H2 1.4 & 2.0 in H2SequenceMaxValueIncrementer
Prior to this commit, H2SequenceMaxValueIncrementer only supported H2 database 1.4. This commit updates H2SequenceMaxValueIncrementer's getSequenceQuery() method so that the syntax used supports version 1.4 and 2.0 of the H2 database. This commit also updates several test schemas so that they work with H2 1.4 and 2.0 as well as HSQL. Closes gh-27870
- Loading branch information
Showing
8 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.jdbc.support.incrementer; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; | ||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Henning Pöttker | ||
*/ | ||
class H2SequenceMaxValueIncrementerTests { | ||
|
||
@Test | ||
void testH2SequenceMaxValueIncrementer() { | ||
DataSource dataSource = new EmbeddedDatabaseBuilder() | ||
.setType(EmbeddedDatabaseType.H2) | ||
.addScript("classpath:/org/springframework/jdbc/support/incrementer/schema.sql") | ||
.build(); | ||
H2SequenceMaxValueIncrementer incrementer = new H2SequenceMaxValueIncrementer(dataSource, "SEQ"); | ||
|
||
assertThat(incrementer.nextIntValue()).isEqualTo(1); | ||
assertThat(incrementer.nextStringValue()).isEqualTo("2"); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...est/resources/org/springframework/jdbc/datasource/init/users-schema-without-separator.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
CREATE TABLE users ( | ||
id INTEGER NOT NULL IDENTITY, | ||
id INTEGER GENERATED BY DEFAULT AS IDENTITY, | ||
first_name VARCHAR(50) NOT NULL, | ||
last_name VARCHAR(50) NOT NULL | ||
) |
2 changes: 1 addition & 1 deletion
2
spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
DROP TABLE users IF EXISTS; | ||
|
||
CREATE TABLE users ( | ||
id INTEGER NOT NULL IDENTITY, | ||
id INTEGER GENERATED BY DEFAULT AS IDENTITY, | ||
first_name VARCHAR(50) NOT NULL, | ||
last_name VARCHAR(50) NOT NULL | ||
); |
1 change: 1 addition & 0 deletions
1
spring-jdbc/src/test/resources/org/springframework/jdbc/support/incrementer/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE SEQUENCE SEQ; |
2 changes: 1 addition & 1 deletion
2
spring-r2dbc/src/test/resources/org/springframework/r2dbc/connection/init/users-schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
DROP TABLE users IF EXISTS; | ||
|
||
CREATE TABLE users ( | ||
id INTEGER NOT NULL IDENTITY, | ||
id INTEGER GENERATED BY DEFAULT AS IDENTITY, | ||
first_name VARCHAR(50) NOT NULL, | ||
last_name VARCHAR(50) NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...est/src/test/resources/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
CREATE TABLE enigma ( | ||
id INTEGER NOT NULL IDENTITY | ||
id INTEGER GENERATED BY DEFAULT AS IDENTITY | ||
); |