Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b9883c8c
提交
b9883c8c
authored
2月 21, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
INIT
上级
11ecd55b
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
138 行增加
和
144 行删除
+138
-144
changelog.html
h2/src/docsrc/html/changelog.html
+3
-3
Engine.java
h2/src/main/org/h2/engine/Engine.java
+12
-28
TestConnectionInfo.java
h2/src/test/org/h2/test/db/TestConnectionInfo.java
+49
-41
TestInit.java
h2/src/test/org/h2/test/server/TestInit.java
+74
-72
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
b9883c8c
...
...
@@ -23,7 +23,7 @@ Change Log
</li><li>
Creating a database was delayed about 2 seconds if the directory didn't exist.
</li><li>
Implemented INIT feature. If the database URL contains ";INIT=...;" then the DDL or DML commands
following are executed on startup. Example URL: jdbc:h2:mem:test;INIT=RUNSCRIPT FROM '~/create.sql'
(patch from Kerry Sainsbury)
(patch from Kerry Sainsbury)
.
</li></ul>
<h2>
Version 1.2.129 (2010-02-19)
</h2>
...
...
@@ -60,8 +60,8 @@ Change Log
</li><li>
The following system properties are no longer supported:
h2.overflowExceptions, h2.optimizeDropDependencies, h2.optimizeGroupSorted,
h2.optimizeMinMax, h2.optimizeNot, h2.optimizeIn, h2.optimizeInJoin, h2.reuseSpace*.
Most of then were there for
e a long time, but always with the same value.
There was no unit test with the other value. So changing them was potentially dangerous
Most of then were there for
a long time, but always with the same value.
There was no unit test with the other value. So changing them was potentially dangerous
(not a lot, but still).
</li><li>
The setting LOG has currently no effect (it only had an effect when the page store was disabled).
</li><li>
Disabling the page store is no longer supported. The old storage mechanism
...
...
h2/src/main/org/h2/engine/Engine.java
浏览文件 @
b9883c8c
...
...
@@ -6,8 +6,6 @@
*/
package
org
.
h2
.
engine
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.HashMap
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Parser
;
...
...
@@ -119,19 +117,11 @@ public class Engine {
throw
DbException
.
convert
(
e
);
}
}
String
init
=
ci
.
removeProperty
(
"INIT"
,
null
);
Session
session
=
openSession
(
ci
);
validateUserAndPassword
(
true
);
if
(
backup
!=
null
)
{
session
.
setConnectionInfo
(
backup
);
}
if
(
init
!=
null
)
{
runInitScripts
(
session
,
init
);
}
return
session
;
}
catch
(
DbException
e
)
{
if
(
e
.
getErrorCode
()
==
ErrorCode
.
WRONG_USER_OR_PASSWORD
)
{
...
...
@@ -141,28 +131,11 @@ public class Engine {
}
}
private
void
runInitScripts
(
Session
session
,
String
init
)
throws
DbException
{
Statement
stat
=
null
;
try
{
stat
=
session
.
createConnection
(
false
).
createStatement
();
stat
.
execute
(
init
);
}
catch
(
SQLException
e
)
{
throw
DbException
.
convert
(
e
);
}
finally
{
if
(
stat
!=
null
)
{
try
{
stat
.
close
();
}
catch
(
SQLException
e
)
{
throw
DbException
.
convert
(
e
);
}
}
}
}
private
synchronized
Session
openSession
(
ConnectionInfo
ci
)
{
boolean
ifExists
=
ci
.
removeProperty
(
"IFEXISTS"
,
false
);
boolean
ignoreUnknownSetting
=
ci
.
removeProperty
(
"IGNORE_UNKNOWN_SETTINGS"
,
false
);
String
cipher
=
ci
.
removeProperty
(
"CIPHER"
,
null
);
String
init
=
ci
.
removeProperty
(
"INIT"
,
null
);
Session
session
;
while
(
true
)
{
session
=
openSession
(
ci
,
ifExists
,
cipher
);
...
...
@@ -191,6 +164,17 @@ public class Engine {
}
}
}
if
(
init
!=
null
)
{
try
{
CommandInterface
command
=
session
.
prepareCommand
(
init
,
Integer
.
MAX_VALUE
);
command
.
executeUpdate
();
}
catch
(
DbException
e
)
{
if
(!
ignoreUnknownSetting
)
{
session
.
close
();
throw
e
;
}
}
}
session
.
setAllowLiterals
(
false
);
session
.
commit
(
true
);
session
.
getDatabase
().
getTrace
(
Trace
.
SESSION
).
info
(
"connected #"
+
session
.
getId
());
...
...
h2/src/test/org/h2/test/db/TestConnectionInfo.java
浏览文件 @
b9883c8c
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
db
;
import
org.h2.test.TestBase
;
import
org.h2.engine.ConnectionInfo
;
import
java.util.Properties
;
/**
*/
public
class
TestConnectionInfo
extends
TestBase
{
public
static
void
main
(
String
[]
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
Properties
info
=
new
Properties
();
ConnectionInfo
connectionInfo
=
new
ConnectionInfo
(
"jdbc:h2:mem:testdb"
+
";LOG=2"
+
";ACCESS_MODE_DATA=rws"
+
";INIT=INSERT this...\\;UPDATE that..."
+
";IFEXISTS=TRUE"
,
info
);
assertEquals
(
"jdbc:h2:mem:testdb"
,
connectionInfo
.
getURL
());
assertEquals
(
"2"
,
connectionInfo
.
getProperty
(
"LOG"
,
""
));
assertEquals
(
"rws"
,
connectionInfo
.
getProperty
(
"ACCESS_MODE_DATA"
,
""
));
assertEquals
(
"INSERT this...;UPDATE that..."
,
connectionInfo
.
getProperty
(
"INIT"
,
""
));
assertEquals
(
"TRUE"
,
connectionInfo
.
getProperty
(
"IFEXISTS"
,
""
));
assertEquals
(
"undefined"
,
connectionInfo
.
getProperty
(
"CACHE_TYPE"
,
"undefined"
));
}
}
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
db
;
import
org.h2.test.TestBase
;
import
org.h2.engine.ConnectionInfo
;
import
java.util.Properties
;
/**
* Test the ConnectionInfo class.
*
* @author Kerry Sainsbury
*/
public
class
TestConnectionInfo
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
Properties
info
=
new
Properties
();
ConnectionInfo
connectionInfo
=
new
ConnectionInfo
(
"jdbc:h2:mem:testdb"
+
";LOG=2"
+
";ACCESS_MODE_DATA=rws"
+
";INIT=CREATE this...\\;INSERT that..."
+
";IFEXISTS=TRUE"
,
info
);
assertEquals
(
"jdbc:h2:mem:testdb"
,
connectionInfo
.
getURL
());
assertEquals
(
"2"
,
connectionInfo
.
getProperty
(
"LOG"
,
""
));
assertEquals
(
"rws"
,
connectionInfo
.
getProperty
(
"ACCESS_MODE_DATA"
,
""
));
assertEquals
(
"CREATE this...;INSERT that..."
,
connectionInfo
.
getProperty
(
"INIT"
,
""
));
assertEquals
(
"TRUE"
,
connectionInfo
.
getProperty
(
"IFEXISTS"
,
""
));
assertEquals
(
"undefined"
,
connectionInfo
.
getProperty
(
"CACHE_TYPE"
,
"undefined"
));
}
}
h2/src/test/org/h2/test/server/TestInit.java
浏览文件 @
b9883c8c
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
server
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
import
java.sql.*
;
import
java.io.FileWriter
;
import
java.io.PrintWriter
;
/**
* Tests INIT command within embedded/server mode.
*/
public
class
TestInit
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
// Create two scripts that we will run via "INIT"
FileWriter
fw
=
new
FileWriter
(
baseDir
+
"/test-init-1.sql"
);
PrintWriter
writer
=
new
PrintWriter
(
fw
);
writer
.
println
(
"create table test(id int identity, name varchar);"
);
writer
.
println
(
"insert into test(name) values('cat');"
);
writer
.
close
();
fw
=
new
FileWriter
(
baseDir
+
"/test-init-2.sql"
);
writer
=
new
PrintWriter
(
fw
);
writer
.
println
(
"insert into test(name) values('dog');"
);
writer
.
close
();
// Make the database connection, and run the two scripts
deleteDb
(
"initDb"
);
Connection
conn
=
getConnection
(
"initDb;"
+
"INIT="
+
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-1.sql'\\;"
+
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-2.sql'"
);
Statement
stat
=
conn
.
createStatement
();
// Confirm our scripts have run by loading the data they inserted
ResultSet
rs
=
stat
.
executeQuery
(
"select name from test order by name"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"cat"
,
rs
.
getString
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
"dog"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"initDb"
);
IOUtils
.
delete
(
baseDir
+
"/test-init-1.sql"
);
IOUtils
.
delete
(
baseDir
+
"/test-init-2.sql"
);
}
}
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
server
;
import
java.io.FileWriter
;
import
java.io.PrintWriter
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
* Tests INIT command within embedded/server mode.
*/
public
class
TestInit
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
// Create two scripts that we will run via "INIT"
IOUtils
.
createDirs
(
baseDir
+
"/test-init-1.sql"
);
FileWriter
fw
=
new
FileWriter
(
baseDir
+
"/test-init-1.sql"
);
PrintWriter
writer
=
new
PrintWriter
(
fw
);
writer
.
println
(
"create table test(id int identity, name varchar);"
);
writer
.
println
(
"insert into test(name) values('cat');"
);
writer
.
close
();
fw
=
new
FileWriter
(
baseDir
+
"/test-init-2.sql"
);
writer
=
new
PrintWriter
(
fw
);
writer
.
println
(
"insert into test(name) values('dog');"
);
writer
.
close
();
// Make the database connection, and run the two scripts
deleteDb
(
"initDb"
);
Connection
conn
=
getConnection
(
"initDb;"
+
"INIT="
+
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-1.sql'\\;"
+
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-2.sql'"
);
Statement
stat
=
conn
.
createStatement
();
// Confirm our scripts have run by loading the data they inserted
ResultSet
rs
=
stat
.
executeQuery
(
"select name from test order by name"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"cat"
,
rs
.
getString
(
1
));
assertTrue
(
rs
.
next
());
assertEquals
(
"dog"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"initDb"
);
IOUtils
.
delete
(
baseDir
+
"/test-init-1.sql"
);
IOUtils
.
delete
(
baseDir
+
"/test-init-2.sql"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论