Add support for ClickHouse in `DatabaseDriver` enum

See gh-42815
This commit is contained in:
Dmytro Nosan 2024-10-21 23:15:20 +03:00 committed by Phillip Webb
parent 3f7e9d8592
commit 1796c20017
5 changed files with 31 additions and 4 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -62,8 +62,8 @@ class BatchDataSourceScriptDatabaseInitializerTests {
} }
@ParameterizedTest @ParameterizedTest
@EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, @EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, names = { "CLICKHOUSE", "FIREBIRD", "INFORMIX",
names = { "FIREBIRD", "INFORMIX", "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" }) "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
void batchSchemaCanBeLocated(DatabaseDriver driver) throws SQLException { void batchSchemaCanBeLocated(DatabaseDriver driver) throws SQLException {
DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
BatchProperties properties = new BatchProperties(); BatchProperties properties = new BatchProperties();

View File

@ -205,6 +205,17 @@ bom {
site("https://github.com/FasterXML/java-classmate") 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}") { library("Commons Codec", "${commonsCodecVersion}") {
group("commons-codec") { group("commons-codec") {
modules = [ modules = [

View File

@ -22,6 +22,7 @@ dependencies {
api("org.springframework:spring-context") api("org.springframework:spring-context")
optional("ch.qos.logback:logback-classic") optional("ch.qos.logback:logback-classic")
optional("com.clickhouse:clickhouse-jdbc")
optional("com.fasterxml.jackson.core:jackson-databind") optional("com.fasterxml.jackson.core:jackson-databind")
optional("com.h2database:h2") optional("com.h2database:h2")
optional("com.google.code.gson:gson") optional("com.google.code.gson:gson")

View File

@ -205,6 +205,17 @@ public enum DatabaseDriver {
return Collections.singleton("tc"); return Collections.singleton("tc");
} }
},
/**
* ClickHouse.
* @since 3.4.0
*/
CLICKHOUSE("ClickHouse", "com.clickhouse.jdbc.ClickHouseDriver", null, "SELECT 1") {
@Override
protected Collection<String> getUrlPrefixes() {
return Arrays.asList("ch", "clickhouse");
}
}; };
private final String productName; private final String productName;

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -84,6 +84,7 @@ class DatabaseDriverTests {
assertThat(DatabaseDriver.fromProductName("Teradata")).isEqualTo(DatabaseDriver.TERADATA); assertThat(DatabaseDriver.fromProductName("Teradata")).isEqualTo(DatabaseDriver.TERADATA);
assertThat(DatabaseDriver.fromProductName("Informix Dynamic Server")).isEqualTo(DatabaseDriver.INFORMIX); assertThat(DatabaseDriver.fromProductName("Informix Dynamic Server")).isEqualTo(DatabaseDriver.INFORMIX);
assertThat(DatabaseDriver.fromProductName("Apache Phoenix")).isEqualTo(DatabaseDriver.PHOENIX); assertThat(DatabaseDriver.fromProductName("Apache Phoenix")).isEqualTo(DatabaseDriver.PHOENIX);
assertThat(DatabaseDriver.fromProductName("ClickHouse")).isEqualTo(DatabaseDriver.CLICKHOUSE);
} }
@Test @Test
@ -117,6 +118,9 @@ class DatabaseDriverTests {
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:phoenix:localhost")).isEqualTo(DatabaseDriver.PHOENIX); assertThat(DatabaseDriver.fromJdbcUrl("jdbc:phoenix:localhost")).isEqualTo(DatabaseDriver.PHOENIX);
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:tc:mysql://localhost:3306/sample")) assertThat(DatabaseDriver.fromJdbcUrl("jdbc:tc:mysql://localhost:3306/sample"))
.isEqualTo(DatabaseDriver.TESTCONTAINERS); .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);
} }
} }