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
...
@@ -23,7 +23,7 @@ Change Log
</li><li>
Creating a database was delayed about 2 seconds if the directory didn't exist.
</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
</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'
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>
</li></ul>
<h2>
Version 1.2.129 (2010-02-19)
</h2>
<h2>
Version 1.2.129 (2010-02-19)
</h2>
...
@@ -60,8 +60,8 @@ Change Log
...
@@ -60,8 +60,8 @@ Change Log
</li><li>
The following system properties are no longer supported:
</li><li>
The following system properties are no longer supported:
h2.overflowExceptions, h2.optimizeDropDependencies, h2.optimizeGroupSorted,
h2.overflowExceptions, h2.optimizeDropDependencies, h2.optimizeGroupSorted,
h2.optimizeMinMax, h2.optimizeNot, h2.optimizeIn, h2.optimizeInJoin, h2.reuseSpace*.
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.
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
There was no unit test with the other value. So changing them was potentially dangerous
(not a lot, but still).
(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>
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
</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 @@
...
@@ -6,8 +6,6 @@
*/
*/
package
org
.
h2
.
engine
;
package
org
.
h2
.
engine
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
...
@@ -119,19 +117,11 @@ public class Engine {
...
@@ -119,19 +117,11 @@ public class Engine {
throw
DbException
.
convert
(
e
);
throw
DbException
.
convert
(
e
);
}
}
}
}
String
init
=
ci
.
removeProperty
(
"INIT"
,
null
);
Session
session
=
openSession
(
ci
);
Session
session
=
openSession
(
ci
);
validateUserAndPassword
(
true
);
validateUserAndPassword
(
true
);
if
(
backup
!=
null
)
{
if
(
backup
!=
null
)
{
session
.
setConnectionInfo
(
backup
);
session
.
setConnectionInfo
(
backup
);
}
}
if
(
init
!=
null
)
{
runInitScripts
(
session
,
init
);
}
return
session
;
return
session
;
}
catch
(
DbException
e
)
{
}
catch
(
DbException
e
)
{
if
(
e
.
getErrorCode
()
==
ErrorCode
.
WRONG_USER_OR_PASSWORD
)
{
if
(
e
.
getErrorCode
()
==
ErrorCode
.
WRONG_USER_OR_PASSWORD
)
{
...
@@ -141,28 +131,11 @@ public class Engine {
...
@@ -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
)
{
private
synchronized
Session
openSession
(
ConnectionInfo
ci
)
{
boolean
ifExists
=
ci
.
removeProperty
(
"IFEXISTS"
,
false
);
boolean
ifExists
=
ci
.
removeProperty
(
"IFEXISTS"
,
false
);
boolean
ignoreUnknownSetting
=
ci
.
removeProperty
(
"IGNORE_UNKNOWN_SETTINGS"
,
false
);
boolean
ignoreUnknownSetting
=
ci
.
removeProperty
(
"IGNORE_UNKNOWN_SETTINGS"
,
false
);
String
cipher
=
ci
.
removeProperty
(
"CIPHER"
,
null
);
String
cipher
=
ci
.
removeProperty
(
"CIPHER"
,
null
);
String
init
=
ci
.
removeProperty
(
"INIT"
,
null
);
Session
session
;
Session
session
;
while
(
true
)
{
while
(
true
)
{
session
=
openSession
(
ci
,
ifExists
,
cipher
);
session
=
openSession
(
ci
,
ifExists
,
cipher
);
...
@@ -191,6 +164,17 @@ public class Engine {
...
@@ -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
.
setAllowLiterals
(
false
);
session
.
commit
(
true
);
session
.
commit
(
true
);
session
.
getDatabase
().
getTrace
(
Trace
.
SESSION
).
info
(
"connected #"
+
session
.
getId
());
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,
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Initial Developer: H2 Group
*/
*/
package
org
.
h2
.
test
.
db
;
package
org
.
h2
.
test
.
db
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.engine.ConnectionInfo
;
import
org.h2.engine.ConnectionInfo
;
import
java.util.Properties
;
import
java.util.Properties
;
/**
/**
*/
* Test the ConnectionInfo class.
public
class
TestConnectionInfo
extends
TestBase
{
*
* @author Kerry Sainsbury
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
public
class
TestConnectionInfo
extends
TestBase
{
TestBase
.
createCaller
().
init
().
test
();
}
/**
* Run just this test.
public
void
test
()
throws
Exception
{
*
Properties
info
=
new
Properties
();
* @param a ignored
ConnectionInfo
connectionInfo
=
new
ConnectionInfo
(
*/
"jdbc:h2:mem:testdb"
+
public
static
void
main
(
String
[]
a
)
throws
Exception
{
";LOG=2"
+
TestBase
.
createCaller
().
init
().
test
();
";ACCESS_MODE_DATA=rws"
+
}
";INIT=INSERT this...\\;UPDATE that..."
+
";IFEXISTS=TRUE"
,
public
void
test
()
throws
Exception
{
info
);
Properties
info
=
new
Properties
();
ConnectionInfo
connectionInfo
=
new
ConnectionInfo
(
assertEquals
(
"jdbc:h2:mem:testdb"
,
connectionInfo
.
getURL
());
"jdbc:h2:mem:testdb"
+
";LOG=2"
+
assertEquals
(
"2"
,
connectionInfo
.
getProperty
(
"LOG"
,
""
));
";ACCESS_MODE_DATA=rws"
+
assertEquals
(
"rws"
,
connectionInfo
.
getProperty
(
"ACCESS_MODE_DATA"
,
""
));
";INIT=CREATE this...\\;INSERT that..."
+
assertEquals
(
"INSERT this...;UPDATE that..."
,
connectionInfo
.
getProperty
(
"INIT"
,
""
));
";IFEXISTS=TRUE"
,
assertEquals
(
"TRUE"
,
connectionInfo
.
getProperty
(
"IFEXISTS"
,
""
));
info
);
assertEquals
(
"undefined"
,
connectionInfo
.
getProperty
(
"CACHE_TYPE"
,
"undefined"
));
}
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,
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Initial Developer: H2 Group
*/
*/
package
org
.
h2
.
test
.
server
;
package
org
.
h2
.
test
.
server
;
import
org.h2.test.TestBase
;
import
java.io.FileWriter
;
import
org.h2.util.IOUtils
;
import
java.io.PrintWriter
;
import
java.sql.Connection
;
import
java.sql.*
;
import
java.sql.ResultSet
;
import
java.io.FileWriter
;
import
java.sql.Statement
;
import
java.io.PrintWriter
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
* Tests INIT command within embedded/server mode.
/**
*/
* Tests INIT command within embedded/server mode.
public
class
TestInit
extends
TestBase
{
*/
public
class
TestInit
extends
TestBase
{
/**
* Run just this test.
/**
*
* Run just this test.
* @param a ignored
*
*/
* @param a ignored
public
static
void
main
(
String
[]
a
)
throws
Exception
{
*/
TestBase
.
createCaller
().
init
().
test
();
public
static
void
main
(
String
[]
a
)
throws
Exception
{
}
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
// Create two scripts that we will run via "INIT"
FileWriter
fw
=
new
FileWriter
(
baseDir
+
"/test-init-1.sql"
);
// Create two scripts that we will run via "INIT"
IOUtils
.
createDirs
(
baseDir
+
"/test-init-1.sql"
);
PrintWriter
writer
=
new
PrintWriter
(
fw
);
FileWriter
fw
=
new
FileWriter
(
baseDir
+
"/test-init-1.sql"
);
writer
.
println
(
"create table test(id int identity, name varchar);"
);
writer
.
println
(
"insert into test(name) values('cat');"
);
PrintWriter
writer
=
new
PrintWriter
(
fw
);
writer
.
close
();
writer
.
println
(
"create table test(id int identity, name varchar);"
);
writer
.
println
(
"insert into test(name) values('cat');"
);
fw
=
new
FileWriter
(
baseDir
+
"/test-init-2.sql"
);
writer
.
close
();
writer
=
new
PrintWriter
(
fw
);
writer
.
println
(
"insert into test(name) values('dog');"
);
fw
=
new
FileWriter
(
baseDir
+
"/test-init-2.sql"
);
writer
.
close
();
writer
=
new
PrintWriter
(
fw
);
writer
.
println
(
"insert into test(name) values('dog');"
);
// Make the database connection, and run the two scripts
writer
.
close
();
deleteDb
(
"initDb"
);
Connection
conn
=
getConnection
(
"initDb;"
+
// Make the database connection, and run the two scripts
"INIT="
+
deleteDb
(
"initDb"
);
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-1.sql'\\;"
+
Connection
conn
=
getConnection
(
"initDb;"
+
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-2.sql'"
);
"INIT="
+
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-1.sql'\\;"
+
Statement
stat
=
conn
.
createStatement
();
"RUNSCRIPT FROM '"
+
baseDir
+
"/test-init-2.sql'"
);
// Confirm our scripts have run by loading the data they inserted
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select name from test order by name"
);
// Confirm our scripts have run by loading the data they inserted
assertTrue
(
rs
.
next
());
ResultSet
rs
=
stat
.
executeQuery
(
"select name from test order by name"
);
assertEquals
(
"cat"
,
rs
.
getString
(
1
));
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
"cat"
,
rs
.
getString
(
1
));
assertEquals
(
"dog"
,
rs
.
getString
(
1
));
assertTrue
(
rs
.
next
());
assertFalse
(
rs
.
next
());
assertEquals
(
"dog"
,
rs
.
getString
(
1
));
conn
.
close
();
assertFalse
(
rs
.
next
());
deleteDb
(
"initDb"
);
conn
.
close
();
IOUtils
.
delete
(
baseDir
+
"/test-init-1.sql"
);
deleteDb
(
"initDb"
);
IOUtils
.
delete
(
baseDir
+
"/test-init-2.sql"
);
IOUtils
.
delete
(
baseDir
+
"/test-init-1.sql"
);
}
IOUtils
.
delete
(
baseDir
+
"/test-init-2.sql"
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论