Skip to content

Commit

Permalink
GH-195 - Remove support for legacy spring.modulith.jdbc-… namespace i…
Browse files Browse the repository at this point in the history
…n JDBC-based event support.
  • Loading branch information
odrotbohm committed Jun 23, 2023
1 parent 3d18606 commit 068916a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@
*/
package org.springframework.modulith.events.jdbc;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.modulith.events.EventSerializer;
import org.springframework.modulith.events.config.EventPublicationConfigurationExtension;
Expand All @@ -54,39 +47,10 @@ JdbcEventPublicationRepository jdbcEventPublicationRepository(JdbcTemplate jdbcT
}

@Bean
@Conditional(SchemaInitializationEnabled.class)
@ConditionalOnProperty(name = "spring.modulith.events.jdbc.schema-initialization.enabled", havingValue = "true")
DatabaseSchemaInitializer databaseSchemaInitializer(JdbcTemplate jdbcTemplate, ResourceLoader resourceLoader,
DatabaseType databaseType) {

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

/**
* Combined condition to support the legacy schema initialization property as well as the new one.
*
* @author Oliver Drotbohm
*/
static class SchemaInitializationEnabled extends SpringBootCondition {

private static final String LEGACY = "spring.modulith.events.jdbc-schema-initialization.enabled";
private static final String CURRENT = "spring.modulith.events.jdbc.schema-initialization.enabled";

/*
* (non-Javadoc)
* @see org.springframework.boot.autoconfigure.condition.SpringBootCondition#getMatchOutcome(org.springframework.context.annotation.ConditionContext, org.springframework.core.type.AnnotatedTypeMetadata)
*/
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {

Environment environment = context.getEnvironment();

var enabled = List.of(CURRENT, LEGACY).stream()
.map(it -> environment.getProperty(it, Boolean.class))
.anyMatch(Boolean.TRUE::equals);

return enabled //
? ConditionOutcome.match("Schema initialization explicitly enabled.") //
: ConditionOutcome.noMatch("Schema initialization disabled by default.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
@SpringBootTest(
classes = TestApplication.class,
properties = "spring.modulith.events.jdbc-schema-initialization.enabled=true")
properties = "spring.modulith.events.jdbc.schema-initialization.enabled=true")
class JdbcEventPublicationAutoConfigurationIntegrationTests {

@Autowired ApplicationContext context;
Expand Down

0 comments on commit 068916a

Please sign in to comment.