diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java index c32975bff5..9a4ee42c63 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java @@ -83,7 +83,7 @@ class DataSourceInitializationConfiguration { ScriptDataSourceInitializer ddlOnlyScriptDataSourceInitializer(ObjectProvider dataSource, DataSourceProperties properties, ResourceLoader resourceLoader) { DataSourceInitializationSettings settings = new DataSourceInitializationSettings(); - settings.setDdlScriptLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform())); + settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform())); settings.setContinueOnError(properties.isContinueOnError()); settings.setSeparator(properties.getSeparator()); settings.setEncoding(properties.getSqlScriptEncoding()); @@ -98,7 +98,7 @@ class DataSourceInitializationConfiguration { ScriptDataSourceInitializer dmlOnlyScriptDataSourceInitializer(ObjectProvider dataSource, DataSourceProperties properties, ResourceLoader resourceLoader) { DataSourceInitializationSettings settings = new DataSourceInitializationSettings(); - settings.setDmlScriptLocations(scriptLocations(properties.getData(), "data", properties.getPlatform())); + settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform())); settings.setContinueOnError(properties.isContinueOnError()); settings.setSeparator(properties.getSeparator()); settings.setEncoding(properties.getSqlScriptEncoding()); @@ -138,8 +138,8 @@ class DataSourceInitializationConfiguration { ScriptDataSourceInitializer scriptDataSourceInitializer(DataSource dataSource, DataSourceProperties properties, ResourceLoader resourceLoader) { DataSourceInitializationSettings settings = new DataSourceInitializationSettings(); - settings.setDdlScriptLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform())); - settings.setDmlScriptLocations(scriptLocations(properties.getData(), "data", properties.getPlatform())); + settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform())); + settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform())); settings.setContinueOnError(properties.isContinueOnError()); settings.setSeparator(properties.getSeparator()); settings.setEncoding(properties.getSqlScriptEncoding()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java index 427f9804e4..90f980f0ae 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationIntegrationTests.java @@ -243,7 +243,7 @@ class DataSourceInitializationIntegrationTests { assertThat(context).hasFailed(); assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class); assertThat(context.getStartupFailure()) - .hasMessageContaining("No DDL scripts found at location 'classpath:does/not/exist.sql'"); + .hasMessageContaining("No schema scripts found at location 'classpath:does/not/exist.sql'"); }); } @@ -255,7 +255,7 @@ class DataSourceInitializationIntegrationTests { assertThat(context).hasFailed(); assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class); assertThat(context.getStartupFailure()) - .hasMessageContaining("No DML scripts found at location 'classpath:does/not/exist.sql'"); + .hasMessageContaining("No data scripts found at location 'classpath:does/not/exist.sql'"); }); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/DataSourceInitializationSettings.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/DataSourceInitializationSettings.java index 8df5d9058a..64e4df3b72 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/DataSourceInitializationSettings.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/DataSourceInitializationSettings.java @@ -29,9 +29,9 @@ import javax.sql.DataSource; */ public class DataSourceInitializationSettings { - private List ddlScriptLocations; + private List schemaLocations; - private List dmlScriptLocations; + private List dataLocations; private boolean continueOnError = false; @@ -40,43 +40,43 @@ public class DataSourceInitializationSettings { private Charset encoding; /** - * Returns the locations of the DDL (schema) scripts to apply to the database. - * @return the locations of the DDL scripts + * Returns the locations of the schema (DDL) scripts to apply to the database. + * @return the locations of the schema scripts */ - public List getDdlScriptLocations() { - return this.ddlScriptLocations; + public List getSchemaLocations() { + return this.schemaLocations; } /** - * Sets the locations of DDL (schema) scripts to apply to the database. By default, + * Sets the locations of schema (DDL) scripts to apply to the database. By default, * initialization will fail if a location does not exist. To prevent a failure, a * location can be made optional by prefixing it with {@code optional:}. - * @param ddlScriptLocations locations of the DDL scripts + * @param schemaLocations locations of the schema scripts */ - public void setDdlScriptLocations(List ddlScriptLocations) { - this.ddlScriptLocations = ddlScriptLocations; + public void setSchemaLocations(List schemaLocations) { + this.schemaLocations = schemaLocations; } /** - * Returns the locations of the DML (data) scripts to apply to the database. - * @return the locations of the DML scripts + * Returns the locations of data (DML) scripts to apply to the database. + * @return the locations of the data scripts */ - public List getDmlScriptLocations() { - return this.dmlScriptLocations; + public List getDataLocations() { + return this.dataLocations; } /** - * Sets the locations of DML (data) scripts to apply to the database. By default, + * Sets the locations of data (DML) scripts to apply to the database. By default, * initialization will fail if a location does not exist. To prevent a failure, a * location can be made optional by prefixing it with {@code optional:}. - * @param dmlScriptLocations locations of the DML scripts + * @param dataLocations locations of the data scripts */ - public void setDmlScriptLocations(List dmlScriptLocations) { - this.dmlScriptLocations = dmlScriptLocations; + public void setDataLocations(List dataLocations) { + this.dataLocations = dataLocations; } /** - * Returns whether to continue when an error occurs while applying a DDL or DML + * Returns whether to continue when an error occurs while applying a schema or data * script. * @return whether to continue on error */ @@ -86,7 +86,7 @@ public class DataSourceInitializationSettings { /** * Sets whether initialization should continue when an error occurs when applying a - * DDL or DML script. + * schema or data script. * @param continueOnError whether to continue when an error occurs. */ public void setContinueOnError(boolean continueOnError) { @@ -94,7 +94,7 @@ public class DataSourceInitializationSettings { } /** - * Returns the statement separator used in the DDL and DML scripts. + * Returns the statement separator used in the schema and data scripts. * @return the statement separator */ public String getSeparator() { @@ -102,15 +102,15 @@ public class DataSourceInitializationSettings { } /** - * Sets the statement separator to use when reading the DDL and DML scripts. - * @param separator statement separator used in DDL and DML scripts + * Sets the statement separator to use when reading the schema and data scripts. + * @param separator statement separator used in the schema and data scripts */ public void setSeparator(String separator) { this.separator = separator; } /** - * Returns the encoding to use when reading the DDL and DML scripts. + * Returns the encoding to use when reading the schema and data scripts. * @return the script encoding */ public Charset getEncoding() { @@ -118,8 +118,8 @@ public class DataSourceInitializationSettings { } /** - * Sets the encoding to use when reading the DDL and DML scripts. - * @param encoding encoding to use when reading the DDL and DML scripts + * Sets the encoding to use when reading the schema and data scripts. + * @param encoding encoding to use when reading the schema and data scripts */ public void setEncoding(Charset encoding) { this.encoding = encoding; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializer.java index 1d9b452a6a..105133b401 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializer.java @@ -36,8 +36,8 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.util.CollectionUtils; /** - * {@link InitializingBean} that performs {@link DataSource} initialization using DDL and - * DML scripts. + * {@link InitializingBean} that performs {@link DataSource} initialization using schema + * (DDL) and data (DML) scripts. * * @author Andy Wilkinson * @since 2.5.0 @@ -82,23 +82,23 @@ public class ScriptDataSourceInitializer implements ResourceLoaderAware, Initial } /** - * Initializes the database by running DDL and DML scripts. + * Initializes the database by applying schema and data scripts. * @return {@code true} if one or more scripts were applied to the database, otherwise * {@code false} */ public boolean initializeDatabase() { ScriptLocationResolver locationResolver = new ScriptLocationResolver(this.resourceLoader); - boolean initialized = applyDdlScripts(locationResolver); - initialized = applyDmlScripts(locationResolver) || initialized; + boolean initialized = applySchemaScripts(locationResolver); + initialized = applyDataScripts(locationResolver) || initialized; return initialized; } - private boolean applyDdlScripts(ScriptLocationResolver locationResolver) { - return applyScripts(this.settings.getDdlScriptLocations(), "DDL", locationResolver); + private boolean applySchemaScripts(ScriptLocationResolver locationResolver) { + return applyScripts(this.settings.getSchemaLocations(), "schema", locationResolver); } - private boolean applyDmlScripts(ScriptLocationResolver locationResolver) { - return applyScripts(this.settings.getDmlScriptLocations(), "DML", locationResolver); + private boolean applyDataScripts(ScriptLocationResolver locationResolver) { + return applyScripts(this.settings.getDataLocations(), "data", locationResolver); } private boolean applyScripts(List locations, String type, ScriptLocationResolver locationResolver) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializerTests.java index 1e7675fa96..368d92cc8c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/init/ScriptDataSourceInitializerTests.java @@ -46,10 +46,10 @@ class ScriptDataSourceInitializerTests { } @Test - void whenDatabaseIsInitializedThenDdlAndDmlScriptsAreApplied() { + void whenDatabaseIsInitializedThenSchemaAndDataScriptsAreApplied() { DataSourceInitializationSettings settings = new DataSourceInitializationSettings(); - settings.setDdlScriptLocations(Arrays.asList("schema.sql")); - settings.setDmlScriptLocations(Arrays.asList("data.sql")); + settings.setSchemaLocations(Arrays.asList("schema.sql")); + settings.setDataLocations(Arrays.asList("data.sql")); ScriptDataSourceInitializer initializer = createInitializer(settings); assertThat(initializer.initializeDatabase()).isTrue(); assertThat(numberOfRows("SELECT COUNT(*) FROM EXAMPLE")).isEqualTo(1); @@ -58,7 +58,7 @@ class ScriptDataSourceInitializerTests { @Test void whenContinueOnErrorIsFalseThenInitializationFailsOnError() { DataSourceInitializationSettings settings = new DataSourceInitializationSettings(); - settings.setDmlScriptLocations(Arrays.asList("data.sql")); + settings.setDataLocations(Arrays.asList("data.sql")); ScriptDataSourceInitializer initializer = createInitializer(settings); assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> initializer.initializeDatabase()); } @@ -67,7 +67,7 @@ class ScriptDataSourceInitializerTests { void whenContinueOnErrorIsTrueThenInitializationDoesNotFailOnError() { DataSourceInitializationSettings settings = new DataSourceInitializationSettings(); settings.setContinueOnError(true); - settings.setDmlScriptLocations(Arrays.asList("data.sql")); + settings.setDataLocations(Arrays.asList("data.sql")); ScriptDataSourceInitializer initializer = createInitializer(settings); assertThat(initializer.initializeDatabase()).isTrue(); }