mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Rename DatabaseInitialization to DataSourceInitialization
Closes gh-10779
This commit is contained in:
parent
555f51bfdb
commit
b720c2141c
@ -78,9 +78,9 @@ public class BatchAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(DataSource.class)
|
||||
public BatchDatabaseInitializer batchDatabaseInitializer(DataSource dataSource,
|
||||
public BatchDataSourceInitializer batchDataSourceInitializer(DataSource dataSource,
|
||||
ResourceLoader resourceLoader) {
|
||||
return new BatchDatabaseInitializer(dataSource, resourceLoader, this.properties);
|
||||
return new BatchDataSourceInitializer(dataSource, resourceLoader, this.properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.batch;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.jdbc.AbstractDataSourceInitializer;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@ -29,19 +29,19 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public class BatchDatabaseInitializer extends AbstractDatabaseInitializer {
|
||||
public class BatchDataSourceInitializer extends AbstractDataSourceInitializer {
|
||||
|
||||
private final BatchProperties properties;
|
||||
|
||||
public BatchDatabaseInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
||||
BatchProperties properties) {
|
||||
public BatchDataSourceInitializer(DataSource dataSource,
|
||||
ResourceLoader resourceLoader, BatchProperties properties) {
|
||||
super(dataSource, resourceLoader);
|
||||
Assert.notNull(properties, "BatchProperties must not be null");
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DatabaseInitializationMode getMode() {
|
||||
protected DataSourceInitializationMode getMode() {
|
||||
return this.properties.getInitializeSchema();
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.batch;
|
||||
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
|
||||
/**
|
||||
* Configuration properties for Spring Batch.
|
||||
@ -46,7 +46,7 @@ public class BatchProperties {
|
||||
/**
|
||||
* Database schema initialization mode.
|
||||
*/
|
||||
private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
|
||||
private DataSourceInitializationMode initializeSchema = DataSourceInitializationMode.EMBEDDED;
|
||||
|
||||
private final Job job = new Job();
|
||||
|
||||
@ -66,11 +66,11 @@ public class BatchProperties {
|
||||
this.tablePrefix = tablePrefix;
|
||||
}
|
||||
|
||||
public DatabaseInitializationMode getInitializeSchema() {
|
||||
public DataSourceInitializationMode getInitializeSchema() {
|
||||
return this.initializeSchema;
|
||||
}
|
||||
|
||||
public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
|
||||
public void setInitializeSchema(DataSourceInitializationMode initializeSchema) {
|
||||
this.initializeSchema = initializeSchema;
|
||||
}
|
||||
|
||||
|
@ -147,10 +147,10 @@ public class IntegrationAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public IntegrationDatabaseInitializer integrationDatabaseInitializer(
|
||||
public IntegrationDataSourceInitializer integrationDataSourceInitializer(
|
||||
DataSource dataSource, ResourceLoader resourceLoader,
|
||||
IntegrationProperties properties) {
|
||||
return new IntegrationDatabaseInitializer(dataSource, resourceLoader,
|
||||
return new IntegrationDataSourceInitializer(dataSource, resourceLoader,
|
||||
properties);
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.integration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.jdbc.AbstractDataSourceInitializer;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@ -29,11 +29,11 @@ import org.springframework.util.Assert;
|
||||
* @author Vedran Pavic
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class IntegrationDatabaseInitializer extends AbstractDatabaseInitializer {
|
||||
public class IntegrationDataSourceInitializer extends AbstractDataSourceInitializer {
|
||||
|
||||
private final IntegrationProperties.Jdbc properties;
|
||||
|
||||
public IntegrationDatabaseInitializer(DataSource dataSource,
|
||||
public IntegrationDataSourceInitializer(DataSource dataSource,
|
||||
ResourceLoader resourceLoader, IntegrationProperties properties) {
|
||||
super(dataSource, resourceLoader);
|
||||
Assert.notNull(properties, "IntegrationProperties must not be null");
|
||||
@ -41,7 +41,7 @@ public class IntegrationDatabaseInitializer extends AbstractDatabaseInitializer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DatabaseInitializationMode getMode() {
|
||||
protected DataSourceInitializationMode getMode() {
|
||||
return this.properties.getInitializeSchema();
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.integration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
|
||||
/**
|
||||
* Configuration properties for Spring Integration.
|
||||
@ -48,7 +48,7 @@ public class IntegrationProperties {
|
||||
/**
|
||||
* Database schema initialization mode.
|
||||
*/
|
||||
private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
|
||||
private DataSourceInitializationMode initializeSchema = DataSourceInitializationMode.EMBEDDED;
|
||||
|
||||
public String getSchema() {
|
||||
return this.schema;
|
||||
@ -58,11 +58,11 @@ public class IntegrationProperties {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
public DatabaseInitializationMode getInitializeSchema() {
|
||||
public DataSourceInitializationMode getInitializeSchema() {
|
||||
return this.initializeSchema;
|
||||
}
|
||||
|
||||
public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
|
||||
public void setInitializeSchema(DataSourceInitializationMode initializeSchema) {
|
||||
this.initializeSchema = initializeSchema;
|
||||
}
|
||||
|
||||
|
@ -150,22 +150,23 @@ public class QuartzAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public QuartzDatabaseInitializer quartzDatabaseInitializer(DataSource dataSource,
|
||||
ResourceLoader resourceLoader, QuartzProperties properties) {
|
||||
return new QuartzDatabaseInitializer(dataSource, resourceLoader, properties);
|
||||
public QuartzDataSourceInitializer quartzDataSourceInitializer(
|
||||
DataSource dataSource, ResourceLoader resourceLoader,
|
||||
QuartzProperties properties) {
|
||||
return new QuartzDataSourceInitializer(dataSource, resourceLoader, properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static DatabaseInitializerSchedulerDependencyPostProcessor databaseInitializerSchedulerDependencyPostProcessor() {
|
||||
return new DatabaseInitializerSchedulerDependencyPostProcessor();
|
||||
public static DataSourceInitializerSchedulerDependencyPostProcessor dataSourceInitializerSchedulerDependencyPostProcessor() {
|
||||
return new DataSourceInitializerSchedulerDependencyPostProcessor();
|
||||
}
|
||||
|
||||
private static class DatabaseInitializerSchedulerDependencyPostProcessor
|
||||
private static class DataSourceInitializerSchedulerDependencyPostProcessor
|
||||
extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||
|
||||
DatabaseInitializerSchedulerDependencyPostProcessor() {
|
||||
DataSourceInitializerSchedulerDependencyPostProcessor() {
|
||||
super(Scheduler.class, SchedulerFactoryBean.class,
|
||||
"quartzDatabaseInitializer");
|
||||
"quartzDataSourceInitializer");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,22 +18,22 @@ package org.springframework.boot.autoconfigure.quartz;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.jdbc.AbstractDataSourceInitializer;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Initializer for Quartz Scheduler schema.
|
||||
* Initialize the Quartz Scheduler schema.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class QuartzDatabaseInitializer extends AbstractDatabaseInitializer {
|
||||
public class QuartzDataSourceInitializer extends AbstractDataSourceInitializer {
|
||||
|
||||
private final QuartzProperties properties;
|
||||
|
||||
public QuartzDatabaseInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
||||
public QuartzDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
||||
QuartzProperties properties) {
|
||||
super(dataSource, resourceLoader);
|
||||
Assert.notNull(properties, "QuartzProperties must not be null");
|
||||
@ -41,7 +41,7 @@ public class QuartzDatabaseInitializer extends AbstractDatabaseInitializer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DatabaseInitializationMode getMode() {
|
||||
protected DataSourceInitializationMode getMode() {
|
||||
return this.properties.getJdbc().getInitializeSchema();
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ package org.springframework.boot.autoconfigure.quartz;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
|
||||
/**
|
||||
* Configuration properties for the Quartz Scheduler integration.
|
||||
@ -73,7 +73,7 @@ public class QuartzProperties {
|
||||
/**
|
||||
* Database schema initialization mode.
|
||||
*/
|
||||
private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
|
||||
private DataSourceInitializationMode initializeSchema = DataSourceInitializationMode.EMBEDDED;
|
||||
|
||||
public String getSchema() {
|
||||
return this.schema;
|
||||
@ -83,11 +83,11 @@ public class QuartzProperties {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
public DatabaseInitializationMode getInitializeSchema() {
|
||||
public DataSourceInitializationMode getInitializeSchema() {
|
||||
return this.initializeSchema;
|
||||
}
|
||||
|
||||
public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
|
||||
public void setInitializeSchema(DataSourceInitializationMode initializeSchema) {
|
||||
this.initializeSchema = initializeSchema;
|
||||
}
|
||||
|
||||
|
@ -49,10 +49,10 @@ class JdbcSessionConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JdbcSessionDatabaseInitializer jdbcSessionDatabaseInitializer(
|
||||
public JdbcSessionDataSourceInitializer jdbcSessionDataSourceInitializer(
|
||||
DataSource dataSource, ResourceLoader resourceLoader,
|
||||
JdbcSessionProperties properties) {
|
||||
return new JdbcSessionDatabaseInitializer(dataSource, resourceLoader, properties);
|
||||
return new JdbcSessionDataSourceInitializer(dataSource, resourceLoader, properties);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AbstractDatabaseInitializer;
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.jdbc.AbstractDataSourceInitializer;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@ -29,11 +29,11 @@ import org.springframework.util.Assert;
|
||||
* @author Vedran Pavic
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public class JdbcSessionDatabaseInitializer extends AbstractDatabaseInitializer {
|
||||
public class JdbcSessionDataSourceInitializer extends AbstractDataSourceInitializer {
|
||||
|
||||
private final JdbcSessionProperties properties;
|
||||
|
||||
public JdbcSessionDatabaseInitializer(DataSource dataSource,
|
||||
public JdbcSessionDataSourceInitializer(DataSource dataSource,
|
||||
ResourceLoader resourceLoader, JdbcSessionProperties properties) {
|
||||
super(dataSource, resourceLoader);
|
||||
Assert.notNull(properties, "JdbcSessionProperties must not be null");
|
||||
@ -41,7 +41,7 @@ public class JdbcSessionDatabaseInitializer extends AbstractDatabaseInitializer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DatabaseInitializationMode getMode() {
|
||||
protected DataSourceInitializationMode getMode() {
|
||||
return this.properties.getInitializeSchema();
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
|
||||
/**
|
||||
* Configuration properties for JDBC backed Spring Session.
|
||||
@ -46,7 +46,7 @@ public class JdbcSessionProperties {
|
||||
/**
|
||||
* Database schema initialization mode.
|
||||
*/
|
||||
private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
|
||||
private DataSourceInitializationMode initializeSchema = DataSourceInitializationMode.EMBEDDED;
|
||||
|
||||
public String getSchema() {
|
||||
return this.schema;
|
||||
@ -64,11 +64,11 @@ public class JdbcSessionProperties {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public DatabaseInitializationMode getInitializeSchema() {
|
||||
public DataSourceInitializationMode getInitializeSchema() {
|
||||
return this.initializeSchema;
|
||||
}
|
||||
|
||||
public void setInitializeSchema(DatabaseInitializationMode initializeSchema) {
|
||||
public void setInitializeSchema(DataSourceInitializationMode initializeSchema) {
|
||||
this.initializeSchema = initializeSchema;
|
||||
}
|
||||
|
||||
|
@ -47,12 +47,12 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
|
||||
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -89,7 +89,7 @@ public class BatchAutoConfigurationTests {
|
||||
assertThat(context).hasSingleBean(JobExplorer.class);
|
||||
assertThat(
|
||||
context.getBean(BatchProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
.isEqualTo(DataSourceInitializationMode.EMBEDDED);
|
||||
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty();
|
||||
});
|
||||
@ -176,7 +176,7 @@ public class BatchAutoConfigurationTests {
|
||||
assertThat(context).hasSingleBean(JobLauncher.class);
|
||||
assertThat(
|
||||
context.getBean(BatchProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.NEVER);
|
||||
.isEqualTo(DataSourceInitializationMode.NEVER);
|
||||
this.expected.expect(BadSqlGrammarException.class);
|
||||
new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from BATCH_JOB_EXECUTION");
|
||||
@ -215,7 +215,7 @@ public class BatchAutoConfigurationTests {
|
||||
assertThat(context).hasSingleBean(JobLauncher.class);
|
||||
assertThat(
|
||||
context.getBean(BatchProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
.isEqualTo(DataSourceInitializationMode.EMBEDDED);
|
||||
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from PREFIX_JOB_EXECUTION"))
|
||||
.isEmpty();
|
||||
|
@ -27,11 +27,11 @@ import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
|
||||
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
||||
@ -69,7 +69,7 @@ public class BatchAutoConfigurationWithoutJpaTests {
|
||||
.contains("DataSourceTransactionManager");
|
||||
assertThat(
|
||||
context.getBean(BatchProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
.isEqualTo(DataSourceInitializationMode.EMBEDDED);
|
||||
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from BATCH_JOB_EXECUTION")).isEmpty();
|
||||
assertThat(context.getBean(JobExplorer.class)
|
||||
|
@ -26,13 +26,13 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration.IntegrationComponentScanAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@ -148,14 +148,14 @@ public class IntegrationAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationJdbcDatabaseInitializerEnabled() {
|
||||
public void integrationJdbcDataSourceInitializerEnabled() {
|
||||
load(new Class[] { EmbeddedDataSourceConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class,
|
||||
JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class },
|
||||
"spring.datasource.generate-unique-name=true",
|
||||
"spring.integration.jdbc.initialize-schema=always");
|
||||
assertThat(this.context.getBean(IntegrationProperties.class).getJdbc()
|
||||
.getInitializeSchema()).isEqualTo(DatabaseInitializationMode.ALWAYS);
|
||||
.getInitializeSchema()).isEqualTo(DataSourceInitializationMode.ALWAYS);
|
||||
JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class);
|
||||
assertThat(jdbcOperations.queryForList("select * from INT_MESSAGE")).isEmpty();
|
||||
assertThat(jdbcOperations.queryForList("select * from INT_GROUP_TO_MESSAGE"))
|
||||
@ -168,27 +168,27 @@ public class IntegrationAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationJdbcDatabaseInitializerDisabled() {
|
||||
public void integrationJdbcDataSourceInitializerDisabled() {
|
||||
load(new Class[] { EmbeddedDataSourceConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class,
|
||||
JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class },
|
||||
"spring.datasource.generate-unique-name=true",
|
||||
"spring.integration.jdbc.initialize-schema=never");
|
||||
assertThat(this.context.getBean(IntegrationProperties.class).getJdbc()
|
||||
.getInitializeSchema()).isEqualTo(DatabaseInitializationMode.NEVER);
|
||||
.getInitializeSchema()).isEqualTo(DataSourceInitializationMode.NEVER);
|
||||
JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class);
|
||||
this.thrown.expect(BadSqlGrammarException.class);
|
||||
jdbcOperations.queryForList("select * from INT_MESSAGE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationJdbcDatabaseInitializerEnabledByDefaultWithEmbeddedDb() {
|
||||
public void integrationJdbcDataSourceInitializerEnabledByDefaultWithEmbeddedDb() {
|
||||
load(new Class[] { EmbeddedDataSourceConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class,
|
||||
JdbcTemplateAutoConfiguration.class, IntegrationAutoConfiguration.class },
|
||||
"spring.datasource.generate-unique-name=true");
|
||||
assertThat(this.context.getBean(IntegrationProperties.class).getJdbc()
|
||||
.getInitializeSchema()).isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
.getInitializeSchema()).isEqualTo(DataSourceInitializationMode.EMBEDDED);
|
||||
JdbcOperations jdbcOperations = this.context.getBean(JdbcOperations.class);
|
||||
jdbcOperations.queryForList("select * from INT_MESSAGE").isEmpty();
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.DatabaseInitializationMode;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.boot.test.context.HideClassesClassLoader;
|
||||
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
@ -79,7 +79,7 @@ public class SessionAutoConfigurationJdbcTests
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName"))
|
||||
.isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
.isEqualTo(DataSourceInitializationMode.EMBEDDED);
|
||||
assertThat(context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from SPRING_SESSION")).isEmpty();
|
||||
|
||||
@ -96,7 +96,7 @@ public class SessionAutoConfigurationJdbcTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disableDatabaseInitializer() {
|
||||
public void disableDataSourceInitializer() {
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc",
|
||||
"spring.session.jdbc.initialize-schema=never").run((context) -> {
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(
|
||||
@ -105,7 +105,7 @@ public class SessionAutoConfigurationJdbcTests
|
||||
.getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||
.getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.NEVER);
|
||||
.isEqualTo(DataSourceInitializationMode.NEVER);
|
||||
this.thrown.expect(BadSqlGrammarException.class);
|
||||
context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from SPRING_SESSION");
|
||||
@ -125,7 +125,7 @@ public class SessionAutoConfigurationJdbcTests
|
||||
.getPropertyValue("tableName")).isEqualTo("FOO_BAR");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||
.getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
.isEqualTo(DataSourceInitializationMode.EMBEDDED);
|
||||
assertThat(context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from FOO_BAR")).isEmpty();
|
||||
});
|
||||
|
@ -14,13 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure;
|
||||
package org.springframework.boot.jdbc;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
@ -29,13 +27,13 @@ import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base class used for database initialization.
|
||||
* Base class used for {@link DataSource} initialization.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public abstract class AbstractDatabaseInitializer {
|
||||
public abstract class AbstractDataSourceInitializer {
|
||||
|
||||
private static final String PLATFORM_PLACEHOLDER = "@@platform@@";
|
||||
|
||||
@ -43,7 +41,7 @@ public abstract class AbstractDatabaseInitializer {
|
||||
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
protected AbstractDatabaseInitializer(DataSource dataSource,
|
||||
protected AbstractDataSourceInitializer(DataSource dataSource,
|
||||
ResourceLoader resourceLoader) {
|
||||
Assert.notNull(dataSource, "DataSource must not be null");
|
||||
Assert.notNull(resourceLoader, "ResourceLoader must not be null");
|
||||
@ -68,17 +66,17 @@ public abstract class AbstractDatabaseInitializer {
|
||||
}
|
||||
|
||||
private boolean isEnabled() {
|
||||
if (getMode() == DatabaseInitializationMode.NEVER) {
|
||||
if (getMode() == DataSourceInitializationMode.NEVER) {
|
||||
return false;
|
||||
}
|
||||
if (getMode() == DatabaseInitializationMode.EMBEDDED
|
||||
if (getMode() == DataSourceInitializationMode.EMBEDDED
|
||||
&& !EmbeddedDatabaseConnection.isEmbedded(this.dataSource)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract DatabaseInitializationMode getMode();
|
||||
protected abstract DataSourceInitializationMode getMode();
|
||||
|
||||
protected abstract String getSchemaLocation();
|
||||
|
@ -14,29 +14,30 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure;
|
||||
package org.springframework.boot.jdbc;
|
||||
|
||||
/**
|
||||
* Supported {@link AbstractDatabaseInitializer database initializer} modes.
|
||||
* Supported {@link javax.sql.DataSource} initialization modes.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
* @see AbstractDataSourceInitializer
|
||||
*/
|
||||
public enum DatabaseInitializationMode {
|
||||
public enum DataSourceInitializationMode {
|
||||
|
||||
/**
|
||||
* Always initialize the database.
|
||||
* Always initialize the datasource.
|
||||
*/
|
||||
ALWAYS,
|
||||
|
||||
/**
|
||||
* Only initialize an embedded database.
|
||||
* Only initialize an embedded datasource.
|
||||
*/
|
||||
EMBEDDED,
|
||||
|
||||
/**
|
||||
* Do not initialize the database.
|
||||
* Do not initialize the datasource.
|
||||
*/
|
||||
NEVER
|
||||
|
Loading…
Reference in New Issue
Block a user