diff --git a/Jenkinsfile b/Jenkinsfile index 95554dd87..bb0a945e7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,6 +29,7 @@ pipeline { } options { timeout(time: 30, unit: 'MINUTES') } steps { + sh './accept-third-party-license.sh' sh 'mkdir -p /tmp/jenkins-home' sh 'chown -R 1001:1001 .' sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,all-dbs clean dependency:list test -Dsort -U -B' @@ -55,6 +56,7 @@ pipeline { } options { timeout(time: 30, unit: 'MINUTES') } steps { + sh './accept-third-party-license.sh' sh 'mkdir -p /tmp/jenkins-home' sh 'chown -R 1001:1001 .' sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,all-dbs,java11 clean dependency:list test -Dsort -U -B' @@ -73,7 +75,8 @@ pipeline { } options { timeout(time: 30, unit: 'MINUTES') } steps { - sh 'mkdir -p /tmp/jenkins-home' + sh './accept-third-party-license.sh' + sh 'mkdir -p /tmp/jenkins-home' sh 'chown -R 1001:1001 .' sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,all-dbs,java11 clean dependency:list test -Dsort -U -B' sh 'chown -R 1001:1001 .' diff --git a/accept-third-party-license.sh b/accept-third-party-license.sh new file mode 100755 index 000000000..efc815ac4 --- /dev/null +++ b/accept-third-party-license.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +{ + echo "mcr.microsoft.com/mssql/server:2017-CU12" + echo "ibmcom/db2:11.5.0.0a" +} > spring-data-jdbc/src/test/resources/container-license-acceptance.txt \ No newline at end of file diff --git a/pom.xml b/pom.xml index f6359158d..2c60a0816 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ 0.1.4 + 11.5.0.0 1.4.200 2.2.8 7.0.0.jre8 @@ -170,6 +171,24 @@ + + db2-test + test + + test + + + + **/*IntegrationTests.java + + + **/*HsqlIntegrationTests.java + + + db2 + + + diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index 1fdf3e615..2fe841462 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -186,6 +186,12 @@ test + + com.ibm.db2 + jcc + 11.1.4.4 + + de.schauderhaft.degraph degraph-check @@ -223,6 +229,12 @@ test + + org.testcontainers + db2 + test + + diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/DialectResolver.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/DialectResolver.java index 2784e7e97..7aca7c53f 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/DialectResolver.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/DialectResolver.java @@ -26,6 +26,7 @@ import javax.sql.DataSource; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.data.relational.core.dialect.Db2Dialect; import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.dialect.H2Dialect; import org.springframework.data.relational.core.dialect.HsqlDbDialect; @@ -123,7 +124,9 @@ public class DialectResolver { if (name.contains("microsoft")) { return SqlServerDialect.INSTANCE; } - + if (name.contains("db2")) { + return Db2Dialect.INSTANCE; + } return null; } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java index c406fc9ec..0b260c182 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java @@ -514,6 +514,7 @@ public class JdbcAggregateTemplateIntegrationTests { assumeNot("mysql"); assumeNot("mariadb"); assumeNot("mssql"); + assumeNot("db2"); ArrayOwner arrayOwner = new ArrayOwner(); arrayOwner.digits = new String[] { "one", "two", "three" }; @@ -539,6 +540,7 @@ public class JdbcAggregateTemplateIntegrationTests { assumeNot("mariadb"); assumeNot("mssql"); assumeNot("hsqldb"); + assumeNot("db2"); ArrayOwner arrayOwner = new ArrayOwner(); arrayOwner.multidimensional = new String[][] { { "one-a", "two-a", "three-a" }, { "one-b", "two-b", "three-b" } }; @@ -563,6 +565,7 @@ public class JdbcAggregateTemplateIntegrationTests { assumeNot("mysql"); assumeNot("mariadb"); assumeNot("mssql"); + assumeNot("db2"); ListOwner arrayOwner = new ListOwner(); arrayOwner.digits.addAll(Arrays.asList("one", "two", "three")); @@ -586,6 +589,7 @@ public class JdbcAggregateTemplateIntegrationTests { assumeNot("mysql"); assumeNot("mariadb"); assumeNot("mssql"); + assumeNot("db2"); SetOwner setOwner = new SetOwner(); setOwner.digits.addAll(Arrays.asList("one", "two", "three")); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java similarity index 83% rename from spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationIntegrationTests.java rename to spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java index 7524bc0df..e90cc12f7 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/QueryAnnotationHsqlIntegrationTests.java @@ -19,18 +19,16 @@ import static org.assertj.core.api.Assertions.*; import lombok.Value; -import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.Date; import java.util.List; import java.util.Optional; import java.util.stream.Stream; -import org.junit.Assume; +import org.assertj.core.api.SoftAssertions; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -42,7 +40,7 @@ import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; import org.springframework.lang.Nullable; -import org.springframework.test.annotation.ProfileValueUtils; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.transaction.annotation.Transactional; @@ -55,7 +53,8 @@ import org.springframework.transaction.annotation.Transactional; * @author Mark Paluch */ @Transactional -public class QueryAnnotationIntegrationTests { +@ActiveProfiles("hsql") +public class QueryAnnotationHsqlIntegrationTests { @Configuration @Import(TestConfiguration.class) @@ -64,7 +63,7 @@ public class QueryAnnotationIntegrationTests { @Bean Class testClass() { - return QueryAnnotationIntegrationTests.class; + return QueryAnnotationHsqlIntegrationTests.class; } } @@ -76,8 +75,6 @@ public class QueryAnnotationIntegrationTests { @Test // DATAJDBC-164 public void executeCustomQueryWithoutParameter() { - assumeNot("mysql"); - repository.save(dummyEntity("Example")); repository.save(dummyEntity("example")); repository.save(dummyEntity("EXAMPLE")); @@ -180,8 +177,6 @@ public class QueryAnnotationIntegrationTests { @Test // DATAJDBC-175 public void executeCustomQueryWithReturnTypeIsNumber() { - assumeNot("mysql"); - repository.save(dummyEntity("aaa")); repository.save(dummyEntity("bbb")); repository.save(dummyEntity("cac")); @@ -194,40 +189,29 @@ public class QueryAnnotationIntegrationTests { @Test // DATAJDBC-175 public void executeCustomQueryWithReturnTypeIsBoolean() { - assumeNot("mysql"); - repository.save(dummyEntity("aaa")); repository.save(dummyEntity("bbb")); repository.save(dummyEntity("cac")); - assertThat(repository.existsByNameContaining("a")).isTrue(); - assertThat(repository.existsByNameContaining("d")).isFalse(); + SoftAssertions.assertSoftly(softly -> { + + softly.assertThat(repository.existsByNameContaining("a")).describedAs("entities with A in the name").isTrue(); + softly.assertThat(repository.existsByNameContaining("d")).describedAs("entities with D in the name").isFalse(); + }); } @Test // DATAJDBC-175 public void executeCustomQueryWithReturnTypeIsDate() { - assumeNot("mysql"); - - // Since Timestamp extends Date the repository returns the Timestamp as it comes from the database. - // Trying to compare that to an actual Date results in non deterministic results, so we have to use an actual - // Timestamp. - Date now = new Timestamp(System.currentTimeMillis()); - assertThat(repository.nowWithDate()).isAfterOrEqualsTo(now); - + assertThat(repository.nowWithDate()).isInstanceOf(Date.class); } @Test // DATAJDBC-175 public void executeCustomQueryWithReturnTypeIsLocalDateTimeList() { - // mysql does not support plain VALUES(…) - assumeNot("mysql"); - - LocalDateTime preciseNow = LocalDateTime.now(); - LocalDateTime truncatedNow = truncateSubmillis(preciseNow); - - repository.nowWithLocalDateTimeList() // - .forEach(d -> assertThat(d).isAfterOrEqualTo(truncatedNow)); + assertThat(repository.nowWithLocalDateTimeList()) // + .hasSize(2) // + .allSatisfy(d -> assertThat(d).isInstanceOf(LocalDateTime.class)); } @Test // DATAJDBC-182 @@ -270,19 +254,9 @@ public class QueryAnnotationIntegrationTests { @Test // DATAJDBC-175 public void executeCustomQueryWithImmutableResultType() { - // mysql does not support plain VALUES(…) - - assumeNot("mysql"); - assertThat(repository.immutableTuple()).isEqualTo(new DummyEntityRepository.ImmutableTuple("one", "two", 3)); } - private static LocalDateTime truncateSubmillis(LocalDateTime now) { - - int NANOS_IN_MILLIS = 1_000_000; - return now.withNano((now.getNano() / NANOS_IN_MILLIS) * 1_000_000); - } - private DummyEntity dummyEntity(String name) { DummyEntity entity = new DummyEntity(); @@ -290,13 +264,6 @@ public class QueryAnnotationIntegrationTests { return entity; } - private static void assumeNot(String dbProfileName) { - - Assume.assumeTrue( - "true".equalsIgnoreCase(ProfileValueUtils.retrieveProfileValueSource(QueryAnnotationIntegrationTests.class) - .get("current.database.is.not." + dbProfileName))); - } - private static class DummyEntity { @Id Long id; @@ -327,11 +294,11 @@ public class QueryAnnotationIntegrationTests { Stream findAllWithReturnTypeIsStream(); // DATAJDBC-175 - @Query("SELECT count(*) FROM DUMMY_ENTITY WHERE name like '%' || :name || '%'") + @Query("SELECT count(*) FROM DUMMY_ENTITY WHERE name like concat('%', :name, '%')") int countByNameContaining(@Param("name") String name); // DATAJDBC-175 - @Query("SELECT count(*) FROM DUMMY_ENTITY WHERE name like '%' || :name || '%'") + @Query("SELECT case when count(*) > 0 THEN 'true' ELSE 'false' END FROM DUMMY_ENTITY WHERE name like '%' || :name || '%'") boolean existsByNameContaining(@Param("name") String name); // DATAJDBC-175 @@ -358,7 +325,7 @@ public class QueryAnnotationIntegrationTests { void insert(@Param("name") String name); // DATAJDBC-252 - @Query("SELECT 'one' one, 'two' two, 3 three FROM (VALUES (0))") + @Query("SELECT 'one' one, 'two' two, 3 three FROM (VALUES (0)) as tableName") ImmutableTuple immutableTuple(); @Value diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/Db2DataSourceConfiguration.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/Db2DataSourceConfiguration.java new file mode 100644 index 000000000..b025b372d --- /dev/null +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/Db2DataSourceConfiguration.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 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.data.jdbc.testing; + +import javax.sql.DataSource; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.testcontainers.containers.Db2Container; + +/** + * {@link DataSource} setup for DB2. + * + * @author Jens Schauder + * @author Oliver Gierke + */ +@Configuration +@Profile("db2") +class Db2DataSourceConfiguration extends DataSourceConfiguration { + + private static final Db2Container DB_2_CONTAINER = new Db2Container(); + + static { + DB_2_CONTAINER.start(); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource() + */ + @Override + protected DataSource createDataSource() { + + DriverManagerDataSource dataSource = new DriverManagerDataSource(DB_2_CONTAINER.getJdbcUrl(), + DB_2_CONTAINER.getUsername(), DB_2_CONTAINER.getPassword()); + + return dataSource; + } + + @Override + protected void customizePopulator(ResourceDatabasePopulator populator) { + populator.setIgnoreFailedDrops(true); + } +} diff --git a/spring-data-jdbc/src/test/resources/container-license-acceptance.txt b/spring-data-jdbc/src/test/resources/container-license-acceptance.txt deleted file mode 100644 index ce512af36..000000000 --- a/spring-data-jdbc/src/test/resources/container-license-acceptance.txt +++ /dev/null @@ -1 +0,0 @@ -mcr.microsoft.com/mssql/server:2017-CU12 \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-db2.sql new file mode 100644 index 000000000..fde21b0de --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-db2.sql @@ -0,0 +1,307 @@ +CREATE TABLE LEGO_SET +( + "id1" BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, + NAME VARCHAR(30) +); +CREATE TABLE MANUAL +( + "id2" BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, + LEGO_SET BIGINT, + "alternative" BIGINT, + CONTENT VARCHAR(2000) +); + +ALTER TABLE MANUAL + ADD FOREIGN KEY (LEGO_SET) + REFERENCES LEGO_SET ("id1"); + +CREATE TABLE ONE_TO_ONE_PARENT +( + "id3" BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, + content VARCHAR(30) +); +CREATE TABLE Child_No_Id +( + ONE_TO_ONE_PARENT INTEGER NOT NULL PRIMARY KEY, + content VARCHAR(30) +); + +CREATE TABLE LIST_PARENT +( + "id4" BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, + NAME VARCHAR(100) +); +CREATE TABLE ELEMENT_NO_ID +( + CONTENT VARCHAR(100), + LIST_PARENT_KEY BIGINT, + LIST_PARENT BIGINT +); +ALTER TABLE ELEMENT_NO_ID + ADD FOREIGN KEY (LIST_PARENT) + REFERENCES LIST_PARENT ("id4"); +-- +-- CREATE TABLE ARRAY_OWNER +-- ( +-- ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, +-- DIGITS VARCHAR(20) ARRAY[10] NOT NULL, +-- MULTIDIMENSIONAL VARCHAR(20) ARRAY[10] NULL +-- ); + +CREATE TABLE BYTE_ARRAY_OWNER +( + ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, + BINARY_DATA VARBINARY(20) NOT NULL +); + +CREATE TABLE CHAIN4 +( + FOUR BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 40) PRIMARY KEY, + FOUR_VALUE VARCHAR(20) +); + +CREATE TABLE CHAIN3 +( + THREE BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 30) PRIMARY KEY, + THREE_VALUE VARCHAR(20), + CHAIN4 BIGINT, + FOREIGN KEY (CHAIN4) REFERENCES CHAIN4 (FOUR) +); + +CREATE TABLE CHAIN2 +( + TWO BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 20) PRIMARY KEY, + TWO_VALUE VARCHAR(20), + CHAIN3 BIGINT, + FOREIGN KEY (CHAIN3) REFERENCES CHAIN3 (THREE) +); + +CREATE TABLE CHAIN1 +( + ONE BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 10) PRIMARY KEY, + ONE_VALUE VARCHAR(20), + CHAIN2 BIGINT, + FOREIGN KEY (CHAIN2) REFERENCES CHAIN2 (TWO) +); + +CREATE TABLE CHAIN0 +( + ZERO BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0) PRIMARY KEY, + ZERO_VALUE VARCHAR(20), + CHAIN1 BIGINT, + FOREIGN KEY (CHAIN1) REFERENCES CHAIN1 (ONE) +); + +CREATE TABLE NO_ID_CHAIN4 +( + FOUR BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 40) PRIMARY KEY, + FOUR_VALUE VARCHAR(20) +); + +CREATE TABLE NO_ID_CHAIN3 +( + THREE_VALUE VARCHAR(20), + NO_ID_CHAIN4 BIGINT, + FOREIGN KEY (NO_ID_CHAIN4) REFERENCES NO_ID_CHAIN4 (FOUR) +); + +CREATE TABLE NO_ID_CHAIN2 +( + TWO_VALUE VARCHAR(20), + NO_ID_CHAIN4 BIGINT, + FOREIGN KEY (NO_ID_CHAIN4) REFERENCES NO_ID_CHAIN4 (FOUR) +); + +CREATE TABLE NO_ID_CHAIN1 +( + ONE_VALUE VARCHAR(20), + NO_ID_CHAIN4 BIGINT, + FOREIGN KEY (NO_ID_CHAIN4) REFERENCES NO_ID_CHAIN4 (FOUR) +); + +CREATE TABLE NO_ID_CHAIN0 +( + ZERO_VALUE VARCHAR(20), + NO_ID_CHAIN4 BIGINT, + FOREIGN KEY (NO_ID_CHAIN4) REFERENCES NO_ID_CHAIN4 (FOUR) +); + + +CREATE TABLE NO_ID_LIST_CHAIN4 +( + FOUR BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 40) PRIMARY KEY, + FOUR_VALUE VARCHAR(20) +); + +CREATE TABLE NO_ID_LIST_CHAIN3 +( + THREE_VALUE VARCHAR(20), + NO_ID_LIST_CHAIN4 BIGINT NOT NULL, + NO_ID_LIST_CHAIN4_KEY BIGINT NOT NULL, + PRIMARY KEY (NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY), + FOREIGN KEY (NO_ID_LIST_CHAIN4) REFERENCES NO_ID_LIST_CHAIN4 (FOUR) +); + +CREATE TABLE NO_ID_LIST_CHAIN2 +( + TWO_VALUE VARCHAR(20), + NO_ID_LIST_CHAIN4 BIGINT NOT NULL, + NO_ID_LIST_CHAIN4_KEY BIGINT NOT NULL, + NO_ID_LIST_CHAIN3_KEY BIGINT NOT NULL, + PRIMARY KEY (NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY, + NO_ID_LIST_CHAIN3_KEY), + FOREIGN KEY ( + NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY + ) REFERENCES NO_ID_LIST_CHAIN3 ( + NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY + ) +); + +CREATE TABLE NO_ID_LIST_CHAIN1 +( + ONE_VALUE VARCHAR(20), + NO_ID_LIST_CHAIN4 BIGINT NOT NULL, + NO_ID_LIST_CHAIN4_KEY BIGINT NOT NULL, + NO_ID_LIST_CHAIN3_KEY BIGINT NOT NULL, + NO_ID_LIST_CHAIN2_KEY BIGINT NOT NULL, + PRIMARY KEY (NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY, + NO_ID_LIST_CHAIN3_KEY, + NO_ID_LIST_CHAIN2_KEY), + FOREIGN KEY ( + NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY, + NO_ID_LIST_CHAIN3_KEY + ) REFERENCES NO_ID_LIST_CHAIN2 ( + NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY, + NO_ID_LIST_CHAIN3_KEY + ) +); + +CREATE TABLE NO_ID_LIST_CHAIN0 +( + ZERO_VALUE VARCHAR(20), + NO_ID_LIST_CHAIN4 BIGINT NOT NULL, + NO_ID_LIST_CHAIN4_KEY BIGINT NOT NULL, + NO_ID_LIST_CHAIN3_KEY BIGINT NOT NULL, + NO_ID_LIST_CHAIN2_KEY BIGINT NOT NULL, + NO_ID_LIST_CHAIN1_KEY BIGINT NOT NULL, + PRIMARY KEY (NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY, + NO_ID_LIST_CHAIN3_KEY, + NO_ID_LIST_CHAIN2_KEY, + NO_ID_LIST_CHAIN1_KEY), + FOREIGN KEY ( + NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY, + NO_ID_LIST_CHAIN3_KEY, + NO_ID_LIST_CHAIN2_KEY + ) REFERENCES NO_ID_LIST_CHAIN1 ( + NO_ID_LIST_CHAIN4, + NO_ID_LIST_CHAIN4_KEY, + NO_ID_LIST_CHAIN3_KEY, + NO_ID_LIST_CHAIN2_KEY + ) +); + + + + +CREATE TABLE NO_ID_MAP_CHAIN4 +( + FOUR BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 40) PRIMARY KEY, + FOUR_VALUE VARCHAR(20) +); + +CREATE TABLE NO_ID_MAP_CHAIN3 +( + THREE_VALUE VARCHAR(20), + NO_ID_MAP_CHAIN4 BIGINT NOT NULL, + NO_ID_MAP_CHAIN4_KEY VARCHAR(20) NOT NULL, + PRIMARY KEY (NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY), + FOREIGN KEY (NO_ID_MAP_CHAIN4) REFERENCES NO_ID_MAP_CHAIN4 (FOUR) +); + +CREATE TABLE NO_ID_MAP_CHAIN2 +( + TWO_VALUE VARCHAR(20), + NO_ID_MAP_CHAIN4 BIGINT NOT NULL, + NO_ID_MAP_CHAIN4_KEY VARCHAR(20) NOT NULL, + NO_ID_MAP_CHAIN3_KEY VARCHAR(20) NOT NULL, + PRIMARY KEY (NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY, + NO_ID_MAP_CHAIN3_KEY), + FOREIGN KEY ( + NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY + ) REFERENCES NO_ID_MAP_CHAIN3 ( + NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY + ) +); + +CREATE TABLE NO_ID_MAP_CHAIN1 +( + ONE_VALUE VARCHAR(20), + NO_ID_MAP_CHAIN4 BIGINT NOT NULL, + NO_ID_MAP_CHAIN4_KEY VARCHAR(20) NOT NULL, + NO_ID_MAP_CHAIN3_KEY VARCHAR(20) NOT NULL, + NO_ID_MAP_CHAIN2_KEY VARCHAR(20) NOT NULL, + PRIMARY KEY (NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY, + NO_ID_MAP_CHAIN3_KEY, + NO_ID_MAP_CHAIN2_KEY), + FOREIGN KEY ( + NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY, + NO_ID_MAP_CHAIN3_KEY + ) REFERENCES NO_ID_MAP_CHAIN2 ( + NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY, + NO_ID_MAP_CHAIN3_KEY + ) +); + +CREATE TABLE NO_ID_MAP_CHAIN0 +( + ZERO_VALUE VARCHAR(20), + NO_ID_MAP_CHAIN4 BIGINT NOT NULL, + NO_ID_MAP_CHAIN4_KEY VARCHAR(20) NOT NULL, + NO_ID_MAP_CHAIN3_KEY VARCHAR(20) NOT NULL, + NO_ID_MAP_CHAIN2_KEY VARCHAR(20) NOT NULL, + NO_ID_MAP_CHAIN1_KEY VARCHAR(20) NOT NULL, + PRIMARY KEY (NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY, + NO_ID_MAP_CHAIN3_KEY, + NO_ID_MAP_CHAIN2_KEY, + NO_ID_MAP_CHAIN1_KEY), + FOREIGN KEY ( + NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY, + NO_ID_MAP_CHAIN3_KEY, + NO_ID_MAP_CHAIN2_KEY + ) REFERENCES NO_ID_MAP_CHAIN1 ( + NO_ID_MAP_CHAIN4, + NO_ID_MAP_CHAIN4_KEY, + NO_ID_MAP_CHAIN3_KEY, + NO_ID_MAP_CHAIN2_KEY + ) +); + +CREATE TABLE WITH_READ_ONLY ( + ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 40) PRIMARY KEY, + NAME VARCHAR(200), + READ_ONLY VARCHAR(200) DEFAULT 'from-db' +); + +CREATE TABLE VERSIONED_AGGREGATE +( + ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, + VERSION BIGINT +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-db2.sql new file mode 100644 index 000000000..660512ca7 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-db2.sql @@ -0,0 +1,3 @@ +DROP TABLE Dummy_entity; + +CREATE TABLE Dummy_Entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY) \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-h2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationHsqlIntegrationTests-hsql.sql similarity index 100% rename from spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-h2.sql rename to spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationHsqlIntegrationTests-hsql.sql diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-hsql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-hsql.sql deleted file mode 100644 index 12c793eaa..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-hsql.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, NAME VARCHAR(100)) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-mariadb.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-mariadb.sql deleted file mode 100644 index dd786b053..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-mariadb.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE dummy_entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-mysql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-mysql.sql deleted file mode 100644 index dd786b053..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-mysql.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE TABLE dummy_entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-postgres.sql deleted file mode 100644 index c8c5fb08f..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.query/QueryAnnotationIntegrationTests-postgres.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE IF EXISTS dummy_entity; -CREATE TABLE dummy_entity ( id SERIAL PRIMARY KEY, NAME VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryCustomConversionIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryCustomConversionIntegrationTests-db2.sql new file mode 100644 index 000000000..5707b888a --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryCustomConversionIntegrationTests-db2.sql @@ -0,0 +1,3 @@ +DROP TABLE ENTITY_WITH_STRINGY_BIG_DECIMAL; + +CREATE TABLE ENTITY_WITH_STRINGY_BIG_DECIMAL ( id BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY, Stringy_number DECIMAL(20,10)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedImmutableIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedImmutableIntegrationTests-db2.sql new file mode 100644 index 000000000..05b12dccb --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedImmutableIntegrationTests-db2.sql @@ -0,0 +1,2 @@ +DROP TABLE dummy_entity; +CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, PREFIX_ATTR1 BIGINT, PREFIX_ATTR2 VARCHAR(100)) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedIntegrationTests-db2.sql new file mode 100644 index 000000000..1e790d582 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedIntegrationTests-db2.sql @@ -0,0 +1,2 @@ +DROP TABLE dummy_entity; +CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, TEST VARCHAR(100), PREFIX2_ATTR BIGINT, PREFIX_TEST VARCHAR(100), PREFIX_PREFIX2_ATTR BIGINT); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-db2.sql new file mode 100644 index 000000000..1a7174511 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests-db2.sql @@ -0,0 +1,5 @@ +DROP TABLE dummy_entity; +DROP TABLE dummy_entity2; + +CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, TEST VARCHAR(100)); +CREATE TABLE dummy_entity2 ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, TEST VARCHAR(100), PREFIX_ATTR BIGINT) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests-db2.sql new file mode 100644 index 000000000..3d3b73d80 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithCollectionIntegrationTests-db2.sql @@ -0,0 +1,16 @@ +DROP TABLE dummy_entity; +DROP TABLE dummy_entity2; + +CREATE TABLE dummy_entity +( + id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, + TEST VARCHAR(100), + PREFIX_TEST VARCHAR(100) +); +CREATE TABLE dummy_entity2 +( + id BIGINT NOT NULL, + ORDER_KEY BIGINT NOT NULL, + TEST VARCHAR(100), + PRIMARY KEY (id, ORDER_KEY) +) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests-db2.sql new file mode 100644 index 000000000..99fb0d624 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests-db2.sql @@ -0,0 +1,14 @@ +DROP TABLE dummy_entity; +DROP TABLE dummy_entity2; + +CREATE TABLE dummy_entity +( + ID BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, + TEST VARCHAR(100), + PREFIX_TEST VARCHAR(100) +); +CREATE TABLE dummy_entity2 +( + ID BIGINT, + TEST VARCHAR(100) +) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-db2.sql new file mode 100644 index 000000000..9ced33535 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-db2.sql @@ -0,0 +1,7 @@ +DROP TABLE ReadOnlyIdEntity; +DROP TABLE PrimitiveIdEntity; +DROP TABLE ImmutableWithManualIdentity; + +CREATE TABLE ReadOnlyIdEntity (ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE PrimitiveIdEntity (ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE ImmutableWithManualIdentity (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryInsertExistingIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryInsertExistingIntegrationTests-db2.sql new file mode 100644 index 000000000..acbf9d5ed --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryInsertExistingIntegrationTests-db2.sql @@ -0,0 +1,3 @@ +DROP TABLE dummy_entity; + +CREATE TABLE dummy_entity ( id_Prop BIGINT PRIMARY KEY, NAME VARCHAR(100)) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql new file mode 100644 index 000000000..358bcbbbd --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql @@ -0,0 +1,8 @@ +DROP TABLE dummy_entity; + +CREATE TABLE dummy_entity +( + id_Prop BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, + NAME VARCHAR(100), + POINT_IN_TIME TIMESTAMP +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-h2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-h2.sql deleted file mode 100644 index 616c4a8c8..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-h2.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(1), log BIGINT); -CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-hsql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-hsql.sql deleted file mode 100644 index 616c4a8c8..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-hsql.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(1), log BIGINT); -CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql deleted file mode 100644 index f536225ed..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE TABLE dummy_entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(1), log BIGINT); -CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mssql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mssql.sql deleted file mode 100644 index 45ef8bd9a..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mssql.sql +++ /dev/null @@ -1,4 +0,0 @@ -DROP TABLE IF EXISTS dummy_entity; -DROP TABLE IF EXISTS log; -CREATE TABLE dummy_entity ( id BIGINT IDENTITY PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(1), log BIGINT); -CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mysql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mysql.sql deleted file mode 100644 index f536225ed..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mysql.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE TABLE dummy_entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(1), log BIGINT); -CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-postgres.sql deleted file mode 100644 index 4ce926eca..000000000 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-postgres.sql +++ /dev/null @@ -1,4 +0,0 @@ -DROP TABLE dummy_entity; -DROP TABLE log; -CREATE TABLE dummy_entity ( id SERIAL PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(5), log BIGINT); -CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql new file mode 100644 index 000000000..9ddb7fe3f --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-db2.sql @@ -0,0 +1,11 @@ +DROP TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS; + +CREATE TABLE ENTITY_WITH_COLUMNS_REQUIRING_CONVERSIONS ( + id_Timestamp DATETIME NOT NULL PRIMARY KEY, + bool boolean, SOME_ENUM VARCHAR(100), + big_Decimal VARCHAR(100), + big_Integer BIGINT, + date DATETIME, + local_Date_Time DATETIME, + zoned_Date_Time VARCHAR(30) +); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryResultSetExtractorIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryResultSetExtractorIntegrationTests-db2.sql new file mode 100644 index 000000000..3d31bbc1e --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryResultSetExtractorIntegrationTests-db2.sql @@ -0,0 +1,7 @@ +DROP TABLE address; +DROP TABLE person; + + +CREATE TABLE person ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, name VARCHAR(100)); +CREATE TABLE address ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, street VARCHAR(100), person_id BIGINT); +ALTER TABLE address ADD FOREIGN KEY (person_id) REFERENCES person(id); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-db2.sql new file mode 100644 index 000000000..1d2e74739 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-db2.sql @@ -0,0 +1,5 @@ +DROP TABLE element; +DROP TABLE dummy_entity; + +CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE element (id BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, content VARCHAR(100), dummy_entity BIGINT); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-db2.sql new file mode 100644 index 000000000..5532bbff1 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-db2.sql @@ -0,0 +1,5 @@ +DROP TABLE element; +DROP TABLE dummy_entity; + +CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE element (id BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, content VARCHAR(100), Dummy_Entity_key BIGINT, dummy_entity BIGINT); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-db2.sql new file mode 100644 index 000000000..4c1dc2d72 --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-db2.sql @@ -0,0 +1,9 @@ +DROP TABLE element; +DROP TABLE dummy_entity; + +CREATE TABLE dummy_entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE element (id BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, content VARCHAR(100), Dummy_Entity_key VARCHAR(100), dummy_entity BIGINT); + +ALTER TABLE ELEMENT + ADD FOREIGN KEY (dummy_entity) + REFERENCES dummy_entity(id); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests-db2.sql new file mode 100644 index 000000000..5bc12b55e --- /dev/null +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests-db2.sql @@ -0,0 +1,3 @@ +DROP TABLE car; + +CREATE TABLE car ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, model VARCHAR(100)); diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests-h2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests-h2.sql index 9d5026bc6..7306fe6b3 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests-h2.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/StringBasedJdbcQueryMappingConfigurationIntegrationTests-h2.sql @@ -1 +1,4 @@ +DROP TABLE car; + + CREATE TABLE car ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, model VARCHAR(100)); diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/Db2Dialect.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/Db2Dialect.java new file mode 100644 index 000000000..7d2fef315 --- /dev/null +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/Db2Dialect.java @@ -0,0 +1,87 @@ +/* + * Copyright 2020 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.data.relational.core.dialect; + +import org.springframework.data.relational.core.sql.IdentifierProcessing; + +/** + * An SQL dialect for DB2. + * + * @author Jens Schauder + * @since 2.1 + */ +public class Db2Dialect extends AbstractDialect { + + /** + * Singleton instance. + */ + public static final Db2Dialect INSTANCE = new Db2Dialect(); + + protected Db2Dialect() {} + + private static final LimitClause LIMIT_CLAUSE = new LimitClause() { + + /* + * (non-Javadoc) + * @see org.springframework.data.relational.core.dialect.LimitClause#getLimit(long) + */ + @Override + public String getLimit(long limit) { + return "FIRST " + limit + " ROWS ONLY"; + } + + /* + * (non-Javadoc) + * @see org.springframework.data.relational.core.dialect.LimitClause#getOffset(long) + */ + @Override + public String getOffset(long offset) { + return "OFFSET " + offset + " ROWS"; + } + + /* + * (non-Javadoc) + * @see org.springframework.data.relational.core.dialect.LimitClause#getClause(long, long) + */ + @Override + public String getLimitOffset(long limit, long offset) { + return String.format("OFFSET %d ROWS FETCH FIRST %d ROWS ONLY", offset, limit); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.relational.core.dialect.LimitClause#getClausePosition() + */ + @Override + public Position getClausePosition() { + return Position.AFTER_ORDER_BY; + } + }; + + /* + * (non-Javadoc) + * @see org.springframework.data.relational.core.dialect.Dialect#limit() + */ + @Override + public LimitClause limit() { + return LIMIT_CLAUSE; + } + + @Override + public IdentifierProcessing getIdentifierProcessing() { + return IdentifierProcessing.ANSI; + } +}