提交 d69f1d98 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved support for GAE for Java thanks to Vince Bonfanti.

上级 195c8b6e
...@@ -385,6 +385,11 @@ public class WebApp implements DatabaseEventListener { ...@@ -385,6 +385,11 @@ public class WebApp implements DatabaseEventListener {
return "helpTranslate.jsp"; return "helpTranslate.jsp";
} }
/**
* Stop the application and the server.
*
* @return the page to display
*/
protected String adminShutdown() { protected String adminShutdown() {
server.shutdown(); server.shutdown();
return "admin.jsp"; return "admin.jsp";
...@@ -813,15 +818,17 @@ public class WebApp implements DatabaseEventListener { ...@@ -813,15 +818,17 @@ public class WebApp implements DatabaseEventListener {
return getStackTrace(0, e, isH2); return getStackTrace(0, e, isH2);
} }
protected String login() { private String login() {
final String driver = attributes.getProperty("driver", ""); String driver = attributes.getProperty("driver", "");
final String url = attributes.getProperty("url", ""); String url = attributes.getProperty("url", "");
final String user = attributes.getProperty("user", ""); String user = attributes.getProperty("user", "");
final String password = attributes.getProperty("password", ""); String password = attributes.getProperty("password", "");
session.put("autoCommit", "checked"); session.put("autoCommit", "checked");
session.put("autoComplete", "1"); session.put("autoComplete", "1");
session.put("maxrows", "1000"); session.put("maxrows", "1000");
if (loginAsync(driver, url, user, password)) {
return "";
}
boolean isH2 = url.startsWith("jdbc:h2:"); boolean isH2 = url.startsWith("jdbc:h2:");
try { try {
Connection conn = server.getConnection(driver, url, user, password, this); Connection conn = server.getConnection(driver, url, user, password, this);
...@@ -837,6 +844,19 @@ public class WebApp implements DatabaseEventListener { ...@@ -837,6 +844,19 @@ public class WebApp implements DatabaseEventListener {
} }
} }
/**
* Login in a separate thread if possible.
*
* @param driver the driver class
* @param url the database URL
* @param user the user name
* @param password the password
* @return false if asynchronous login is not possible
*/
protected boolean loginAsync(String driver, String url, String user, String password) {
return false;
}
private String logout() { private String logout() {
try { try {
Connection conn = session.getConnection(); Connection conn = session.getConnection();
......
...@@ -48,11 +48,19 @@ class WebThread extends WebApp implements Runnable { ...@@ -48,11 +48,19 @@ class WebThread extends WebApp implements Runnable {
thread = new Thread(this, "H2 Console thread"); thread = new Thread(this, "H2 Console thread");
} }
public void start() { /**
* Start the thread.
*/
void start() {
thread.start(); thread.start();
} }
public void join(int millis) throws InterruptedException { /**
* Wait until the thread is stopped.
*
* @param millis the maximum number of milliseconds to wait
*/
void join(int millis) throws InterruptedException {
thread.join(millis); thread.join(millis);
} }
...@@ -277,33 +285,14 @@ class WebThread extends WebApp implements Runnable { ...@@ -277,33 +285,14 @@ class WebThread extends WebApp implements Runnable {
return super.adminShutdown(); return super.adminShutdown();
} }
protected String login() { protected boolean loginAsync(final String driver, final String url, final String user, final String password) {
final String driver = attributes.getProperty("driver", ""); if (socket == null
final String url = attributes.getProperty("url", ""); || !url.startsWith("jdbc:h2:")
final String user = attributes.getProperty("user", ""); || url.startsWith("jdbc:h2:tcp:")
final String password = attributes.getProperty("password", ""); || url.startsWith("jdbc:h2:ssl:")
session.put("autoCommit", "checked"); || url.startsWith("jdbc:h2:mem:")) {
session.put("autoComplete", "1"); // async login only possible for H2 embedded
session.put("maxrows", "1000"); return false;
boolean thread = false;
if (socket != null && url.startsWith("jdbc:h2:") && !url.startsWith("jdbc:h2:tcp:")
&& !url.startsWith("jdbc:h2:ssl:") && !url.startsWith("jdbc:h2:mem:")) {
thread = true;
}
if (!thread) {
boolean isH2 = url.startsWith("jdbc:h2:");
try {
Connection conn = server.getConnection(driver, url, user, password, this);
session.setConnection(conn);
session.put("url", url);
session.put("user", user);
session.remove("error");
settingSave();
return "frame.jsp";
} catch (Exception e) {
session.put("error", getLoginError(e, isH2));
return "login.jsp";
}
} }
/** /**
...@@ -422,7 +411,7 @@ class WebThread extends WebApp implements Runnable { ...@@ -422,7 +411,7 @@ class WebThread extends WebApp implements Runnable {
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
return ""; return true;
} }
private boolean allow() { private boolean allow() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论