From e6ff3859ed6532f967f67806bdb471b34daac04a Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Mon, 16 May 2022 13:55:31 +0200 Subject: [PATCH] Drop support for H2 1.x. Closes #1243 --- pom.xml | 2 +- ...WithTimeZoneToOffsetDateTimeConverter.java | 63 ------------------- .../data/jdbc/core/dialect/JdbcH2Dialect.java | 63 ------------------- .../repository/config/DialectResolver.java | 4 +- .../jdbc/core/dialect/JdbcH2DialectTests.java | 50 --------------- ...bcAggregateTemplateIntegrationTests-h2.sql | 8 +-- .../relational/core/dialect/H2Dialect.java | 10 +-- 7 files changed, 9 insertions(+), 191 deletions(-) delete mode 100644 spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/H2TimestampWithTimeZoneToOffsetDateTimeConverter.java delete mode 100644 spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcH2Dialect.java delete mode 100644 spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/JdbcH2DialectTests.java diff --git a/pom.xml b/pom.xml index f18481d2..298dcb73 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 11.5.7.0 - 1.4.200 + 2.1.212 2.6.1 2.7.5 9.2.1.jre8 diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/H2TimestampWithTimeZoneToOffsetDateTimeConverter.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/H2TimestampWithTimeZoneToOffsetDateTimeConverter.java deleted file mode 100644 index 76876764..00000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/H2TimestampWithTimeZoneToOffsetDateTimeConverter.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2021 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.core.dialect; - -import java.time.OffsetDateTime; -import java.time.ZoneOffset; - -import org.h2.api.TimestampWithTimeZone; -import org.springframework.core.convert.converter.Converter; -import org.springframework.data.convert.ReadingConverter; - -/** - * Converter converting from an H2 internal representation of a timestamp with time zone to an OffsetDateTime. - * - * Only required for H2 versions < 2.0 - * - * @author Jens Schauder - * @since 2.7 - */ -@ReadingConverter -public enum H2TimestampWithTimeZoneToOffsetDateTimeConverter - implements Converter { - - INSTANCE; - - @Override - public OffsetDateTime convert(TimestampWithTimeZone source) { - - long nanosInSecond = 1_000_000_000; - long nanosInMinute = nanosInSecond * 60; - long nanosInHour = nanosInMinute * 60; - - long hours = (source.getNanosSinceMidnight() / nanosInHour); - - long nanosInHours = hours * nanosInHour; - long nanosLeft = source.getNanosSinceMidnight() - nanosInHours; - long minutes = nanosLeft / nanosInMinute; - - long nanosInMinutes = minutes * nanosInMinute; - nanosLeft -= nanosInMinutes; - long seconds = nanosLeft / nanosInSecond; - - long nanosInSeconds = seconds * nanosInSecond; - nanosLeft -= nanosInSeconds; - ZoneOffset offset = ZoneOffset.ofTotalSeconds(source.getTimeZoneOffsetSeconds()); - - return OffsetDateTime.of(source.getYear(), source.getMonth(), source.getDay(), (int) hours, (int) minutes, - (int) seconds, (int) nanosLeft, offset); - } -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcH2Dialect.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcH2Dialect.java deleted file mode 100644 index 15807ff4..00000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcH2Dialect.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2021 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.core.dialect; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.springframework.data.relational.core.dialect.Db2Dialect; -import org.springframework.data.relational.core.dialect.H2Dialect; - -/** - * {@link Db2Dialect} that registers JDBC specific converters. - * - * @author Jens Schauder - * @author Christoph Strobl - * @since 2.3 - */ -public class JdbcH2Dialect extends H2Dialect { - - public static JdbcH2Dialect INSTANCE = new JdbcH2Dialect(); - - protected JdbcH2Dialect() {} - - @Override - public Collection getConverters() { - - final Collection originalConverters = super.getConverters(); - - if (isH2belowVersion2()) { - - List converters = new ArrayList<>(originalConverters); - converters.add(H2TimestampWithTimeZoneToOffsetDateTimeConverter.INSTANCE); - return converters; - } - - return originalConverters; - } - - static boolean isH2belowVersion2() { - - try { - - JdbcH2Dialect.class.getClassLoader().loadClass("org.h2.api.TimestampWithTimeZone"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } -} 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 2f7b3670..ef3e2725 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 @@ -29,11 +29,11 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.dao.NonTransientDataAccessException; import org.springframework.data.jdbc.core.dialect.JdbcDb2Dialect; -import org.springframework.data.jdbc.core.dialect.JdbcH2Dialect; import org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect; import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect; import org.springframework.data.jdbc.core.dialect.JdbcSqlServerDialect; import org.springframework.data.relational.core.dialect.Dialect; +import org.springframework.data.relational.core.dialect.H2Dialect; import org.springframework.data.relational.core.dialect.HsqlDbDialect; import org.springframework.data.relational.core.dialect.MariaDbDialect; import org.springframework.data.relational.core.dialect.OracleDialect; @@ -119,7 +119,7 @@ public class DialectResolver { return HsqlDbDialect.INSTANCE; } if (name.contains("h2")) { - return JdbcH2Dialect.INSTANCE; + return H2Dialect.INSTANCE; } if (name.contains("mysql")) { return new JdbcMySqlDialect(getIdentifierProcessing(metaData)); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/JdbcH2DialectTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/JdbcH2DialectTests.java deleted file mode 100644 index a971d31b..00000000 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/JdbcH2DialectTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2021 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.core.dialect; - -import static org.assertj.core.api.Assertions.*; - -import java.time.OffsetDateTime; - -import org.h2.api.TimestampWithTimeZone; -import org.h2.util.DateTimeUtils; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link JdbcH2Dialect}. - * - * @author Jens Schauder - */ -class JdbcH2DialectTests { - - @Test - void TimestampWithTimeZone2OffsetDateTimeConverterConvertsProperly() { - - H2TimestampWithTimeZoneToOffsetDateTimeConverter converter = H2TimestampWithTimeZoneToOffsetDateTimeConverter.INSTANCE; - long dateValue = 123456789; - long timeNanos = 987654321; - int timeZoneOffsetSeconds = 4 * 60 * 60; - TimestampWithTimeZone timestampWithTimeZone = new TimestampWithTimeZone(dateValue, timeNanos, - timeZoneOffsetSeconds); - - OffsetDateTime offsetDateTime = converter.convert(timestampWithTimeZone); - - assertThat(offsetDateTime.getOffset().getTotalSeconds()).isEqualTo(timeZoneOffsetSeconds); - assertThat(offsetDateTime.getNano()).isEqualTo(timeNanos); - assertThat(offsetDateTime.toEpochSecond()) - .isEqualTo(DateTimeUtils.getEpochSeconds(dateValue, timeNanos, timeZoneOffsetSeconds)); - } -} diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-h2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-h2.sql index 2773ba72..73e85c0d 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-h2.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.core/JdbcAggregateTemplateIntegrationTests-h2.sql @@ -42,8 +42,8 @@ CREATE TABLE element_no_id CREATE TABLE "ARRAY_OWNER" ( ID SERIAL PRIMARY KEY, - DIGITS ARRAY[10] NOT NULL, - MULTIDIMENSIONAL ARRAY[10] NULL + DIGITS VARCHAR(30) ARRAY[10] NOT NULL, + MULTIDIMENSIONAL VARCHAR(30) ARRAY[10] NULL ); CREATE TABLE BYTE_ARRAY_OWNER @@ -55,13 +55,13 @@ CREATE TABLE BYTE_ARRAY_OWNER CREATE TABLE DOUBLE_LIST_OWNER ( ID SERIAL PRIMARY KEY, - DIGITS ARRAY[10] + DIGITS DOUBLE ARRAY[10] ); CREATE TABLE FLOAT_LIST_OWNER ( ID SERIAL PRIMARY KEY, - DIGITS ARRAY[10] + DIGITS FLOAT ARRAY[10] ); CREATE TABLE CHAIN4 diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/H2Dialect.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/H2Dialect.java index 37ed9c8d..879aa8ec 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/H2Dialect.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/H2Dialect.java @@ -30,6 +30,7 @@ import org.springframework.util.ClassUtils; * @author Mark Paluch * @author Myeonghyeon Lee * @author Christph Strobl + * @author Jens Schauder * @since 2.0 */ public class H2Dialect extends AbstractDialect { @@ -105,13 +106,6 @@ public class H2Dialect extends AbstractDialect { @Override public Set> simpleTypes() { - if (!ClassUtils.isPresent("org.h2.api.TimestampWithTimeZone", getClass().getClassLoader())) { - return Collections.emptySet(); - } - try { - return Collections.singleton(ClassUtils.forName("org.h2.api.TimestampWithTimeZone", getClass().getClassLoader())); - } catch (ClassNotFoundException e) { - throw new IllegalStateException(e); - } + return Collections.emptySet(); } }