提交 2b22f40b authored 作者: Steve McLeod's avatar Steve McLeod

DatabaseEventListener now calls setProgress periodically while a query statement is running

上级 44649f78
...@@ -29,6 +29,7 @@ Change Log ...@@ -29,6 +29,7 @@ Change Log
</li><li>Then reading from a resource using the prefix "classpath:", the ContextClassLoader </li><li>Then reading from a resource using the prefix "classpath:", the ContextClassLoader
is now used if the resource can't be read otherwise. is now used if the resource can't be read otherwise.
</li><li>DatabaseEventListener now calls setProgress whenever a statement starts and ends. </li><li>DatabaseEventListener now calls setProgress whenever a statement starts and ends.
</li><li>DatabaseEventListener now calls setProgress periodically while a statement is running.
</li><li>The table INFORMATION_SCHEMA.FUNCTION_ALIASES now includes a column TYPE_NAME. </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!
......
...@@ -54,6 +54,11 @@ public interface DatabaseEventListener extends EventListener { ...@@ -54,6 +54,11 @@ public interface DatabaseEventListener extends EventListener {
*/ */
int STATE_STATEMENT_END = 6; int STATE_STATEMENT_END = 6;
/**
* This state is used for periodic notification during long-running queries
*/
int STATE_STATEMENT_PROGRESS = 7;
/** /**
* 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
......
...@@ -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.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -331,6 +332,7 @@ public abstract class Prepared { ...@@ -331,6 +332,7 @@ public abstract class Prepared {
checkCanceled(); checkCanceled();
} }
this.currentRowNumber = rowNumber; this.currentRowNumber = rowNumber;
setProgress();
} }
/** /**
...@@ -342,6 +344,15 @@ public abstract class Prepared { ...@@ -342,6 +344,15 @@ public abstract class Prepared {
return currentRowNumber; return currentRowNumber;
} }
/**
* Notifies query progress via the DatabaseEventListener
*/
private void setProgress() {
if ((currentRowNumber & 127) == 0) {
session.getDatabase().setProgress(DatabaseEventListener.STATE_STATEMENT_PROGRESS, sqlStatement, currentRowNumber, 0);
}
}
/** /**
* Convert the statement to a String. * Convert the statement to a String.
* *
......
...@@ -973,7 +973,7 @@ HASH(algorithmString, dataBytes, iterationInt) ...@@ -973,7 +973,7 @@ HASH(algorithmString, dataBytes, iterationInt)
"," ","
Calculate the hash value using an algorithm, and repeat this process for a number of iterations." Calculate the hash value using an algorithm, and repeat this process for a number of iterations."
"Functions (Numeric)","TRUNCATE"," "Functions (Numeric)","TRUNCATE","
TRUNCATE(numeric, digitsInt) { TRUNC | TRUNCATE } (numeric, digitsInt)
"," ","
Truncates to a number of digits (to the next value closer to 0)." Truncates to a number of digits (to the next value closer to 0)."
"Functions (Numeric)","COMPRESS"," "Functions (Numeric)","COMPRESS","
......
...@@ -69,7 +69,7 @@ public class TestListener extends TestBase implements DatabaseEventListener { ...@@ -69,7 +69,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
if (state == lastState && time < last + 1000) { if (state == lastState && time < last + 1000) {
return; return;
} }
if (state == STATE_STATEMENT_START || state == STATE_STATEMENT_END) { if (state == STATE_STATEMENT_START || state == STATE_STATEMENT_END || state == STATE_STATEMENT_PROGRESS) {
return; return;
} }
if (name.length() > 30) { if (name.length() > 30) {
......
...@@ -23,7 +23,7 @@ import org.h2.test.TestBase; ...@@ -23,7 +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; private static boolean calledStatementStart, calledStatementEnd, calledStatementProgress;
/** /**
* Run just this test. * Run just this test.
...@@ -218,6 +218,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -218,6 +218,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
p.setProperty("password", "sa"); p.setProperty("password", "sa");
calledStatementStart = false; calledStatementStart = false;
calledStatementEnd = false; calledStatementEnd = false;
calledStatementProgress = false;
p.put("DATABASE_EVENT_LISTENER", getClass().getName()); p.put("DATABASE_EVENT_LISTENER", getClass().getName());
org.h2.Driver.load(); org.h2.Driver.load();
String url = "jdbc:h2:mem:databaseEventListener"; String url = "jdbc:h2:mem:databaseEventListener";
...@@ -228,6 +229,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -228,6 +229,7 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
conn.close(); conn.close();
assertTrue(calledStatementStart); assertTrue(calledStatementStart);
assertTrue(calledStatementEnd); assertTrue(calledStatementEnd);
assertTrue(calledStatementProgress);
} }
public void closingDatabase() { public void closingDatabase() {
...@@ -265,6 +267,11 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent ...@@ -265,6 +267,11 @@ public class TestDatabaseEventListener extends TestBase implements DatabaseEvent
calledStatementEnd = true; calledStatementEnd = true;
} }
} }
if (state == STATE_STATEMENT_PROGRESS) {
if (name.equals("select * from test")) {
calledStatementProgress = true;
}
}
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论