Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
39b11771
提交
39b11771
authored
9月 15, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New sample application that shows how to pass data to a trigger.
上级
0d3a6cc7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
76 行增加
和
1 行删除
+76
-1
changelog.html
h2/src/docsrc/html/changelog.html
+2
-1
TriggerPassData.java
h2/src/test/org/h2/samples/TriggerPassData.java
+71
-0
TestSampleApps.java
h2/src/test/org/h2/test/unit/TestSampleApps.java
+3
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
39b11771
...
...
@@ -18,7 +18,8 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
More bugs in the server-less multi-connection mode have been fixed:
<ul><li>
New sample application that shows how to pass data to a trigger.
</li><li>
More bugs in the server-less multi-connection mode have been fixed:
On Windows, two processes could write to the same database at the same time.
</li><li>
When loading triggers or other client classes
(static functions, database event listener, user aggregate functions, other JDBC drivers),
...
...
h2/src/test/org/h2/samples/TriggerPassData.java
0 → 100644
浏览文件 @
39b11771
/*
* Copyright 2004-2009 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
.
samples
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.Statement
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.h2.api.Trigger
;
/**
* This sample application shows how to pass data to a trigger.
*/
public
class
TriggerPassData
implements
Trigger
{
private
static
final
Map
<
String
,
TriggerPassData
>
TRIGGERS
=
new
HashMap
<
String
,
TriggerPassData
>();
private
String
triggerData
;
/**
* This method is called when executing this sample application from the
* command line.
*
* @param args the command line parameters
*/
public
static
void
main
(
String
...
args
)
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:"
,
"sa"
,
""
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"CREATE ALIAS TRIGGER_SET FOR \""
+
TriggerPassData
.
class
.
getName
()
+
".setTriggerData\""
);
stat
.
execute
(
"CREATE TRIGGER T1 "
+
"BEFORE INSERT ON TEST "
+
"FOR EACH ROW CALL \""
+
TriggerPassData
.
class
.
getName
()
+
"\""
);
stat
.
execute
(
"CALL TRIGGER_SET('T1', 'Hello')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
stat
.
execute
(
"CALL TRIGGER_SET('T1', 'World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(2)"
);
conn
.
close
();
}
public
void
init
(
Connection
conn
,
String
schemaName
,
String
triggerName
,
String
tableName
,
boolean
before
,
int
type
)
{
TRIGGERS
.
put
(
triggerName
,
this
);
}
public
void
fire
(
Connection
conn
,
Object
[]
old
,
Object
[]
row
)
{
System
.
out
.
println
(
triggerData
+
": "
+
row
[
0
]);
}
/**
* Call this method to change a specific trigger.
*
* @param trigger the trigger name
* @param data the data
*/
public
static
void
setTriggerData
(
String
trigger
,
String
data
)
{
TRIGGERS
.
get
(
trigger
).
triggerData
=
data
;
}
}
h2/src/test/org/h2/test/unit/TestSampleApps.java
浏览文件 @
39b11771
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
test
.
unit
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.PrintStream
;
...
...
@@ -35,6 +36,7 @@ public class TestSampleApps extends TestBase {
public
void
test
()
throws
Exception
{
deleteDb
(
"optimizations"
);
InputStream
in
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"org/h2/samples/optimizations.sql"
);
new
File
(
baseDir
).
mkdirs
();
FileOutputStream
out
=
new
FileOutputStream
(
baseDir
+
"/optimizations.sql"
);
IOUtils
.
copyAndClose
(
in
,
out
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/optimizations"
;
...
...
@@ -54,6 +56,7 @@ public class TestSampleApps extends TestBase {
// TODO test ShutdownServer (server needs to be started in a separate
// process)
testApp
(
"The sum is 20.00"
,
org
.
h2
.
samples
.
TriggerSample
.
class
);
testApp
(
"Hello: 1\nWorld: 2"
,
org
.
h2
.
samples
.
TriggerPassData
.
class
);
// tools
testApp
(
"Allows changing the database file encryption password or algorithm*"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论