📄 webserver.java
字号:
s.close();
return true;
} catch (Exception e) {
return false;
}
}
public void stop() {
try {
serverSocket.close();
} catch (IOException e) {
// TODO log exception
}
serverSocket = null;
if (listenerThread != null) {
try {
listenerThread.join(1000);
} catch (InterruptedException e) {
TraceSystem.traceThrowable(e);
}
}
// TODO server: using a boolean 'now' argument? a timeout?
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
}
}
}
list = new ArrayList(running);
for (int i = 0; i < list.size(); i++) {
WebThread c = (WebThread) list.get(i);
try {
c.stopNow();
c.join(100);
} catch (Exception e) {
// TODO log exception
e.printStackTrace();
}
}
}
void trace(String s) {
// System.out.println(s);
}
public void traceError(Exception e) {
e.printStackTrace();
}
public boolean supportsLanguage(String language) {
return languages.contains(language);
}
public void readTranslations(WebSession session, String language) {
Properties text = new Properties();
try {
trace("translation: "+language);
byte[] trans = getFile("_text_"+language+".properties");
trace(" "+new String(trans));
text.load(new ByteArrayInputStream(trans));
} catch (IOException e) {
TraceSystem.traceThrowable(e);
}
session.put("text", new HashMap(text));
}
public String[][] getLanguageArray() {
return LANGUAGES;
}
public ArrayList getSessions() {
ArrayList list = new ArrayList(sessions.values());
for (int i = 0; i < list.size(); i++) {
WebSession s = (WebSession) list.get(i);
list.set(i, s.getInfo());
}
return list;
}
public String getType() {
return "Web";
}
public String getName() {
return "H2 Console Server";
}
void setAllowOthers(boolean b) {
allowOthers = b;
}
public boolean getAllowOthers() {
return allowOthers;
}
void setSSL(boolean b) {
ssl = b;
}
void setPort(int port) {
this.port = port;
}
boolean getSSL() {
return ssl;
}
int getPort() {
return port;
}
ConnectionInfo getSetting(String name) {
return (ConnectionInfo) connInfoMap.get(name);
}
void updateSetting(ConnectionInfo info) {
connInfoMap.put(info.name, info);
info.lastAccess = ticker++;
}
void removeSetting(String name) {
connInfoMap.remove(name);
}
private String getPropertiesFileName() {
// store the properties in the user directory
return FileUtils.getFileInUserHome(Constants.SERVER_PROPERTIES_FILE);
}
Properties loadProperties() {
String fileName = getPropertiesFileName();
try {
return FileUtils.loadProperties(fileName);
} catch (IOException e) {
// TODO log exception
return new Properties();
}
}
String[] getSettingNames() {
ArrayList list = getSettings();
String[] names = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
names[i] = ((ConnectionInfo) list.get(i)).name;
}
return names;
}
synchronized ArrayList getSettings() {
ArrayList settings = new ArrayList();
if (connInfoMap.size() == 0) {
Properties prop = loadProperties();
if (prop.size() == 0) {
for (int i = 0; i < GENERIC.length; i++) {
ConnectionInfo info = new ConnectionInfo(GENERIC[i]);
settings.add(info);
updateSetting(info);
}
} else {
for (int i = 0;; i++) {
String data = prop.getProperty(String.valueOf(i));
if (data == null) {
break;
}
ConnectionInfo info = new ConnectionInfo(data);
settings.add(info);
updateSetting(info);
}
}
} else {
settings.addAll(connInfoMap.values());
}
sortConnectionInfo(settings);
return settings;
}
void sortConnectionInfo(ArrayList list) {
for (int i = 1, j; i < list.size(); i++) {
ConnectionInfo t = (ConnectionInfo) list.get(i);
for (j = i - 1; j >= 0 && (((ConnectionInfo) list.get(j)).lastAccess < t.lastAccess); j--) {
list.set(j + 1, list.get(j));
}
list.set(j + 1, t);
}
}
synchronized void saveSettings() {
try {
Properties prop = new SortedProperties();
if (driverList != null) {
prop.setProperty("drivers", driverList);
}
prop.setProperty("webPort", String.valueOf(port));
prop.setProperty("webAllowOthers", String.valueOf(allowOthers));
prop.setProperty("webSSL", String.valueOf(ssl));
ArrayList settings = getSettings();
int len = settings.size();
for (int i = 0; i < len; i++) {
ConnectionInfo info = (ConnectionInfo) settings.get(i);
if (info != null) {
prop.setProperty(String.valueOf(len - i - 1), info.getString());
}
}
OutputStream out = FileUtils.openFileOutputStream(getPropertiesFileName(), false);
prop.store(out, Constants.SERVER_PROPERTIES_TITLE);
out.close();
} catch (Exception e) {
TraceSystem.traceThrowable(e);
}
}
Connection getConnection(String driver, String url, String user, String password, DatabaseEventListener listener) throws Exception {
driver = driver.trim();
url = url.trim();
org.h2.Driver.load();
Properties p = new Properties();
p.setProperty("user", user.trim());
p.setProperty("password", password.trim());
if (url.startsWith("jdbc:h2:")) {
if (ifExists) {
url += ";IFEXISTS=TRUE";
}
p.put("DATABASE_EVENT_LISTENER_OBJECT", listener);
// PostgreSQL would throw a NullPointerException
// if it is loaded before the H2 driver
// because it can't deal with non-String objects in the connection Properties
return org.h2.Driver.load().connect(url, p);
}
// try {
// Driver dr = (Driver) urlClassLoader.
// loadClass(driver).newInstance();
// return dr.connect(url, p);
// } catch(ClassNotFoundException e2) {
// throw e2;
// }
return JdbcUtils.getConnection(driver, url, p);
}
void shutdown() {
if (shutdownHandler != null) {
shutdownHandler.shutdown();
}
}
public void setShutdownHandler(ShutdownHandler shutdownHandler) {
this.shutdownHandler = shutdownHandler;
}
public boolean getAllowScript() {
return allowScript;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -