From f500f3689906d11374a9e6c37802f206f8e0ed74 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Mon, 21 Oct 2024 23:15:20 +0300 Subject: [PATCH] Add support for ClickHouse JDBC driver in enum DatabaseDriver --- ...BatchDataSourceScriptDatabaseInitializerTests.java | 6 +++--- .../spring-boot-dependencies/build.gradle | 11 +++++++++++ spring-boot-project/spring-boot/build.gradle | 1 + .../org/springframework/boot/jdbc/DatabaseDriver.java | 11 +++++++++++ .../boot/jdbc/DatabaseDriverTests.java | 6 +++++- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java index 87a87f90c460..724fda601a68 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 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. @@ -62,8 +62,8 @@ void getSettingsWithPlatformDoesNotTouchDataSource() { } @ParameterizedTest - @EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, - names = { "FIREBIRD", "INFORMIX", "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" }) + @EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, names = { "CLICKHOUSE", "FIREBIRD", "INFORMIX", + "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" }) void batchSchemaCanBeLocated(DatabaseDriver driver) throws SQLException { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); BatchProperties properties = new BatchProperties(); diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index ce382ada117b..036895327803 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -205,6 +205,17 @@ bom { site("https://github.com/FasterXML/java-classmate") } } + library("ClickHouse", "0.6.5") { + group("com.clickhouse") { + modules = [ + "clickhouse-jdbc" + ] + } + links { + site("https://clickhouse.com") + releaseNotes("https://github.com/ClickHouse/clickhouse-java/releases/tag/v{version}") + } + } library("Commons Codec", "${commonsCodecVersion}") { group("commons-codec") { modules = [ diff --git a/spring-boot-project/spring-boot/build.gradle b/spring-boot-project/spring-boot/build.gradle index d48ecf65950f..8e538638db39 100644 --- a/spring-boot-project/spring-boot/build.gradle +++ b/spring-boot-project/spring-boot/build.gradle @@ -22,6 +22,7 @@ dependencies { api("org.springframework:spring-context") optional("ch.qos.logback:logback-classic") + optional("com.clickhouse:clickhouse-jdbc") optional("com.fasterxml.jackson.core:jackson-databind") optional("com.h2database:h2") optional("com.google.code.gson:gson") diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java index 0ef89b5ffcfd..0fb5233393df 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java @@ -205,6 +205,17 @@ protected Collection getUrlPrefixes() { return Collections.singleton("tc"); } + }, + + /** + * ClickHouse. + * @since 3.4.0 + */ + CLICKHOUSE("ClickHouse", "com.clickhouse.jdbc.ClickHouseDriver", null, "SELECT 1") { + @Override + protected Collection getUrlPrefixes() { + return Arrays.asList("ch", "clickhouse"); + } }; private final String productName; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java index 7ca5f44c904e..9f60004fd678 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 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. @@ -84,6 +84,7 @@ void databaseProductNameLookups() { assertThat(DatabaseDriver.fromProductName("Teradata")).isEqualTo(DatabaseDriver.TERADATA); assertThat(DatabaseDriver.fromProductName("Informix Dynamic Server")).isEqualTo(DatabaseDriver.INFORMIX); assertThat(DatabaseDriver.fromProductName("Apache Phoenix")).isEqualTo(DatabaseDriver.PHOENIX); + assertThat(DatabaseDriver.fromProductName("ClickHouse")).isEqualTo(DatabaseDriver.CLICKHOUSE); } @Test @@ -117,6 +118,9 @@ void databaseJdbcUrlLookups() { assertThat(DatabaseDriver.fromJdbcUrl("jdbc:phoenix:localhost")).isEqualTo(DatabaseDriver.PHOENIX); assertThat(DatabaseDriver.fromJdbcUrl("jdbc:tc:mysql://localhost:3306/sample")) .isEqualTo(DatabaseDriver.TESTCONTAINERS); + assertThat(DatabaseDriver.fromJdbcUrl("jdbc:clickhouse://localhost:3306/sample")) + .isEqualTo(DatabaseDriver.CLICKHOUSE); + assertThat(DatabaseDriver.fromJdbcUrl("jdbc:ch://localhost:3306/sample")).isEqualTo(DatabaseDriver.CLICKHOUSE); } }