Skip to content

Commit 45c9fc0

Browse files
committed
Merge pull request #42815 from nosan
* pr/42815: Polish 'Add support for ClickHouse in `DatabaseDriver` enum' Add support for ClickHouse in `DatabaseDriver` enum Closes gh-42815
2 parents 3f7e9d8 + 3d47cb7 commit 45c9fc0

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-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-parent/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ bom {
3333
]
3434
}
3535
}
36+
library("ClickHouse", "0.6.5") {
37+
group("com.clickhouse") {
38+
modules = [
39+
"clickhouse-jdbc"
40+
]
41+
}
42+
}
3643
library("Commons Compress", "1.25.0") {
3744
group("org.apache.commons") {
3845
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ 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+
216+
@Override
217+
protected Collection<String> getUrlPrefixes() {
218+
return Arrays.asList("ch", "clickhouse");
219+
}
220+
208221
};
209222

210223
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)