Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
92353459
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92353459
编写于
2月 18, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ScriptUtils.executeSqlScript logs SQLWarnings at debug level
Issue: SPR-13959
上级
8495fcf1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
21 deletion
+31
-21
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java
...ework/jdbc/datasource/init/ResourceDatabasePopulator.java
+20
-18
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java
...org/springframework/jdbc/datasource/init/ScriptUtils.java
+11
-3
未找到文件。
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java
浏览文件 @
92353459
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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>"*/"</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"
);
...
...
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java
浏览文件 @
92353459
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录