提交 fc7c05cd authored 作者: Thomas Mueller's avatar Thomas Mueller

DatabaseEventListener now calls setProgress whenever a statement starts and ends.

上级 a01a0a1e
......@@ -8,8 +8,6 @@ package org.h2.command;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.api.DatabaseEventListener;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database;
......@@ -125,12 +123,8 @@ 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);
void setProgress(int state) {
session.getDatabase().setProgress(state, sql, 0, 0);
}
/**
......@@ -160,7 +154,7 @@ public abstract class Command implements CommandInterface {
}
}
}
if (trace.isInfoEnabled()) {
if (trace.isInfoEnabled() && startTime > 0) {
long time = System.currentTimeMillis() - startTime;
if (time > Constants.SLOW_QUERY_LIMIT_MS) {
trace.info("slow query: {0} ms", time);
......
......@@ -7,6 +7,7 @@
package org.h2.command;
import java.util.ArrayList;
import org.h2.api.DatabaseEventListener;
import org.h2.expression.Parameter;
import org.h2.expression.ParameterInterface;
import org.h2.result.ResultInterface;
......@@ -67,24 +68,24 @@ class CommandContainer extends Command {
public int update() {
recompileIfRequired();
publishStart();
setProgress(DatabaseEventListener.STATE_STATEMENT_START);
start();
session.setLastIdentity(ValueNull.INSTANCE);
prepared.checkParameters();
int updateCount = prepared.update();
prepared.trace(startTime, updateCount);
publishEnd();
setProgress(DatabaseEventListener.STATE_STATEMENT_END);
return updateCount;
}
public ResultInterface query(int maxrows) {
recompileIfRequired();
publishStart();
setProgress(DatabaseEventListener.STATE_STATEMENT_START);
start();
prepared.checkParameters();
ResultInterface result = prepared.query(maxrows);
prepared.trace(startTime, result.getRowCount());
publishEnd();
setProgress(DatabaseEventListener.STATE_STATEMENT_END);
return result;
}
......
......@@ -1809,7 +1809,6 @@ public class Database implements DataHandler {
* @param x the current position
* @param max the highest value
*/
public void setProgress(int state, String name, int x, int max) {
if (eventListener != null) {
try {
......@@ -2406,9 +2405,4 @@ public class Database implements DataHandler {
throw DbException.throwInternalError();
}
public void publishEvent(int state, String sql) {
if (eventListener!= null) {
eventListener.setProgress(state, sql, 0, -1);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论