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