Skip to content

Commit b322b19

Browse files
committed
Clarify scope of DataSourceInitializedEvent
This commit clarifies that DataSourceInitializedEvent is only to be used by the datasource initializer facility and JPA (Hibernate). The even is renamed to DataSourceSchemaCreatedEvent to clarify what it actually signals. Closes gh-4292
1 parent 6635b6a commit b322b19

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
/**
3030
* Bean to handle {@link DataSource} initialization by running {@literal schema-*.sql} on
3131
* {@link InitializingBean#afterPropertiesSet()} and {@literal data-*.sql} SQL scripts on
32-
* a {@link DataSourceInitializedEvent}.
32+
* a {@link DataSourceSchemaCreatedEvent}.
3333
*
3434
* @author Stephane Nicoll
3535
* @see DataSourceAutoConfiguration
3636
*/
3737
class DataSourceInitializerInvoker
38-
implements ApplicationListener<DataSourceInitializedEvent>, InitializingBean {
38+
implements ApplicationListener<DataSourceSchemaCreatedEvent>, InitializingBean {
3939

4040
private static final Log logger = LogFactory.getLog(DataSourceInitializerInvoker.class);
4141

@@ -65,7 +65,7 @@ public void afterPropertiesSet() {
6565
if (schemaCreated) {
6666
try {
6767
this.applicationContext
68-
.publishEvent(new DataSourceInitializedEvent(
68+
.publishEvent(new DataSourceSchemaCreatedEvent(
6969
initializer.getDataSource()));
7070
// The listener might not be registered yet, so don't rely on it.
7171
if (!this.initialized) {
@@ -82,7 +82,7 @@ public void afterPropertiesSet() {
8282
}
8383

8484
@Override
85-
public void onApplicationEvent(DataSourceInitializedEvent event) {
85+
public void onApplicationEvent(DataSourceSchemaCreatedEvent event) {
8686
// NOTE the event can happen more than once and
8787
// the event datasource is not used here
8888
DataSourceInitializer initializer = getDataSourceInitializer();
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2017 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.
@@ -21,22 +21,21 @@
2121
import org.springframework.context.ApplicationEvent;
2222

2323
/**
24-
* {@link ApplicationEvent} used internally to trigger {@link DataSource} initialization.
25-
* Initialization can occur when {@literal schema-*.sql} files are executed or when
26-
* external libraries (e.g. JPA) initialize the database.
24+
* {@link ApplicationEvent} used internally to indicate that the schema of a new
25+
* {@link DataSource} has been created. This happens when {@literal schema-*.sql} files
26+
* are executed or when Hibernate initializes the database.
2727
*
2828
* @author Dave Syer
29-
* @see DataSourceInitializer
3029
* @since 1.1.0
3130
*/
3231
@SuppressWarnings("serial")
33-
public class DataSourceInitializedEvent extends ApplicationEvent {
32+
public class DataSourceSchemaCreatedEvent extends ApplicationEvent {
3433

3534
/**
36-
* Create a new {@link DataSourceInitializedEvent}.
35+
* Create a new {@link DataSourceSchemaCreatedEvent}.
3736
* @param source the source {@link DataSource}.
3837
*/
39-
public DataSourceInitializedEvent(DataSource source) {
38+
public DataSourceSchemaCreatedEvent(DataSource source) {
4039
super(source);
4140
}
4241

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/DataSourceInitializedPublisher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
import org.springframework.beans.factory.config.BeanPostProcessor;
2828
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2929
import org.springframework.beans.factory.support.GenericBeanDefinition;
30-
import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializedEvent;
30+
import org.springframework.boot.autoconfigure.jdbc.DataSourceSchemaCreatedEvent;
3131
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
3232
import org.springframework.context.ApplicationContext;
3333
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
3434
import org.springframework.core.type.AnnotationMetadata;
3535

3636
/**
37-
* {@link BeanPostProcessor} used to fire {@link DataSourceInitializedEvent}s. Should only
38-
* be registered via the inner {@link Registrar} class.
37+
* {@link BeanPostProcessor} used to fire {@link DataSourceSchemaCreatedEvent}s. Should
38+
* only be registered via the inner {@link Registrar} class.
3939
*
4040
* @author Dave Syer
4141
* @since 1.1.0
@@ -75,7 +75,7 @@ private void publishEventIfRequired(EntityManagerFactory entityManagerFactory) {
7575
DataSource dataSource = findDataSource(entityManagerFactory);
7676
if (dataSource != null && isInitializingDatabase(dataSource)) {
7777
this.applicationContext
78-
.publishEvent(new DataSourceInitializedEvent(dataSource));
78+
.publishEvent(new DataSourceSchemaCreatedEvent(dataSource));
7979
}
8080
}
8181

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private ContextConsumer<AssertableApplicationContext> assertInitializationIsDisa
177177
return context -> {
178178
assertThat(context).hasSingleBean(DataSource.class);
179179
DataSource dataSource = context.getBean(DataSource.class);
180-
context.publishEvent(new DataSourceInitializedEvent(dataSource));
180+
context.publishEvent(new DataSourceSchemaCreatedEvent(dataSource));
181181
assertDataSourceNotInitialized(dataSource);
182182
};
183183
}

0 commit comments

Comments
 (0)