Skip to content

Commit 1796c20

Browse files
nosanphilwebb
authored andcommitted
Add support for ClickHouse in DatabaseDriver enum
See gh-42815
1 parent 3f7e9d8 commit 1796c20

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,8 +62,8 @@ void getSettingsWithPlatformDoesNotTouchDataSource() {
6262
}
6363

6464
@ParameterizedTest
65-
@EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE,
66-
names = { "FIREBIRD", "INFORMIX", "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
65+
@EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, names = { "CLICKHOUSE", "FIREBIRD", "INFORMIX",
66+
"JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
6767
void batchSchemaCanBeLocated(DatabaseDriver driver) throws SQLException {
6868
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
6969
BatchProperties properties = new BatchProperties();

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ bom {
205205
site("https://github.com/FasterXML/java-classmate")
206206
}
207207
}
208+
library("ClickHouse", "0.6.5") {
209+
group("com.clickhouse") {
210+
modules = [
211+
"clickhouse-jdbc"
212+
]
213+
}
214+
links {
215+
site("https://clickhouse.com")
216+
releaseNotes("https://github.com/ClickHouse/clickhouse-java/releases/tag/v{version}")
217+
}
218+
}
208219
library("Commons Codec", "${commonsCodecVersion}") {
209220
group("commons-codec") {
210221
modules = [

spring-boot-project/spring-boot/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies {
2222
api("org.springframework:spring-context")
2323

2424
optional("ch.qos.logback:logback-classic")
25+
optional("com.clickhouse:clickhouse-jdbc")
2526
optional("com.fasterxml.jackson.core:jackson-databind")
2627
optional("com.h2database:h2")
2728
optional("com.google.code.gson:gson")

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ protected Collection<String> getUrlPrefixes() {
205205
return Collections.singleton("tc");
206206
}
207207

208+
},
209+
210+
/**
211+
* ClickHouse.
212+
* @since 3.4.0
213+
*/
214+
CLICKHOUSE("ClickHouse", "com.clickhouse.jdbc.ClickHouseDriver", null, "SELECT 1") {
215+
@Override
216+
protected Collection<String> getUrlPrefixes() {
217+
return Arrays.asList("ch", "clickhouse");
218+
}
208219
};
209220

210221
private final String productName;

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,6 +84,7 @@ void databaseProductNameLookups() {
8484
assertThat(DatabaseDriver.fromProductName("Teradata")).isEqualTo(DatabaseDriver.TERADATA);
8585
assertThat(DatabaseDriver.fromProductName("Informix Dynamic Server")).isEqualTo(DatabaseDriver.INFORMIX);
8686
assertThat(DatabaseDriver.fromProductName("Apache Phoenix")).isEqualTo(DatabaseDriver.PHOENIX);
87+
assertThat(DatabaseDriver.fromProductName("ClickHouse")).isEqualTo(DatabaseDriver.CLICKHOUSE);
8788
}
8889

8990
@Test
@@ -117,6 +118,9 @@ void databaseJdbcUrlLookups() {
117118
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:phoenix:localhost")).isEqualTo(DatabaseDriver.PHOENIX);
118119
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:tc:mysql://localhost:3306/sample"))
119120
.isEqualTo(DatabaseDriver.TESTCONTAINERS);
121+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:clickhouse://localhost:3306/sample"))
122+
.isEqualTo(DatabaseDriver.CLICKHOUSE);
123+
assertThat(DatabaseDriver.fromJdbcUrl("jdbc:ch://localhost:3306/sample")).isEqualTo(DatabaseDriver.CLICKHOUSE);
120124
}
121125

122126
}

0 commit comments

Comments
 (0)