From 90183568ba9d416becf7a424f4129c3ad9809242 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 18 May 2021 15:39:08 +0200 Subject: [PATCH] Deprecate internal APIs in ScriptUtils Many of the utility methods in ScriptUtils are public only because they were once invoked from JdbdTestUtils in spring-test, which is no longer the case. Consequently, there should no longer be a need for any external clients to invoke such methods. To address, this commit formally deprecates the following methods in ScriptUtils in spring-jdbc. - readScript(...) - containsSqlScriptDelimiters(...) - splitSqlScript(...) Closes gh-26947 --- .../jdbc/datasource/init/ScriptUtils.java | 21 +++++++++++++++++++ .../datasource/init/ScriptUtilsUnitTests.java | 10 +++++++++ 2 files changed, 31 insertions(+) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java index 200607787e..f20b5d857b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java @@ -344,7 +344,10 @@ public abstract class ScriptUtils { * @param blockCommentEndDelimiter the end block comment delimiter * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors + * @deprecated as of Spring Framework 5.2.16 with no plans for replacement. + * This is an internal API and will likely be removed in Spring Framework 6.0. */ + @Deprecated public static String readScript(LineNumberReader lineNumberReader, @Nullable String commentPrefix, @Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException { @@ -368,7 +371,10 @@ public abstract class ScriptUtils { * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors * @since 5.2 + * @deprecated as of Spring Framework 5.2.16 with no plans for replacement. + * This is an internal API and will likely be removed in Spring Framework 6.0. */ + @Deprecated public static String readScript(LineNumberReader lineNumberReader, @Nullable String[] commentPrefixes, @Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException { @@ -416,7 +422,10 @@ public abstract class ScriptUtils { * @see #DEFAULT_COMMENT_PREFIXES * @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER * @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER + * @deprecated as of Spring Framework 5.2.16 with no plans for replacement. + * This is an internal API and will likely be removed in Spring Framework 6.0. */ + @Deprecated public static boolean containsSqlScriptDelimiters(String script, String delimiter) { return containsStatementSeparator(null, script, delimiter, DEFAULT_COMMENT_PREFIXES, DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); @@ -519,7 +528,10 @@ public abstract class ScriptUtils { * @throws ScriptException if an error occurred while splitting the SQL script * @see #splitSqlScript(String, String, List) * @see #splitSqlScript(EncodedResource, String, String, String, String, String, List) + * @deprecated as of Spring Framework 5.2.16 with no plans for replacement. + * This is an internal API and will likely be removed in Spring Framework 6.0. */ + @Deprecated public static void splitSqlScript(String script, char separator, List statements) throws ScriptException { splitSqlScript(script, String.valueOf(separator), statements); } @@ -543,7 +555,10 @@ public abstract class ScriptUtils { * @throws ScriptException if an error occurred while splitting the SQL script * @see #splitSqlScript(String, char, List) * @see #splitSqlScript(EncodedResource, String, String, String, String, String, List) + * @deprecated as of Spring Framework 5.2.16 with no plans for replacement. + * This is an internal API and will likely be removed in Spring Framework 6.0. */ + @Deprecated public static void splitSqlScript(String script, String separator, List statements) throws ScriptException { splitSqlScript(null, script, separator, DEFAULT_COMMENT_PREFIX, DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER, statements); @@ -572,7 +587,10 @@ public abstract class ScriptUtils { * never {@code null} or empty * @param statements the list that will contain the individual statements * @throws ScriptException if an error occurred while splitting the SQL script + * @deprecated as of Spring Framework 5.2.16 with no plans for replacement. + * This is an internal API and will likely be removed in Spring Framework 6.0. */ + @Deprecated public static void splitSqlScript(@Nullable EncodedResource resource, String script, String separator, String commentPrefix, String blockCommentStartDelimiter, String blockCommentEndDelimiter, List statements) throws ScriptException { @@ -606,7 +624,10 @@ public abstract class ScriptUtils { * @param statements the list that will contain the individual statements * @throws ScriptException if an error occurred while splitting the SQL script * @since 5.2 + * @deprecated as of Spring Framework 5.2.16 with no plans for replacement. + * This is an internal API and will likely be removed in Spring Framework 6.0. */ + @Deprecated public static void splitSqlScript(@Nullable EncodedResource resource, String script, String separator, String[] commentPrefixes, String blockCommentStartDelimiter, String blockCommentEndDelimiter, List statements) throws ScriptException { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java index ec5c832301..e033ef0339 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java @@ -48,6 +48,7 @@ import static org.springframework.jdbc.datasource.init.ScriptUtils.splitSqlScrip public class ScriptUtilsUnitTests { @Test + @SuppressWarnings("deprecation") public void splitSqlScriptDelimitedWithSemicolon() { String rawStatement1 = "insert into customer (id, name)\nvalues (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')"; String cleanedStatement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')"; @@ -63,6 +64,7 @@ public class ScriptUtilsUnitTests { } @Test + @SuppressWarnings("deprecation") public void splitSqlScriptDelimitedWithNewLine() { String statement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')"; String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)"; @@ -75,6 +77,7 @@ public class ScriptUtilsUnitTests { } @Test + @SuppressWarnings("deprecation") public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() { String statement1 = "do something"; String statement2 = "do something else"; @@ -86,6 +89,7 @@ public class ScriptUtilsUnitTests { } @Test // SPR-13218 + @SuppressWarnings("deprecation") public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() throws Exception { String statement1 = "select '1' as \"Dogbert's owner's\" from dual"; String statement2 = "select '2' as \"Dilbert's\" from dual"; @@ -97,6 +101,7 @@ public class ScriptUtilsUnitTests { } @Test // SPR-11560 + @SuppressWarnings("deprecation") public void readAndSplitScriptWithMultipleNewlinesAsSeparator() throws Exception { String script = readScript("db-test-data-multi-newline.sql"); List statements = new ArrayList<>(); @@ -124,6 +129,7 @@ public class ScriptUtilsUnitTests { splitScriptContainingComments(script, "--", "#", "^"); } + @SuppressWarnings("deprecation") private void splitScriptContainingComments(String script, String... commentPrefixes) throws Exception { List statements = new ArrayList<>(); splitSqlScript(null, script, ";", commentPrefixes, DEFAULT_BLOCK_COMMENT_START_DELIMITER, @@ -137,6 +143,7 @@ public class ScriptUtilsUnitTests { } @Test // SPR-10330 + @SuppressWarnings("deprecation") public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception { String script = readScript("test-data-with-comments-and-leading-tabs.sql"); List statements = new ArrayList<>(); @@ -148,6 +155,7 @@ public class ScriptUtilsUnitTests { } @Test // SPR-9531 + @SuppressWarnings("deprecation") public void readAndSplitScriptContainingMultiLineComments() throws Exception { String script = readScript("test-data-with-multi-line-comments.sql"); List statements = new ArrayList<>(); @@ -158,6 +166,7 @@ public class ScriptUtilsUnitTests { } @Test + @SuppressWarnings("deprecation") public void readAndSplitScriptContainingMultiLineNestedComments() throws Exception { String script = readScript("test-data-with-multi-line-nested-comments.sql"); List statements = new ArrayList<>(); @@ -199,6 +208,7 @@ public class ScriptUtilsUnitTests { "'/* double \" quotes */\ninsert into colors(color_num) values(42);' # ; # true", "'/* double \\\" quotes */\ninsert into colors(color_num) values(42);' # ; # true" }) + @SuppressWarnings("deprecation") public void containsStatementSeparator(String script, String delimiter, boolean expected) { // Indirectly tests ScriptUtils.containsStatementSeparator(EncodedResource, String, String, String[], String, String). assertThat(containsSqlScriptDelimiters(script, delimiter)).isEqualTo(expected);