Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1f1226d1
提交
1f1226d1
authored
4月 13, 2012
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add methods to DatabaseEventListener to notify of statement start and statement end.
Patch from Steve McLeod steve.mcleod@gmail.com
上级
eaeb0c7c
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
64 行增加
和
3 行删除
+64
-3
changelog.html
h2/src/docsrc/html/changelog.html
+2
-1
DatabaseEventListener.java
h2/src/main/org/h2/api/DatabaseEventListener.java
+11
-1
Command.java
h2/src/main/org/h2/command/Command.java
+10
-0
CommandContainer.java
h2/src/main/org/h2/command/CommandContainer.java
+4
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+5
-0
TestDatabaseEventListener.java
h2/src/test/org/h2/test/jdbc/TestDatabaseEventListener.java
+32
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
1f1226d1
...
@@ -18,7 +18,8 @@ Change Log
...
@@ -18,7 +18,8 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The table INFORMATION_SCHEMA.FUNCTION_ALIASES now includes a column TYPE_NAME.
<ul><li>
DatabaseEventListener now calls setProgress whenever a statement starts and ends.
</li><li>
The table INFORMATION_SCHEMA.FUNCTION_ALIASES now includes a column TYPE_NAME.
</li><li>
Issue 378: when using views, the wrong values were bound to a parameter in some cases.
</li><li>
Issue 378: when using views, the wrong values were bound to a parameter in some cases.
</li><li>
Terrence Huang has translated the error messages to Chinese. Thanks a lot!
</li><li>
Terrence Huang has translated the error messages to Chinese. Thanks a lot!
</li></ul>
</li></ul>
...
...
h2/src/main/org/h2/api/DatabaseEventListener.java
浏览文件 @
1f1226d1
...
@@ -44,6 +44,16 @@ public interface DatabaseEventListener extends EventListener {
...
@@ -44,6 +44,16 @@ public interface DatabaseEventListener extends EventListener {
*/
*/
int
STATE_RECONNECTED
=
4
;
int
STATE_RECONNECTED
=
4
;
/**
* This state is used when a query starts.
*/
int
STATE_STATEMENT_START
=
5
;
/**
* This state is used when a query ends.
*/
int
STATE_STATEMENT_END
=
6
;
/**
/**
* This method is called just after creating the object.
* This method is called just after creating the object.
* This is done when opening the database if the listener is specified
* This is done when opening the database if the listener is specified
...
@@ -79,7 +89,7 @@ public interface DatabaseEventListener extends EventListener {
...
@@ -79,7 +89,7 @@ public interface DatabaseEventListener extends EventListener {
* @param state the state
* @param state the state
* @param name the object name
* @param name the object name
* @param x the current position
* @param x the current position
* @param max the highest value
* @param max the highest value
, -1 if the max value is unknown
*/
*/
void
setProgress
(
int
state
,
String
name
,
int
x
,
int
max
);
void
setProgress
(
int
state
,
String
name
,
int
x
,
int
max
);
...
...
h2/src/main/org/h2/command/Command.java
浏览文件 @
1f1226d1
...
@@ -8,6 +8,8 @@ package org.h2.command;
...
@@ -8,6 +8,8 @@ package org.h2.command;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
...
@@ -123,6 +125,14 @@ public abstract class Command implements CommandInterface {
...
@@ -123,6 +125,14 @@ public abstract class Command implements CommandInterface {
}
}
}
}
void
publishStart
()
{
session
.
getDatabase
().
publishEvent
(
DatabaseEventListener
.
STATE_STATEMENT_START
,
sql
);
}
void
publishEnd
()
{
session
.
getDatabase
().
publishEvent
(
DatabaseEventListener
.
STATE_STATEMENT_END
,
sql
);
}
/**
/**
* Check if this command has been canceled, and throw an exception if yes.
* Check if this command has been canceled, and throw an exception if yes.
*
*
...
...
h2/src/main/org/h2/command/CommandContainer.java
浏览文件 @
1f1226d1
...
@@ -67,20 +67,24 @@ class CommandContainer extends Command {
...
@@ -67,20 +67,24 @@ class CommandContainer extends Command {
public
int
update
()
{
public
int
update
()
{
recompileIfRequired
();
recompileIfRequired
();
publishStart
();
start
();
start
();
session
.
setLastIdentity
(
ValueNull
.
INSTANCE
);
session
.
setLastIdentity
(
ValueNull
.
INSTANCE
);
prepared
.
checkParameters
();
prepared
.
checkParameters
();
int
updateCount
=
prepared
.
update
();
int
updateCount
=
prepared
.
update
();
prepared
.
trace
(
startTime
,
updateCount
);
prepared
.
trace
(
startTime
,
updateCount
);
publishEnd
();
return
updateCount
;
return
updateCount
;
}
}
public
ResultInterface
query
(
int
maxrows
)
{
public
ResultInterface
query
(
int
maxrows
)
{
recompileIfRequired
();
recompileIfRequired
();
publishStart
();
start
();
start
();
prepared
.
checkParameters
();
prepared
.
checkParameters
();
ResultInterface
result
=
prepared
.
query
(
maxrows
);
ResultInterface
result
=
prepared
.
query
(
maxrows
);
prepared
.
trace
(
startTime
,
result
.
getRowCount
());
prepared
.
trace
(
startTime
,
result
.
getRowCount
());
publishEnd
();
return
result
;
return
result
;
}
}
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
1f1226d1
...
@@ -2406,4 +2406,9 @@ public class Database implements DataHandler {
...
@@ -2406,4 +2406,9 @@ public class Database implements DataHandler {
throw
DbException
.
throwInternalError
();
throw
DbException
.
throwInternalError
();
}
}
public
void
publishEvent
(
int
state
,
String
sql
)
{
if
(
eventListener
!=
null
)
{
eventListener
.
setProgress
(
state
,
sql
,
0
,
-
1
);
}
}
}
}
h2/src/test/org/h2/test/jdbc/TestDatabaseEventListener.java
浏览文件 @
1f1226d1
...
@@ -23,6 +23,7 @@ import org.h2.test.TestBase;
...
@@ -23,6 +23,7 @@ import org.h2.test.TestBase;
public
class
TestDatabaseEventListener
extends
TestBase
implements
DatabaseEventListener
{
public
class
TestDatabaseEventListener
extends
TestBase
implements
DatabaseEventListener
{
private
static
boolean
calledOpened
,
calledClosingDatabase
,
calledScan
,
calledCreateIndex
;
private
static
boolean
calledOpened
,
calledClosingDatabase
,
calledScan
,
calledCreateIndex
;
private
static
boolean
calledStatementStart
,
calledStatementEnd
;
/**
/**
* Run just this test.
* Run just this test.
...
@@ -40,6 +41,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
...
@@ -40,6 +41,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
testCalled
();
testCalled
();
testCloseLog0
(
false
);
testCloseLog0
(
false
);
testCloseLog0
(
true
);
testCloseLog0
(
true
);
testCalledForStatement
();
deleteDb
(
"databaseEventListener"
);
deleteDb
(
"databaseEventListener"
);
}
}
...
@@ -90,7 +92,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
...
@@ -90,7 +92,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
}
}
deleteDb
(
"databaseEventListener"
);
deleteDb
(
"databaseEventListener"
);
String
url
=
getURL
(
"databaseEventListener"
,
true
);
String
url
=
getURL
(
"databaseEventListener"
,
true
);
url
+=
";DATABASE_EVENT_LISTENER='"
+
Init
.
class
.
getName
()
+
"'"
;
url
+=
";DATABASE_EVENT_LISTENER='"
+
Init
.
class
.
getName
()
+
"'"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
url
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"select * from test"
);
stat
.
execute
(
"select * from test"
);
...
@@ -210,6 +212,24 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
...
@@ -210,6 +212,24 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
assertTrue
(
calledClosingDatabase
);
assertTrue
(
calledClosingDatabase
);
}
}
private
void
testCalledForStatement
()
throws
SQLException
{
Properties
p
=
new
Properties
();
p
.
setProperty
(
"user"
,
"sa"
);
p
.
setProperty
(
"password"
,
"sa"
);
calledStatementStart
=
false
;
calledStatementEnd
=
false
;
p
.
put
(
"DATABASE_EVENT_LISTENER"
,
getClass
().
getName
());
org
.
h2
.
Driver
.
load
();
String
url
=
"jdbc:h2:mem:databaseEventListener"
;
Connection
conn
=
org
.
h2
.
Driver
.
load
().
connect
(
url
,
p
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"select * from test"
);
conn
.
close
();
assertTrue
(
calledStatementStart
);
assertTrue
(
calledStatementEnd
);
}
public
void
closingDatabase
()
{
public
void
closingDatabase
()
{
calledClosingDatabase
=
true
;
calledClosingDatabase
=
true
;
}
}
...
@@ -235,6 +255,17 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
...
@@ -235,6 +255,17 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
calledCreateIndex
=
true
;
calledCreateIndex
=
true
;
}
}
}
}
if
(
state
==
STATE_STATEMENT_START
)
{
System
.
out
.
println
(
"name = "
+
name
);
if
(
name
.
equals
(
"select * from test"
))
{
calledStatementStart
=
true
;
}
}
if
(
state
==
STATE_STATEMENT_END
)
{
if
(
name
.
equals
(
"select * from test"
))
{
calledStatementEnd
=
true
;
}
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论