Remove APIs deprecated for removal in 6.1
This is the first commit that removes deprecated APIs. Subsequent commits will remove additional deprecated APIs. See gh-29449
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -330,53 +330,7 @@ public abstract class ScriptUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a script from the provided {@code LineNumberReader}, using the supplied
|
||||
* comment prefix and statement separator, and build a {@code String} containing
|
||||
* the lines.
|
||||
* <p>Lines <em>beginning</em> with the comment prefix are excluded from the
|
||||
* results; however, line comments anywhere else — for example, within
|
||||
* a statement — will be included in the results.
|
||||
* @param lineNumberReader the {@code LineNumberReader} containing the script
|
||||
* to be processed
|
||||
* @param commentPrefix the prefix that identifies comments in the SQL script
|
||||
* (typically "--")
|
||||
* @param separator the statement separator in the SQL script (typically ";")
|
||||
* @param blockCommentEndDelimiter the <em>end</em> 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 {
|
||||
|
||||
String[] commentPrefixes = (commentPrefix != null) ? new String[] { commentPrefix } : null;
|
||||
return readScript(lineNumberReader, commentPrefixes, separator, blockCommentEndDelimiter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a script from the provided {@code LineNumberReader}, using the supplied
|
||||
* comment prefixes and statement separator, and build a {@code String} containing
|
||||
* the lines.
|
||||
* <p>Lines <em>beginning</em> with one of the comment prefixes are excluded
|
||||
* from the results; however, line comments anywhere else — for example,
|
||||
* within a statement — will be included in the results.
|
||||
* @param lineNumberReader the {@code LineNumberReader} containing the script
|
||||
* to be processed
|
||||
* @param commentPrefixes the prefixes that identify comments in the SQL script
|
||||
* (typically "--")
|
||||
* @param separator the statement separator in the SQL script (typically ";")
|
||||
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
|
||||
* @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,
|
||||
private static String readScript(LineNumberReader lineNumberReader, @Nullable String[] commentPrefixes,
|
||||
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
|
||||
|
||||
String currentStatement = lineNumberReader.readLine();
|
||||
@@ -410,28 +364,6 @@ public abstract class ScriptUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provided SQL script contains the specified delimiter.
|
||||
* <p>This method is intended to be used to find the string delimiting each
|
||||
* SQL statement — for example, a ';' character.
|
||||
* <p>Any occurrence of the delimiter within the script will be ignored if it
|
||||
* is within a <em>literal</em> block of text enclosed in single quotes
|
||||
* ({@code '}) or double quotes ({@code "}), if it is escaped with a backslash
|
||||
* ({@code \}), or if it is within a single-line comment or block comment.
|
||||
* @param script the SQL script to search within
|
||||
* @param delimiter the statement delimiter to search for
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provided SQL script contains the specified statement separator.
|
||||
* <p>This method is intended to be used to find the string separating each
|
||||
@@ -452,7 +384,7 @@ public abstract class ScriptUtils {
|
||||
* (typically <code>"*/"</code>)
|
||||
* @since 5.2.16
|
||||
*/
|
||||
private static boolean containsStatementSeparator(@Nullable EncodedResource resource, String script,
|
||||
static boolean containsStatementSeparator(@Nullable EncodedResource resource, String script,
|
||||
String separator, String[] commentPrefixes, String blockCommentStartDelimiter,
|
||||
String blockCommentEndDelimiter) throws ScriptException {
|
||||
|
||||
@@ -511,96 +443,6 @@ public abstract class ScriptUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* separator character. Each individual statement will be added to the
|
||||
* provided {@code List}.
|
||||
* <p>Within the script, {@value #DEFAULT_COMMENT_PREFIX} will be used as the
|
||||
* comment prefix; any text beginning with the comment prefix and extending to
|
||||
* the end of the line will be omitted from the output. Similarly,
|
||||
* {@value #DEFAULT_BLOCK_COMMENT_START_DELIMITER} and
|
||||
* {@value #DEFAULT_BLOCK_COMMENT_END_DELIMITER} will be used as the
|
||||
* <em>start</em> and <em>end</em> block comment delimiters: any text enclosed
|
||||
* in a block comment will be omitted from the output. In addition, multiple
|
||||
* adjacent whitespace characters will be collapsed into a single space.
|
||||
* @param script the SQL script
|
||||
* @param separator character separating each statement (typically a ';')
|
||||
* @param statements the list that will contain the individual statements
|
||||
* @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<String> statements) throws ScriptException {
|
||||
splitSqlScript(script, String.valueOf(separator), statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* separator string. Each individual statement will be added to the
|
||||
* provided {@code List}.
|
||||
* <p>Within the script, {@value #DEFAULT_COMMENT_PREFIX} will be used as the
|
||||
* comment prefix; any text beginning with the comment prefix and extending to
|
||||
* the end of the line will be omitted from the output. Similarly,
|
||||
* {@value #DEFAULT_BLOCK_COMMENT_START_DELIMITER} and
|
||||
* {@value #DEFAULT_BLOCK_COMMENT_END_DELIMITER} will be used as the
|
||||
* <em>start</em> and <em>end</em> block comment delimiters: any text enclosed
|
||||
* in a block comment will be omitted from the output. In addition, multiple
|
||||
* adjacent whitespace characters will be collapsed into a single space.
|
||||
* @param script the SQL script
|
||||
* @param separator text separating each statement
|
||||
* (typically a ';' or newline character)
|
||||
* @param statements the list that will contain the individual statements
|
||||
* @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<String> statements) throws ScriptException {
|
||||
splitSqlScript(null, script, separator, DEFAULT_COMMENT_PREFIX, DEFAULT_BLOCK_COMMENT_START_DELIMITER,
|
||||
DEFAULT_BLOCK_COMMENT_END_DELIMITER, statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* separator string. Each individual statement will be added to the provided
|
||||
* {@code List}.
|
||||
* <p>Within the script, the provided {@code commentPrefix} will be honored:
|
||||
* any text beginning with the comment prefix and extending to the end of the
|
||||
* line will be omitted from the output. Similarly, the provided
|
||||
* {@code blockCommentStartDelimiter} and {@code blockCommentEndDelimiter}
|
||||
* delimiters will be honored: any text enclosed in a block comment will be
|
||||
* omitted from the output. In addition, multiple adjacent whitespace characters
|
||||
* will be collapsed into a single space.
|
||||
* @param resource the resource from which the script was read
|
||||
* @param script the SQL script
|
||||
* @param separator text separating each statement
|
||||
* (typically a ';' or newline character)
|
||||
* @param commentPrefix the prefix that identifies SQL line comments
|
||||
* (typically "--")
|
||||
* @param blockCommentStartDelimiter the <em>start</em> block comment delimiter;
|
||||
* never {@code null} or empty
|
||||
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter;
|
||||
* 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<String> statements) throws ScriptException {
|
||||
|
||||
Assert.hasText(commentPrefix, "'commentPrefix' must not be null or empty");
|
||||
splitSqlScript(resource, script, separator, new String[] { commentPrefix },
|
||||
blockCommentStartDelimiter, blockCommentEndDelimiter, statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an SQL script into separate statements delimited by the provided
|
||||
* separator string. Each individual statement will be added to the provided
|
||||
@@ -625,11 +467,8 @@ 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,
|
||||
static void splitSqlScript(@Nullable EncodedResource resource, String script,
|
||||
String separator, String[] commentPrefixes, String blockCommentStartDelimiter,
|
||||
String blockCommentEndDelimiter, List<String> statements) throws ScriptException {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,14 +26,14 @@ import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_COMMENT_PREFIX;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_COMMENT_PREFIXES;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_STATEMENT_SEPARATOR;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.containsSqlScriptDelimiters;
|
||||
import static org.springframework.jdbc.datasource.init.ScriptUtils.splitSqlScript;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ScriptUtils}.
|
||||
@@ -46,11 +46,10 @@ import static org.springframework.jdbc.datasource.init.ScriptUtils.splitSqlScrip
|
||||
* @since 4.0.3
|
||||
* @see ScriptUtilsIntegrationTests
|
||||
*/
|
||||
public class ScriptUtilsUnitTests {
|
||||
class ScriptUtilsUnitTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void splitSqlScriptDelimitedWithSemicolon() {
|
||||
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')";
|
||||
String rawStatement2 = "insert into orders(id, order_date, customer_id)\nvalues (1, '2008-01-02', 2)";
|
||||
@@ -68,8 +67,7 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void splitSqlScriptDelimitedWithNewLine() {
|
||||
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)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)";
|
||||
@@ -84,8 +82,7 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
|
||||
void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
|
||||
String statement1 = "do something";
|
||||
String statement2 = "do something else";
|
||||
|
||||
@@ -99,8 +96,7 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13218
|
||||
@SuppressWarnings("deprecation")
|
||||
public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() {
|
||||
void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() {
|
||||
String statement1 = "select '1' as \"Dogbert's owner's\" from dual";
|
||||
String statement2 = "select '2' as \"Dilbert's\" from dual";
|
||||
|
||||
@@ -114,8 +110,7 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test // SPR-11560
|
||||
@SuppressWarnings("deprecation")
|
||||
public void readAndSplitScriptWithMultipleNewlinesAsSeparator() throws Exception {
|
||||
void readAndSplitScriptWithMultipleNewlinesAsSeparator() throws Exception {
|
||||
String script = readScript("db-test-data-multi-newline.sql");
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, "\n\n", statements);
|
||||
@@ -127,24 +122,23 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readAndSplitScriptContainingComments() throws Exception {
|
||||
void readAndSplitScriptContainingComments() throws Exception {
|
||||
String script = readScript("test-data-with-comments.sql");
|
||||
splitScriptContainingComments(script, DEFAULT_COMMENT_PREFIXES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readAndSplitScriptContainingCommentsWithWindowsLineEnding() throws Exception {
|
||||
void readAndSplitScriptContainingCommentsWithWindowsLineEnding() throws Exception {
|
||||
String script = readScript("test-data-with-comments.sql").replaceAll("\n", "\r\n");
|
||||
splitScriptContainingComments(script, DEFAULT_COMMENT_PREFIXES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readAndSplitScriptContainingCommentsWithMultiplePrefixes() throws Exception {
|
||||
void readAndSplitScriptContainingCommentsWithMultiplePrefixes() throws Exception {
|
||||
String script = readScript("test-data-with-multi-prefix-comments.sql");
|
||||
splitScriptContainingComments(script, "--", "#", "^");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void splitScriptContainingComments(String script, String... commentPrefixes) {
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(null, script, ";", commentPrefixes, DEFAULT_BLOCK_COMMENT_START_DELIMITER,
|
||||
@@ -160,11 +154,10 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test // SPR-10330
|
||||
@SuppressWarnings("deprecation")
|
||||
public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception {
|
||||
void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception {
|
||||
String script = readScript("test-data-with-comments-and-leading-tabs.sql");
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, ';', statements);
|
||||
splitSqlScript(script, ";", statements);
|
||||
|
||||
String statement1 = "insert into customer (id, name) values (1, 'Sam Brannen')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1)";
|
||||
@@ -174,11 +167,10 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test // SPR-9531
|
||||
@SuppressWarnings("deprecation")
|
||||
public void readAndSplitScriptContainingMultiLineComments() throws Exception {
|
||||
void readAndSplitScriptContainingMultiLineComments() throws Exception {
|
||||
String script = readScript("test-data-with-multi-line-comments.sql");
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, ';', statements);
|
||||
splitSqlScript(script, ";", statements);
|
||||
|
||||
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')";
|
||||
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )";
|
||||
@@ -187,11 +179,10 @@ public class ScriptUtilsUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void readAndSplitScriptContainingMultiLineNestedComments() throws Exception {
|
||||
void readAndSplitScriptContainingMultiLineNestedComments() throws Exception {
|
||||
String script = readScript("test-data-with-multi-line-nested-comments.sql");
|
||||
List<String> statements = new ArrayList<>();
|
||||
splitSqlScript(script, ';', statements);
|
||||
splitSqlScript(script, ";", statements);
|
||||
|
||||
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')";
|
||||
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )";
|
||||
@@ -237,16 +228,36 @@ public class ScriptUtilsUnitTests {
|
||||
~/* double " quotes */\n insert into colors(color_num) values(42);~ | ; | true
|
||||
~/* double \\" quotes */\n insert into colors(color_num) values(42);~ | ; | true
|
||||
""")
|
||||
@SuppressWarnings("deprecation")
|
||||
public void containsStatementSeparator(String script, String delimiter, boolean expected) {
|
||||
void containsStatementSeparator(String script, String delimiter, boolean expected) {
|
||||
// Indirectly tests ScriptUtils.containsStatementSeparator(EncodedResource, String, String, String[], String, String).
|
||||
assertThat(containsSqlScriptDelimiters(script, delimiter)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
private String readScript(String path) throws Exception {
|
||||
EncodedResource resource = new EncodedResource(new ClassPathResource(path, getClass()));
|
||||
return ScriptUtils.readScript(resource, DEFAULT_STATEMENT_SEPARATOR, DEFAULT_COMMENT_PREFIXES,
|
||||
DEFAULT_BLOCK_COMMENT_END_DELIMITER);
|
||||
}
|
||||
|
||||
|
||||
private static void splitSqlScript(String script, String separator, List<String> statements) throws ScriptException {
|
||||
splitSqlScript(null, script, separator, new String[] { DEFAULT_COMMENT_PREFIX },
|
||||
DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER, statements);
|
||||
}
|
||||
|
||||
private static void splitSqlScript(@Nullable EncodedResource resource, String script,
|
||||
String separator, String[] commentPrefixes, String blockCommentStartDelimiter,
|
||||
String blockCommentEndDelimiter, List<String> statements) throws ScriptException {
|
||||
|
||||
ScriptUtils.splitSqlScript(resource, script, separator, commentPrefixes,
|
||||
blockCommentStartDelimiter, blockCommentEndDelimiter, statements);
|
||||
}
|
||||
|
||||
|
||||
private static boolean containsSqlScriptDelimiters(String script, String delimiter) {
|
||||
return ScriptUtils.containsStatementSeparator(null, script, delimiter, DEFAULT_COMMENT_PREFIXES,
|
||||
DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user