|
|
@ -49,7 +49,6 @@ import org.springframework.context.annotation.ConditionContext;
|
|
|
|
import org.springframework.context.annotation.DependsOn;
|
|
|
|
import org.springframework.context.annotation.DependsOn;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
|
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
|
|
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
|
|
|
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@ -63,8 +62,7 @@ import org.springframework.util.StringUtils;
|
|
|
|
@Deprecated
|
|
|
|
@Deprecated
|
|
|
|
class DataSourceInitializationConfiguration {
|
|
|
|
class DataSourceInitializationConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
private static DataSource determineDataSource(Supplier<DataSource> dataSource, String username, String password,
|
|
|
|
private static DataSource determineDataSource(Supplier<DataSource> dataSource, String username, String password) {
|
|
|
|
DataSourceProperties properties) {
|
|
|
|
|
|
|
|
if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
|
|
|
|
if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
|
|
|
|
DataSourceBuilder.derivedFrom(dataSource.get()).type(SimpleDriverDataSource.class).username(username)
|
|
|
|
DataSourceBuilder.derivedFrom(dataSource.get()).type(SimpleDriverDataSource.class).username(username)
|
|
|
|
.password(password).build();
|
|
|
|
.password(password).build();
|
|
|
@ -92,14 +90,14 @@ class DataSourceInitializationConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
DataSourceScriptDatabaseInitializer ddlOnlyScriptDataSourceInitializer(ObjectProvider<DataSource> dataSource,
|
|
|
|
DataSourceScriptDatabaseInitializer ddlOnlyScriptDataSourceInitializer(ObjectProvider<DataSource> dataSource,
|
|
|
|
DataSourceProperties properties, ResourceLoader resourceLoader) {
|
|
|
|
DataSourceProperties properties) {
|
|
|
|
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
|
|
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
|
|
settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform()));
|
|
|
|
settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform()));
|
|
|
|
settings.setContinueOnError(properties.isContinueOnError());
|
|
|
|
settings.setContinueOnError(properties.isContinueOnError());
|
|
|
|
settings.setSeparator(properties.getSeparator());
|
|
|
|
settings.setSeparator(properties.getSeparator());
|
|
|
|
settings.setEncoding(properties.getSqlScriptEncoding());
|
|
|
|
settings.setEncoding(properties.getSqlScriptEncoding());
|
|
|
|
DataSource initializationDataSource = determineDataSource(dataSource::getObject,
|
|
|
|
DataSource initializationDataSource = determineDataSource(dataSource::getObject,
|
|
|
|
properties.getSchemaUsername(), properties.getSchemaPassword(), properties);
|
|
|
|
properties.getSchemaUsername(), properties.getSchemaPassword());
|
|
|
|
return new InitializationModeDataSourceScriptDatabaseInitializer(initializationDataSource, settings,
|
|
|
|
return new InitializationModeDataSourceScriptDatabaseInitializer(initializationDataSource, settings,
|
|
|
|
properties.getInitializationMode());
|
|
|
|
properties.getInitializationMode());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -107,14 +105,14 @@ class DataSourceInitializationConfiguration {
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@DependsOn("ddlOnlyScriptDataSourceInitializer")
|
|
|
|
@DependsOn("ddlOnlyScriptDataSourceInitializer")
|
|
|
|
DataSourceScriptDatabaseInitializer dmlOnlyScriptDataSourceInitializer(ObjectProvider<DataSource> dataSource,
|
|
|
|
DataSourceScriptDatabaseInitializer dmlOnlyScriptDataSourceInitializer(ObjectProvider<DataSource> dataSource,
|
|
|
|
DataSourceProperties properties, ResourceLoader resourceLoader) {
|
|
|
|
DataSourceProperties properties) {
|
|
|
|
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
|
|
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
|
|
settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform()));
|
|
|
|
settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform()));
|
|
|
|
settings.setContinueOnError(properties.isContinueOnError());
|
|
|
|
settings.setContinueOnError(properties.isContinueOnError());
|
|
|
|
settings.setSeparator(properties.getSeparator());
|
|
|
|
settings.setSeparator(properties.getSeparator());
|
|
|
|
settings.setEncoding(properties.getSqlScriptEncoding());
|
|
|
|
settings.setEncoding(properties.getSqlScriptEncoding());
|
|
|
|
DataSource initializationDataSource = determineDataSource(dataSource::getObject,
|
|
|
|
DataSource initializationDataSource = determineDataSource(dataSource::getObject,
|
|
|
|
properties.getDataUsername(), properties.getDataPassword(), properties);
|
|
|
|
properties.getDataUsername(), properties.getDataPassword());
|
|
|
|
return new InitializationModeDataSourceScriptDatabaseInitializer(initializationDataSource, settings,
|
|
|
|
return new InitializationModeDataSourceScriptDatabaseInitializer(initializationDataSource, settings,
|
|
|
|
properties.getInitializationMode());
|
|
|
|
properties.getInitializationMode());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -149,7 +147,7 @@ class DataSourceInitializationConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
DataSourceScriptDatabaseInitializer scriptDataSourceInitializer(DataSource dataSource,
|
|
|
|
DataSourceScriptDatabaseInitializer scriptDataSourceInitializer(DataSource dataSource,
|
|
|
|
DataSourceProperties properties, ResourceLoader resourceLoader) {
|
|
|
|
DataSourceProperties properties) {
|
|
|
|
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
|
|
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
|
|
settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform()));
|
|
|
|
settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform()));
|
|
|
|
settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform()));
|
|
|
|
settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform()));
|
|
|
|