Skip to content

Commit d238121

Browse files
committed
GH-457 - Upgrade to Spring Boot 3.3 snapshots.
Move of previously deprecated DatabaseDriver.fromDataSource(…) and inline functionality for now. Remove obsolete spring.version property from build descriptor.
1 parent c4e6e86 commit d238121

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

pom.xml

+4-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@
4040
<lombok.version>1.18.30</lombok.version>
4141
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4242
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
43-
<spring.version>6.1.0</spring.version> <!-- For Javadoc links only -->
44-
<spring-framework.version>6.1.2</spring-framework.version>
45-
<spring-boot.version>3.2.1</spring-boot.version>
43+
<spring-boot.version>3.3.0-SNAPSHOT</spring-boot.version>
44+
<spring-framework.version>6.1.2</spring-framework.version> <!-- For Javadoc links only -->
4645
<spring-cloud-aws-bom.version>3.1.0</spring-cloud-aws-bom.version>
4746

4847
</properties>
@@ -65,7 +64,7 @@
6564
<name>Apache License, Version 2.0</name>
6665
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
6766
<comments>
68-
Copyright 2022-2023 the original author or authors.
67+
Copyright 2022-2024 the original author or authors.
6968

7069
Licensed under the Apache License, Version 2.0 (the "License");
7170
you may not use this file except in compliance with the License.
@@ -452,7 +451,7 @@ limitations under the License.
452451
<quiet>true</quiet>
453452
<links>
454453
<link>https://docs.spring.io/spring-boot/docs/${spring-boot.version}/api/</link>
455-
<link>https://docs.spring.io/spring/docs/${spring.version}/javadoc-api/</link>
454+
<link>https://docs.spring.io/spring/docs/${spring-framework.version}/javadoc-api/</link>
456455
<link>https://docs.oracle.com/en/java/javase/17/docs/api/</link>
457456
</links>
458457
</configuration>

spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/DatabaseType.java

+6-17
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*/
1616
package org.springframework.modulith.events.jdbc;
1717

18-
import java.util.Map;
18+
import java.util.Arrays;
1919
import java.util.UUID;
2020

21-
import org.springframework.boot.jdbc.DatabaseDriver;
2221
import org.springframework.util.Assert;
2322

2423
/**
@@ -47,22 +46,12 @@ UUID databaseToUUID(Object id) {
4746

4847
POSTGRES("postgresql");
4948

50-
private static final Map<DatabaseDriver, DatabaseType> DATABASE_DRIVER_TO_DATABASE_TYPE_MAP = //
51-
Map.of( //
52-
DatabaseDriver.H2, H2, //
53-
DatabaseDriver.HSQLDB, HSQLDB, //
54-
DatabaseDriver.POSTGRESQL, POSTGRES, //
55-
DatabaseDriver.MYSQL, MYSQL);
49+
static DatabaseType from(String productName) {
5650

57-
static DatabaseType from(DatabaseDriver databaseDriver) {
58-
59-
var databaseType = DATABASE_DRIVER_TO_DATABASE_TYPE_MAP.get(databaseDriver);
60-
61-
if (databaseType == null) {
62-
throw new IllegalArgumentException("Unsupported database type: " + databaseDriver);
63-
}
64-
65-
return databaseType;
51+
return Arrays.stream(DatabaseType.values())
52+
.filter(it -> it.value.equalsIgnoreCase(productName))
53+
.findFirst()
54+
.orElseThrow(() -> new IllegalArgumentException("Unsupported database type: " + productName));
6655
}
6756

6857
private final String value;

spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationAutoConfiguration.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
*/
1616
package org.springframework.modulith.events.jdbc;
1717

18+
import java.sql.DatabaseMetaData;
19+
1820
import javax.sql.DataSource;
1921

2022
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
2123
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
22-
import org.springframework.boot.jdbc.DatabaseDriver;
2324
import org.springframework.context.annotation.Bean;
2425
import org.springframework.context.annotation.Configuration;
2526
import org.springframework.core.io.ResourceLoader;
2627
import org.springframework.jdbc.core.JdbcTemplate;
28+
import org.springframework.jdbc.support.JdbcUtils;
2729
import org.springframework.modulith.events.config.EventPublicationAutoConfiguration;
2830
import org.springframework.modulith.events.config.EventPublicationConfigurationExtension;
2931
import org.springframework.modulith.events.core.EventSerializer;
@@ -39,7 +41,7 @@ class JdbcEventPublicationAutoConfiguration implements EventPublicationConfigura
3941

4042
@Bean
4143
DatabaseType databaseType(DataSource dataSource) {
42-
return DatabaseType.from(DatabaseDriver.fromDataSource(dataSource));
44+
return DatabaseType.from(fromDataSource(dataSource));
4345
}
4446

4547
@Bean
@@ -56,4 +58,18 @@ DatabaseSchemaInitializer databaseSchemaInitializer(JdbcTemplate jdbcTemplate, R
5658

5759
return new DatabaseSchemaInitializer(jdbcTemplate, resourceLoader, databaseType);
5860
}
61+
62+
private static String fromDataSource(DataSource dataSource) {
63+
64+
String name = null;
65+
66+
try {
67+
68+
var metadata = JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName);
69+
name = JdbcUtils.commonDatabaseName(metadata);
70+
71+
} catch (Exception o_O) {}
72+
73+
return name == null ? "UNKNOWN" : name;
74+
}
5975
}

spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/DatabaseTypeUnitTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import static org.assertj.core.api.Assertions.*;
1919

2020
import org.junit.jupiter.api.Test;
21-
import org.springframework.boot.jdbc.DatabaseDriver;
2221

2322
class DatabaseTypeUnitTests {
2423

2524
@Test // GH-29
2625
void shouldThrowExceptionOnUnsupportedDatabaseType() {
2726

2827
assertThatExceptionOfType(IllegalArgumentException.class)
29-
.isThrownBy(() -> DatabaseType.from(DatabaseDriver.UNKNOWN))
28+
.isThrownBy(() -> DatabaseType.from("UNKNOWN"))
3029
.withMessageContaining("UNKNOWN");
3130
}
3231
}

spring-modulith-examples/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
<properties>
2727
<java.version>17</java.version>
2828
<jmolecules.version>2023.1.1</jmolecules.version>
29-
<spring-framework.version>6.1.2</spring-framework.version>
30-
<spring-boot.version>3.2.1</spring-boot.version>
29+
<spring-boot.version>3.3.0-SNAPSHOT</spring-boot.version>
3130
</properties>
3231

3332
<build>

0 commit comments

Comments
 (0)