Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
601c59ba
提交
601c59ba
authored
1月 14, 2015
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Script tool: Now, SCRIPT ... TO is always used (for higher speed and lower disk space usage).
上级
31f7cb05
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
80 行删除
+20
-80
CreateCluster.java
h2/src/main/org/h2/tools/CreateCluster.java
+1
-13
Script.java
h2/src/main/org/h2/tools/Script.java
+18
-66
Compact.java
h2/src/test/org/h2/samples/Compact.java
+1
-1
没有找到文件。
h2/src/main/org/h2/tools/CreateCluster.java
浏览文件 @
601c59ba
...
...
@@ -5,8 +5,6 @@
*/
package
org
.
h2
.
tools
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
...
...
@@ -14,9 +12,7 @@ import java.sql.Statement;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.message.DbException
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.Tool
;
...
...
@@ -148,15 +144,7 @@ public class CreateCluster extends Tool {
// backup
Script
script
=
new
Script
();
script
.
setOut
(
out
);
OutputStream
scriptOut
=
null
;
try
{
scriptOut
=
FileUtils
.
newOutputStream
(
scriptFile
,
false
);
Script
.
process
(
connSource
,
scriptOut
);
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
null
);
}
finally
{
IOUtils
.
closeSilently
(
scriptOut
);
}
Script
.
process
(
connSource
,
scriptFile
,
""
,
""
);
// delete the target database and then restore
connTarget
=
DriverManager
.
getConnection
(
...
...
h2/src/main/org/h2/tools/Script.java
浏览文件 @
601c59ba
...
...
@@ -5,17 +5,11 @@
*/
package
org
.
h2
.
tools
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.PrintWriter
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.message.DbException
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Tool
;
...
...
@@ -58,7 +52,8 @@ public class Script extends Tool {
String
user
=
""
;
String
password
=
""
;
String
file
=
"backup.sql"
;
String
options1
=
null
,
options2
=
null
;
String
options1
=
""
;
String
options2
=
""
;
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
String
arg
=
args
[
i
];
if
(
arg
.
equals
(
"-url"
))
{
...
...
@@ -103,90 +98,47 @@ public class Script extends Tool {
showUsage
();
throw
new
SQLException
(
"URL not set"
);
}
if
(
options1
!=
null
)
{
processScript
(
url
,
user
,
password
,
file
,
options1
,
options2
);
}
else
{
execute
(
url
,
user
,
password
,
file
);
}
}
private
static
void
processScript
(
String
url
,
String
user
,
String
password
,
String
fileName
,
String
options1
,
String
options2
)
throws
SQLException
{
Connection
conn
=
null
;
Statement
stat
=
null
;
try
{
org
.
h2
.
Driver
.
load
();
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
stat
=
conn
.
createStatement
();
String
sql
=
"SCRIPT "
+
options1
+
" TO '"
+
fileName
+
"' "
+
options2
;
stat
.
execute
(
sql
);
}
finally
{
JdbcUtils
.
closeSilently
(
stat
);
JdbcUtils
.
closeSilently
(
conn
);
}
process
(
url
,
user
,
password
,
file
,
options1
,
options2
);
}
/**
* Backs up a database to a
SQL script file
.
* Backs up a database to a
stream
.
*
* @param url the database URL
* @param user the user name
* @param password the password
* @param fileName the script file
* @param fileName the target file name
* @param options1 the options before the file name (may be an empty string)
* @param options2 the options after the file name (may be an empty string)
*/
public
static
void
execute
(
String
url
,
String
user
,
String
password
,
String
fileName
)
throws
SQLException
{
OutputStream
o
=
null
;
try
{
o
=
FileUtils
.
newOutputStream
(
fileName
,
false
);
execute
(
url
,
user
,
password
,
o
);
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
null
);
}
finally
{
IOUtils
.
closeSilently
(
o
);
}
}
/**
* Backs up a database to a stream. The stream is not closed.
*
* @param url the database URL
* @param user the user name
* @param password the password
* @param out the output stream
*/
public
static
void
execute
(
String
url
,
String
user
,
String
password
,
OutputStream
out
)
throws
SQLException
{
public
static
void
process
(
String
url
,
String
user
,
String
password
,
String
fileName
,
String
options1
,
String
options2
)
throws
SQLException
{
Connection
conn
=
null
;
try
{
org
.
h2
.
Driver
.
load
();
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
process
(
conn
,
out
);
process
(
conn
,
fileName
,
options1
,
options2
);
}
finally
{
JdbcUtils
.
closeSilently
(
conn
);
}
}
/**
* Backs up a database to a stream. The stream is not closed.
* The connection is not closed.
*
* @param conn the connection
* @param out the output stream
* @param fileName the target file name
* @param options1 the options before the file name
* @param options2 the options after the file name
*/
static
void
process
(
Connection
conn
,
OutputStream
out
)
throws
SQLException
{
public
static
void
process
(
Connection
conn
,
String
fileName
,
String
options1
,
String
options2
)
throws
SQLException
{
Statement
stat
=
null
;
try
{
stat
=
conn
.
createStatement
();
PrintWriter
writer
=
new
PrintWriter
(
IOUtils
.
getBufferedWriter
(
out
));
ResultSet
rs
=
stat
.
executeQuery
(
"SCRIPT"
);
while
(
rs
.
next
())
{
String
s
=
rs
.
getString
(
1
);
writer
.
println
(
s
);
}
writer
.
flush
();
String
sql
=
"SCRIPT "
+
options1
+
" TO '"
+
fileName
+
"' "
+
options2
;
stat
.
execute
(
sql
);
}
finally
{
JdbcUtils
.
closeSilently
(
stat
);
}
...
...
h2/src/test/org/h2/samples/Compact.java
浏览文件 @
601c59ba
...
...
@@ -54,7 +54,7 @@ public class Compact {
String
user
,
String
password
)
throws
SQLException
{
String
url
=
"jdbc:h2:"
+
dir
+
"/"
+
dbName
;
String
file
=
"data/test.sql"
;
Script
.
execute
(
url
,
user
,
password
,
file
);
Script
.
process
(
url
,
user
,
password
,
file
,
""
,
""
);
DeleteDbFiles
.
execute
(
dir
,
dbName
,
true
);
RunScript
.
execute
(
url
,
user
,
password
,
file
,
null
,
false
);
FileUtils
.
delete
(
file
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论