提交 8564ab61 authored 作者: Owner's avatar Owner

Merge branch 'Issue#576' of https://github.com/stumc/h2database into Issue#576

......@@ -172,6 +172,7 @@ public abstract class Command implements CommandInterface {
trace.info("slow query: {0} ms", timeMillis);
}
}
session.commandCleanup(this);
}
/**
......@@ -233,7 +234,6 @@ public abstract class Command implements CommandInterface {
} finally {
if (callStop) {
stop();
commandCleanup();
}
if (writing) {
database.afterWriting();
......@@ -293,7 +293,6 @@ public abstract class Command implements CommandInterface {
try {
if (callStop) {
stop();
commandCleanup();
}
} finally {
if (writing) {
......@@ -304,17 +303,6 @@ public abstract class Command implements CommandInterface {
}
}
private void commandCleanup() {
if (cleanupCallbacks!=null){
for(Runnable eachCleanup:cleanupCallbacks){
eachCleanup.run();
// clean up done - must restart query (and dependency construction) to reuse
canReuse = false;
}
cleanupCallbacks.clear();
}
}
private long filterConcurrentUpdate(DbException e, long start) {
int errorCode = e.getErrorCode();
if (errorCode != ErrorCode.CONCURRENT_UPDATE_1 &&
......@@ -391,4 +379,11 @@ public abstract class Command implements CommandInterface {
this.cleanupCallbacks = cleanupCallbacks;
}
public List<Runnable> getCleanupCallbacks() {
return cleanupCallbacks;
}
public void setCanReuse(boolean canReuse) {
this.canReuse = canReuse;
}
}
......@@ -4914,6 +4914,25 @@ public class Parser {
return command;
}
private class WithCleanup implements Runnable {
TableView view;
Session session;
public WithCleanup(TableView view, Session session){
this.view = view;
this.session = session;
}
@Override
public void run() {
// check if view was previously deleted as their name is set to null
if(view.getName()!=null) {
session.removeLocalTempTable(view);
}
}
}
private Prepared parseWith() {
List<TableView> viewsCreated = new ArrayList<TableView>();
readIf("RECURSIVE");
......@@ -4957,7 +4976,6 @@ public class Parser {
else {
throw DbException.get(ErrorCode.SYNTAX_ERROR_1,
WITH_STATEMENT_SUPPORTS_LIMITED_STATEMENTS);
}
List<Runnable> cleanupCallbacks = new ArrayList<Runnable>();
......@@ -4969,15 +4987,7 @@ public class Parser {
if(view==null){
continue;
}
cleanupCallbacks.add(new Runnable(){
@Override
public void run() {
// check if view was previously deleted as their name is set to null
if(view.getName()!=null) {
session.removeLocalTempTable(view);
}
}
});
cleanupCallbacks.add(new WithCleanup(view,session));
}
p.setCleanupCallbacks(cleanupCallbacks);
return p;
......
......@@ -1707,6 +1707,22 @@ public class Session extends SessionWithState {
tablesToAnalyze.add(table);
}
/**
* Clean up after the command was run in the session
*
* @param command the command to cleanup for
*/
public void commandCleanup(Command command) {
if (command.getCleanupCallbacks()!=null){
for(Runnable eachCleanup : command.getCleanupCallbacks()){
eachCleanup.run();
// clean up done - must restart query (and dependency construction) to reuse
command.setCanReuse(false);
}
command.getCleanupCallbacks().clear();
}
}
/**
* Represents a savepoint (a position in a transaction to where one can roll
* back to).
......
......@@ -69,7 +69,7 @@ Lists the schemas, tables, or the columns of a table."
"Commands (DML)","WITH","
WITH [ RECURSIVE ] { name [( columnName [,...] )]
AS ( select ) [,...] }
select
{ select | insert | update | merge | delete | createTable }
","
Can be used to create a recursive or non-recursive query (common table expression)."
"Commands (DDL)","ALTER INDEX RENAME","
......@@ -381,6 +381,12 @@ SET BINARY_COLLATION
","
Sets the collation used for comparing BINARY columns, the default is SIGNED
for version 1."
"Commands (Other)","SET BUILTIN_ALIAS_OVERRIDE","
SET BUILTIN_ALIAS_OVERRIDE
{ TRUE | FALSE } ] }
","
Allows the overriding of the builtin system date/time functions
for unit testing purposes."
"Commands (Other)","SET COLLATION","
SET [ DATABASE ] COLLATION
{ OFF | collationName [ STRENGTH { PRIMARY | SECONDARY | TERTIARY | IDENTICAL } ] }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论