Introduce buildErrorMessage() utility in ScriptStatementFailedException
To eliminate code duplication, ScriptStatementFailedException and ScriptUtils now delegate to a new buildErrorMessage() utility method. Issue: SPR-12752
This commit is contained in:
parent
fe8289b5e3
commit
448c99f224
|
|
@ -29,6 +29,18 @@ import org.springframework.core.io.support.EncodedResource;
|
|||
@SuppressWarnings("serial")
|
||||
public class ScriptStatementFailedException extends ScriptException {
|
||||
|
||||
/**
|
||||
* Build an error message based on the supplied parameters.
|
||||
* @param statement the actual SQL statement that failed
|
||||
* @param statementNumber the statement number in the SQL script (i.e.,
|
||||
* the nth statement present in the resource)
|
||||
* @param encodedResource the resource from which the SQL statement was read
|
||||
*/
|
||||
public static String buildErrorMessage(String statement, int statementNumber, EncodedResource encodedResource) {
|
||||
return String.format("Failed to execute SQL script statement #%s of %s: %s",
|
||||
statementNumber, encodedResource, statement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code ScriptStatementFailedException}.
|
||||
* @param statement the actual SQL statement that failed
|
||||
|
|
@ -38,8 +50,7 @@ public class ScriptStatementFailedException extends ScriptException {
|
|||
* @param cause the underlying cause of the failure
|
||||
*/
|
||||
public ScriptStatementFailedException(String statement, int statementNumber, EncodedResource resource, Throwable cause) {
|
||||
super("Failed to execute SQL script statement #" + statementNumber + " of resource " + resource + ": "
|
||||
+ statement, cause);
|
||||
super(buildErrorMessage(statement, statementNumber, resource), cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -464,8 +464,7 @@ public abstract class ScriptUtils {
|
|||
boolean dropStatement = StringUtils.startsWithIgnoreCase(statement.trim(), "drop");
|
||||
if (continueOnError || (dropStatement && ignoreFailedDrops)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to execute SQL script statement #" + stmtNumber +
|
||||
" of resource " + resource + ": " + statement, ex);
|
||||
logger.debug(ScriptStatementFailedException.buildErrorMessage(statement, stmtNumber, resource), ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue