提交 7146e176 authored 作者: Thomas Mueller's avatar Thomas Mueller

The WebServlet did not close the database when undeploying the web application.

上级 a8693704
......@@ -15,7 +15,6 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
......@@ -332,12 +331,14 @@ public class WebServer implements Service {
}
public void stop() {
try {
serverSocket.close();
} catch (IOException e) {
// TODO log exception
if (serverSocket != null) {
try {
serverSocket.close();
} catch (IOException e) {
traceError(e);
}
serverSocket = null;
}
serverSocket = null;
if (listenerThread != null) {
try {
listenerThread.join(1000);
......@@ -349,14 +350,7 @@ public class WebServer implements Service {
ArrayList list = new ArrayList(sessions.values());
for (int i = 0; i < list.size(); i++) {
WebSession session = (WebSession) list.get(i);
Statement stat = session.executingStatement;
if (stat != null) {
try {
stat.cancel();
} catch (Exception e) {
// ignore
}
}
session.close();
}
list = new ArrayList(running);
for (int i = 0; i < list.size(); i++) {
......@@ -365,8 +359,7 @@ public class WebServer implements Service {
c.stopNow();
c.join(100);
} catch (Exception e) {
// TODO log exception
e.printStackTrace();
traceError(e);
}
}
}
......@@ -387,8 +380,10 @@ public class WebServer implements Service {
*
* @param e the exception
*/
void traceError(Exception e) {
e.printStackTrace();
void traceError(Throwable e) {
if (trace) {
e.printStackTrace();
}
}
/**
......@@ -676,7 +671,7 @@ public class WebServer implements Service {
* The translate thread reads and writes the file translation.properties
* once a second.
*/
private static class TranslateThread extends Thread {
private class TranslateThread extends Thread {
private final File file = new File("translation.properties");
private final Map translation;
......@@ -714,8 +709,7 @@ public class WebServer implements Service {
}
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
// ignore
traceError(e);
}
}
}
......
......@@ -53,6 +53,10 @@ public class WebServlet extends HttpServlet {
server.init(args);
}
public void destroy() {
server.stop();
}
private boolean allow(HttpServletRequest req) {
if (server.getAllowOthers()) {
return true;
......
......@@ -125,29 +125,17 @@ class WebSession {
tableRule = new DbContextRule(contents, DbContextRule.TABLE);
schemaRule = new DbContextRule(contents, DbContextRule.SCHEMA);
columnAliasRule = new DbContextRule(contents, DbContextRule.COLUMN_ALIAS);
// bnf.updateTopic("newTableName", new String[]{"TEST"});
// String[] schemas;
// if(contents.isMySQL) {
// schemas = new String[0];
// } else {
// schemas = new String[contents.schemas.length];
// for(int i=0; i<contents.schemas.length; i++) {
// schemas[i] = contents.schemas[i].quotedName + ".";
// }
// }
// bnf.updateTopic("schemaName", schemas);
newBnf.updateTopic("columnName", columnRule);
newBnf.updateTopic("newTableAlias", newAliasRule);
newBnf.updateTopic("tableAlias", aliasRule);
newBnf.updateTopic("columnAlias", columnAliasRule);
newBnf.updateTopic("tableName", tableRule);
newBnf.updateTopic("schemaName", schemaRule);
// bnf.updateTopic("name", new String[]{""});
newBnf.linkStatements();
bnf = newBnf;
} catch (Exception e) {
// ok we don't have the bnf
e.printStackTrace();
server.traceError(e);
}
}
......@@ -246,4 +234,22 @@ class WebSession {
return shutdownServerOnDisconnect;
}
void close() {
if (executingStatement != null) {
try {
executingStatement.cancel();
} catch (Exception e) {
// ignore
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
// ignore
}
}
}
}
......@@ -552,7 +552,7 @@ class WebThread extends Thread implements DatabaseEventListener {
}
session.put("autoCompleteList", result);
} catch (Throwable e) {
e.printStackTrace();
server.traceError(e);
}
return "autoCompleteList.jsp";
}
......@@ -974,7 +974,7 @@ class WebThread extends Thread implements DatabaseEventListener {
error = formatAsError(error);
return error;
} catch (OutOfMemoryError e2) {
e.printStackTrace();
server.traceError(e);
return e.toString();
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论