diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java index 7b39ada35e1a..2c55352cee32 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java @@ -47,7 +47,7 @@ public H2SequenceMaxValueIncrementer(DataSource dataSource, String incrementerNa @Override protected String getSequenceQuery() { - return "select " + getIncrementerName() + ".nextval from dual"; + return "values next value for " + getIncrementerName(); } } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java new file mode 100644 index 000000000000..66804b529224 --- /dev/null +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementerTests.java @@ -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"); + } + +} diff --git a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema-without-separator.sql b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema-without-separator.sql index 4a4dc97f2fbe..19af16cc04ee 100644 --- a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema-without-separator.sql +++ b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema-without-separator.sql @@ -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 ) \ No newline at end of file diff --git a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql index 80ffe23da9ad..523c4a7c2b19 100644 --- a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql +++ b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql @@ -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 ); diff --git a/spring-jdbc/src/test/resources/org/springframework/jdbc/support/incrementer/schema.sql b/spring-jdbc/src/test/resources/org/springframework/jdbc/support/incrementer/schema.sql new file mode 100644 index 000000000000..b74b576ab837 --- /dev/null +++ b/spring-jdbc/src/test/resources/org/springframework/jdbc/support/incrementer/schema.sql @@ -0,0 +1 @@ +CREATE SEQUENCE SEQ; \ No newline at end of file diff --git a/spring-r2dbc/src/test/resources/org/springframework/r2dbc/connection/init/users-schema.sql b/spring-r2dbc/src/test/resources/org/springframework/r2dbc/connection/init/users-schema.sql index 80ffe23da9ad..523c4a7c2b19 100644 --- a/spring-r2dbc/src/test/resources/org/springframework/r2dbc/connection/init/users-schema.sql +++ b/spring-r2dbc/src/test/resources/org/springframework/r2dbc/connection/init/users-schema.sql @@ -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 ); diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-schema.sql b/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-schema.sql index 3dee075af5f0..d8ded6eff4b4 100644 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-schema.sql +++ b/spring-test/src/test/resources/org/springframework/test/context/junit4/orm/db-schema.sql @@ -2,7 +2,7 @@ DROP TABLE drivers_license IF EXISTS; DROP TABLE person IF EXISTS; CREATE TABLE person ( - id INTEGER NOT NULL IDENTITY, + id INTEGER GENERATED BY DEFAULT AS IDENTITY, name VARCHAR(50) NOT NULL, drivers_license_id INTEGER NOT NULL ); @@ -10,7 +10,7 @@ CREATE UNIQUE INDEX person_name ON person(name); CREATE UNIQUE INDEX person_drivers_license_id ON person(drivers_license_id); CREATE TABLE drivers_license ( - id INTEGER NOT NULL IDENTITY, + id INTEGER GENERATED BY DEFAULT AS IDENTITY, license_number INTEGER NOT NULL ); CREATE UNIQUE INDEX drivers_license_license_number ON drivers_license(license_number); diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql b/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql index da1ce4b8c982..2407ffa5edc1 100644 --- a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql +++ b/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql @@ -1,3 +1,3 @@ CREATE TABLE enigma ( - id INTEGER NOT NULL IDENTITY + id INTEGER GENERATED BY DEFAULT AS IDENTITY );