提交 92353459 编写于 作者: J Juergen Hoeller

ScriptUtils.executeSqlScript logs SQLWarnings at debug level

Issue: SPR-13959
上级 8495fcf1
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
......@@ -80,8 +80,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
/**
* Construct a new {@code ResourceDatabasePopulator} with default settings
* for the supplied scripts.
* @param scripts the scripts to execute to initialize or clean up the database;
* never {@code null}
* @param scripts the scripts to execute to initialize or clean up the database
* (never {@code null})
* @since 4.0.3
*/
public ResourceDatabasePopulator(Resource... scripts) {
......@@ -97,21 +97,23 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
* statement can be ignored
* @param sqlScriptEncoding the encoding for the supplied SQL scripts; may
* be {@code null} or <em>empty</em> to indicate platform encoding
* @param scripts the scripts to execute to initialize or clean up the database;
* never {@code null}
* @param scripts the scripts to execute to initialize or clean up the database
* (never {@code null})
* @since 4.0.3
*/
public ResourceDatabasePopulator(boolean continueOnError, boolean ignoreFailedDrops, String sqlScriptEncoding,
Resource... scripts) {
public ResourceDatabasePopulator(boolean continueOnError, boolean ignoreFailedDrops,
String sqlScriptEncoding, Resource... scripts) {
this(scripts);
this.continueOnError = continueOnError;
this.ignoreFailedDrops = ignoreFailedDrops;
setSqlScriptEncoding(sqlScriptEncoding);
}
/**
* Add a script to execute to initialize or clean up the database.
* @param script the path to an SQL script; never {@code null}
* @param script the path to an SQL script (never {@code null})
*/
public void addScript(Resource script) {
Assert.notNull(script, "Script must not be null");
......@@ -120,7 +122,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
/**
* Add multiple scripts to execute to initialize or clean up the database.
* @param scripts the scripts to execute; never {@code null}
* @param scripts the scripts to execute (never {@code null})
*/
public void addScripts(Resource... scripts) {
assertContentsOfScriptArray(scripts);
......@@ -130,7 +132,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
/**
* Set the scripts to execute to initialize or clean up the database,
* replacing any previously added scripts.
* @param scripts the scripts to execute; never {@code null}
* @param scripts the scripts to execute (never {@code null})
*/
public void setScripts(Resource... scripts) {
assertContentsOfScriptArray(scripts);
......@@ -173,8 +175,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
* Set the start delimiter that identifies block comments within the SQL
* scripts.
* <p>Defaults to {@code "/*"}.
* @param blockCommentStartDelimiter the start delimiter for block comments;
* never {@code null} or empty
* @param blockCommentStartDelimiter the start delimiter for block comments
* (never {@code null} or empty)
* @since 4.0.3
* @see #setBlockCommentEndDelimiter
*/
......@@ -187,8 +189,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
* Set the end delimiter that identifies block comments within the SQL
* scripts.
* <p>Defaults to <code>"*&#47;"</code>.
* @param blockCommentEndDelimiter the end delimiter for block comments;
* never {@code null} or empty
* @param blockCommentEndDelimiter the end delimiter for block comments
* (never {@code null} or empty)
* @since 4.0.3
* @see #setBlockCommentStartDelimiter
*/
......@@ -227,8 +229,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
Assert.notNull(connection, "Connection must not be null");
for (Resource script : getScripts()) {
ScriptUtils.executeSqlScript(connection, encodeScript(script), this.continueOnError,
this.ignoreFailedDrops, this.commentPrefix, this.separator, this.blockCommentStartDelimiter,
this.blockCommentEndDelimiter);
this.ignoreFailedDrops, this.commentPrefix, this.separator, this.blockCommentStartDelimiter,
this.blockCommentEndDelimiter);
}
}
......@@ -236,7 +238,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
* Execute this {@code ResourceDatabasePopulator} against the given
* {@link DataSource}.
* <p>Delegates to {@link DatabasePopulatorUtils#execute}.
* @param dataSource the {@code DataSource} to execute against; never {@code null}
* @param dataSource the {@code DataSource} to execute against (never {@code null})
* @throws ScriptException if an error occurs
* @since 4.1
* @see #populate(Connection)
......@@ -254,7 +256,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
* {@link EncodedResource} is not a sub-type of {@link Resource}. Thus we
* always need to wrap each script resource in an {@code EncodedResource}
* using the configured {@linkplain #setSqlScriptEncoding encoding}.
* @param script the script to wrap; never {@code null}
* @param script the script to wrap (never {@code null})
*/
private EncodedResource encodeScript(Resource script) {
Assert.notNull(script, "Script must not be null");
......
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
......@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.LineNumberReader;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
......@@ -399,7 +400,7 @@ public abstract class ScriptUtils {
*/
public static void executeSqlScript(Connection connection, EncodedResource resource) throws ScriptException {
executeSqlScript(connection, resource, false, false, DEFAULT_COMMENT_PREFIX, DEFAULT_STATEMENT_SEPARATOR,
DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER);
DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER);
}
/**
......@@ -472,7 +473,14 @@ public abstract class ScriptUtils {
stmt.execute(statement);
int rowsAffected = stmt.getUpdateCount();
if (logger.isDebugEnabled()) {
logger.debug(rowsAffected + " returned as updateCount for SQL: " + statement);
logger.debug(rowsAffected + " returned as update count for SQL: " + statement);
SQLWarning warningToLog = stmt.getWarnings();
while (warningToLog != null) {
logger.debug("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() +
"', error code '" + warningToLog.getErrorCode() +
"', message [" + warningToLog.getMessage() + "]");
warningToLog = warningToLog.getNextWarning();
}
}
}
catch (SQLException ex) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册