Skip to content

Commit

Permalink
GH-457 - Upgrade to Spring Boot 3.3 snapshots.
Browse files Browse the repository at this point in the history
Move of previously deprecated DatabaseDriver.fromDataSource(…) and inline functionality for now. Remove obsolete spring.version property from build descriptor.
  • Loading branch information
odrotbohm committed Jan 17, 2024
1 parent c4e6e86 commit d238121
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
9 changes: 4 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
<lombok.version>1.18.30</lombok.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.version>6.1.0</spring.version> <!-- For Javadoc links only -->
<spring-framework.version>6.1.2</spring-framework.version>
<spring-boot.version>3.2.1</spring-boot.version>
<spring-boot.version>3.3.0-SNAPSHOT</spring-boot.version>
<spring-framework.version>6.1.2</spring-framework.version> <!-- For Javadoc links only -->
<spring-cloud-aws-bom.version>3.1.0</spring-cloud-aws-bom.version>

</properties>
Expand All @@ -65,7 +64,7 @@
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
<comments>
Copyright 2022-2023 the original author or authors.
Copyright 2022-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.
Expand Down Expand Up @@ -452,7 +451,7 @@ limitations under the License.
<quiet>true</quiet>
<links>
<link>https://docs.spring.io/spring-boot/docs/${spring-boot.version}/api/</link>
<link>https://docs.spring.io/spring/docs/${spring.version}/javadoc-api/</link>
<link>https://docs.spring.io/spring/docs/${spring-framework.version}/javadoc-api/</link>
<link>https://docs.oracle.com/en/java/javase/17/docs/api/</link>
</links>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
package org.springframework.modulith.events.jdbc;

import java.util.Map;
import java.util.Arrays;
import java.util.UUID;

import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -47,22 +46,12 @@ UUID databaseToUUID(Object id) {

POSTGRES("postgresql");

private static final Map<DatabaseDriver, DatabaseType> DATABASE_DRIVER_TO_DATABASE_TYPE_MAP = //
Map.of( //
DatabaseDriver.H2, H2, //
DatabaseDriver.HSQLDB, HSQLDB, //
DatabaseDriver.POSTGRESQL, POSTGRES, //
DatabaseDriver.MYSQL, MYSQL);
static DatabaseType from(String productName) {

static DatabaseType from(DatabaseDriver databaseDriver) {

var databaseType = DATABASE_DRIVER_TO_DATABASE_TYPE_MAP.get(databaseDriver);

if (databaseType == null) {
throw new IllegalArgumentException("Unsupported database type: " + databaseDriver);
}

return databaseType;
return Arrays.stream(DatabaseType.values())
.filter(it -> it.value.equalsIgnoreCase(productName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported database type: " + productName));
}

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
*/
package org.springframework.modulith.events.jdbc;

import java.sql.DatabaseMetaData;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.modulith.events.config.EventPublicationAutoConfiguration;
import org.springframework.modulith.events.config.EventPublicationConfigurationExtension;
import org.springframework.modulith.events.core.EventSerializer;
Expand All @@ -39,7 +41,7 @@ class JdbcEventPublicationAutoConfiguration implements EventPublicationConfigura

@Bean
DatabaseType databaseType(DataSource dataSource) {
return DatabaseType.from(DatabaseDriver.fromDataSource(dataSource));
return DatabaseType.from(fromDataSource(dataSource));
}

@Bean
Expand All @@ -56,4 +58,18 @@ DatabaseSchemaInitializer databaseSchemaInitializer(JdbcTemplate jdbcTemplate, R

return new DatabaseSchemaInitializer(jdbcTemplate, resourceLoader, databaseType);
}

private static String fromDataSource(DataSource dataSource) {

String name = null;

try {

var metadata = JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName);
name = JdbcUtils.commonDatabaseName(metadata);

} catch (Exception o_O) {}

return name == null ? "UNKNOWN" : name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.springframework.boot.jdbc.DatabaseDriver;

class DatabaseTypeUnitTests {

@Test // GH-29
void shouldThrowExceptionOnUnsupportedDatabaseType() {

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> DatabaseType.from(DatabaseDriver.UNKNOWN))
.isThrownBy(() -> DatabaseType.from("UNKNOWN"))
.withMessageContaining("UNKNOWN");
}
}
3 changes: 1 addition & 2 deletions spring-modulith-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
<properties>
<java.version>17</java.version>
<jmolecules.version>2023.1.1</jmolecules.version>
<spring-framework.version>6.1.2</spring-framework.version>
<spring-boot.version>3.2.1</spring-boot.version>
<spring-boot.version>3.3.0-SNAPSHOT</spring-boot.version>
</properties>

<build>
Expand Down

0 comments on commit d238121

Please sign in to comment.