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