public abstract class ScriptUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_BLOCK_COMMENT_END_DELIMITER
Default end delimiter for block comments within SQL scripts.
|
static String |
DEFAULT_BLOCK_COMMENT_START_DELIMITER
Default start delimiter for block comments within SQL scripts.
|
static String |
DEFAULT_COMMENT_PREFIX
Default prefix for line comments within SQL scripts.
|
static String |
DEFAULT_STATEMENT_SEPARATOR
Default statement separator within SQL scripts.
|
static String |
EOF_STATEMENT_SEPARATOR
End of file (EOF) SQL statement separator.
|
static String |
FALLBACK_STATEMENT_SEPARATOR
Fallback statement separator within SQL scripts.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsSqlScriptDelimiters(String script,
String delim)
Does the provided SQL script contain the specified delimiter?
|
static void |
executeSqlScript(DataSource dataSource,
org.springframework.core.io.support.EncodedResource resource)
Execute the given SQL script using default settings for separator separators,
comment delimiters, and exception handling flags.
|
static void |
executeSqlScript(DataSource dataSource,
org.springframework.core.io.support.EncodedResource resource,
String commentPrefix,
String separator,
String blockCommentStartDelimiter,
String blockCommentEndDelimiter)
Execute the given SQL script.
|
static void |
executeSqlScript(DataSource dataSource,
org.springframework.core.io.Resource resource)
Execute the given SQL script using default settings for separator separators,
comment delimiters, and exception handling flags.
|
static String |
readScript(LineNumberReader lineNumberReader,
String commentPrefix,
String separator)
Read a script from the provided
LineNumberReader, using the supplied
comment prefix and statement separator, and build a String containing
the lines. |
static void |
splitSqlScript(org.springframework.core.io.support.EncodedResource resource,
String script,
String separator,
String commentPrefix,
String blockCommentStartDelimiter,
String blockCommentEndDelimiter,
List<String> statements)
Split an SQL script into separate statements delimited by the provided
separator string.
|
public static final String DEFAULT_STATEMENT_SEPARATOR
public static final String FALLBACK_STATEMENT_SEPARATOR
Used if neither a custom defined separator nor the
DEFAULT_STATEMENT_SEPARATOR is present in a given script.
public static final String EOF_STATEMENT_SEPARATOR
This value may be supplied as the separator to executeSqlScript(javax.sql.DataSource, EncodedResource, String, String, String, String)
to denote that an SQL script contains a single statement (potentially
spanning multiple lines) with no explicit statement separator. Note that
such a script should not actually contain this value; it is merely a
virtual statement separator.
public static final String DEFAULT_COMMENT_PREFIX
public static final String DEFAULT_BLOCK_COMMENT_START_DELIMITER
public static final String DEFAULT_BLOCK_COMMENT_END_DELIMITER
public static void splitSqlScript(org.springframework.core.io.support.EncodedResource resource,
String script,
String separator,
String commentPrefix,
String blockCommentStartDelimiter,
String blockCommentEndDelimiter,
List<String> statements)
List.
Within the script, the provided 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
blockCommentStartDelimiter and 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.
resource - the resource from which the script was readscript - the SQL script; never null or emptyseparator - text separating each statement — typically a ';' or
newline character; never nullcommentPrefix - the prefix that identifies SQL line comments —
typically "--"; never null or emptyblockCommentStartDelimiter - the start block comment delimiter;
never null or emptyblockCommentEndDelimiter - the end block comment delimiter;
never null or emptystatements - the list that will contain the individual statementspublic static String readScript(LineNumberReader lineNumberReader, String commentPrefix, String separator) throws IOException
LineNumberReader, using the supplied
comment prefix and statement separator, and build a String containing
the lines.
Lines beginning 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.
lineNumberReader - the LineNumberReader containing the script
to be processedcommentPrefix - the prefix that identifies comments in the SQL script —
typically "--"separator - the statement separator in the SQL script — typically ";"String containing the script linesIOException - in case of I/O errorspublic static boolean containsSqlScriptDelimiters(String script, String delim)
script - the SQL scriptdelim - String delimiting each statement - typically a ';' characterpublic static void executeSqlScript(DataSource dataSource, org.springframework.core.io.Resource resource)
Statement separators and comments will be removed before executing individual statements within the supplied script.
Do not use this method to execute DDL if you expect rollback.
dataSource - the dataSource to use to execute the script; already
configured and ready to useresource - the resource to load the SQL script from; encoded with the
current platform's default encodingexecuteSqlScript(javax.sql.DataSource, EncodedResource, String, String, String, String),
DEFAULT_COMMENT_PREFIX,
DEFAULT_STATEMENT_SEPARATOR,
DEFAULT_BLOCK_COMMENT_START_DELIMITER,
DEFAULT_BLOCK_COMMENT_END_DELIMITERpublic static void executeSqlScript(DataSource dataSource, org.springframework.core.io.support.EncodedResource resource)
Statement separators and comments will be removed before executing individual statements within the supplied script.
Do not use this method to execute DDL if you expect rollback.
dataSource - the dataSource to use to execute the script; already
configured and ready to useresource - the resource (potentially associated with a specific encoding)
to load the SQL script fromexecuteSqlScript(DataSource, EncodedResource, String, String, String, String),
DEFAULT_COMMENT_PREFIX,
DEFAULT_STATEMENT_SEPARATOR,
DEFAULT_BLOCK_COMMENT_START_DELIMITER,
DEFAULT_BLOCK_COMMENT_END_DELIMITERpublic static void executeSqlScript(DataSource dataSource, org.springframework.core.io.support.EncodedResource resource, String commentPrefix, String separator, String blockCommentStartDelimiter, String blockCommentEndDelimiter)
Statement separators and comments will be removed before executing individual statements within the supplied script.
Do not use this method to execute DDL if you expect rollback.
dataSource - the dataSource to use to execute the script; already
configured and ready to useresource - the resource (potentially associated with a specific encoding)
to load the SQL script fromcommentPrefix - the prefix that identifies comments in the SQL script —
typically "--"separator - the script statement separator; defaults to
";" if not specified and falls back to
"\n" as a last resort; may be set to
"^^^ END OF SCRIPT ^^^" to signal that the script contains a
single statement without a separatorblockCommentStartDelimiter - the start block comment delimiter; never
null or emptyblockCommentEndDelimiter - the end block comment delimiter; never
null or emptyDEFAULT_STATEMENT_SEPARATOR,
FALLBACK_STATEMENT_SEPARATOR,
EOF_STATEMENT_SEPARATORCopyright © 2014. All rights reserved.