提交 42e01bf9 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 a326829f
......@@ -958,9 +958,6 @@ public class Function extends Expression implements FunctionCall {
int nanos = d.getNanos() % 1000000;
calendar.setTime(d);
calendar.add(field, count);
// TODO gcj: required so that the millis are calculated?
calendar.get(Calendar.YEAR);
calendar.get(Calendar.HOUR_OF_DAY);
long t = calendar.getTime().getTime();
Timestamp ts = new Timestamp(t);
ts.setNanos(ts.getNanos() + nanos);
......
......@@ -133,8 +133,6 @@ public class SecureSocketFactory {
// See also: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4887561 (1.4.2 cannot read keystore written with 1.4.1)
// --- generated code start ---
// GCJ hack
//KeyStore store = KeyStore.getInstance("JKS");
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
store.load(null, password.toCharArray());
......
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.server.web;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import org.h2.engine.Constants;
import org.h2.message.TraceSystem;
import org.h2.util.FileUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils;
public class AppServer {
private static final String[] GENERIC = new String[] {
"Generic Firebird Server|org.firebirdsql.jdbc.FBDriver|jdbc:firebirdsql:localhost:c:/temp/firebird/test|sysdba",
"Generic OneDollarDB|in.co.daffodil.db.jdbc.DaffodilDBDriver|jdbc:daffodilDB_embedded:school;path=C:/temp;create=true|sa",
"Generic DB2|COM.ibm.db2.jdbc.net.DB2Driver|jdbc:db2://<host>/<db>|" ,
"Generic Oracle|oracle.jdbc.driver.OracleDriver|jdbc:oracle:thin:@<host>:1521:<instance>|scott" ,
"Generic PostgreSQL|org.postgresql.Driver|jdbc:postgresql:<db>|" ,
"Generic MS SQL Server|com.microsoft.jdbc.sqlserver.SQLServerDriver|jdbc:Microsoft:sqlserver://localhost:1433;DatabaseName=sqlexpress|sa",
"Generic MS SQL Server 2005|com.microsoft.sqlserver.jdbc.SQLServerDriver|jdbc:sqlserver://localhost;DatabaseName=test|sa",
"Generic MySQL|com.mysql.jdbc.Driver|jdbc:mysql://<host>:<port>/<db>|" ,
"Generic Derby (Embedded)|org.apache.derby.jdbc.EmbeddedDriver|jdbc:derby:test;create=true|sa",
"Generic Derby (Server)|org.apache.derby.jdbc.ClientDriver|jdbc:derby://localhost:1527/test;create=true|sa",
"Generic HSQLDB|org.hsqldb.jdbcDriver|jdbc:hsqldb:test;hsqldb.default_table_type=cached|sa" ,
"Generic H2|org.h2.Driver|jdbc:h2:test|sa",
};
// private URLClassLoader urlClassLoader;
private String driverList;
private static int ticker;
private int port;
private boolean allowOthers;
private boolean ssl;
private HashMap connInfoMap = new HashMap();
AppServer(String[] args) {
Properties prop = loadProperties();
driverList = prop.getProperty("drivers");
port = FileUtils.getIntProperty(prop, "webPort", Constants.DEFAULT_HTTP_PORT);
ssl = FileUtils.getBooleanProperty(prop, "webSSL", Constants.DEFAULT_HTTP_SSL);
allowOthers = FileUtils.getBooleanProperty(prop, "webAllowOthers", Constants.DEFAULT_HTTP_ALLOW_OTHERS);
for(int i=0; args != null && i<args.length; i++) {
if("-webPort".equals(args[i])) {
port = MathUtils.decodeInt(args[++i]);
} else if("-webSSL".equals(args[i])) {
ssl = Boolean.valueOf(args[++i]).booleanValue();
} else if("-webAllowOthers".equals(args[i])) {
allowOthers = Boolean.valueOf(args[++i]).booleanValue();
// } else if("-baseDir".equals(args[i])) {
// String baseDir = args[++i];
}
}
// TODO gcj: don't load drivers in case of GCJ
// if(false) {
// if(driverList != null) {
// try {
// String[] drivers = StringUtils.arraySplit(driverList, ',', false);
// URL[] urls = new URL[drivers.length];
// for(int i=0; i<drivers.length; i++) {
// urls[i] = new URL(drivers[i]);
// }
// urlClassLoader = URLClassLoader.newInstance(urls);
// } catch (MalformedURLException e) {
// TraceSystem.traceThrowable(e);
// }
// }
// }
}
void setAllowOthers(boolean b) {
allowOthers = b;
}
void setSSL(boolean b) {
ssl = b;
}
void setPort(int port) {
this.port = port;
}
boolean getAllowOthers() {
return allowOthers;
}
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<AppServer.GENERIC.length; i++) {
ConnectionInfo info = new ConnectionInfo(AppServer.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 Properties();
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());
prop.store(out, Constants.SERVER_PROPERTIES_TITLE);
out.close();
} catch(Exception e) {
TraceSystem.traceThrowable(e);
}
}
// TODO GCJ: if this method is synchronized, then the .exe file fails (probably does not unlock the object)
// and cannot go in here after a class was not found
Connection getConnection(String driver, String url, String user, String password) throws Exception {
driver = driver.trim();
url = url.trim();
user = user.trim();
password = password.trim();
org.h2.Driver.load();
// try {
// Driver dr = (Driver) urlClassLoader.loadClass(driver).newInstance();
// Properties p = new Properties();
// p.setProperty("user", user);
// p.setProperty("password", password);
// return dr.connect(url, p);
// } catch(ClassNotFoundException e2) {
// throw e2;
// }
return JdbcUtils.getConnection(driver, url, user, password);
}
}
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.server.web;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Locale;
public class WebServerSession {
long lastAccess;
HashMap map = new HashMap();
Locale locale;
WebServer server;
WebServerSession(WebServer server) {
this.server = server;
}
public void put(String key, Object value) {
map.put(key, value);
}
public Object get(String key) {
if("sessions".equals(key)) {
return server.getSessions();
}
return map.get(key);
}
public void remove(String key) {
map.remove(key);
}
public HashMap getInfo() {
HashMap m = new HashMap();
m.putAll(map);
m.put("lastAccess", new Timestamp(lastAccess).toString());
return m;
}
}
......@@ -9,13 +9,20 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import org.h2.bnf.Bnf;
import org.h2.message.TraceSystem;
public class AppSession extends WebServerSession {
public class WebSession {
long lastAccess;
HashMap map = new HashMap();
Locale locale;
WebServer server;
private static final int MAX_HISTORY = 1000;
private ArrayList commandHistory = new ArrayList();
......@@ -31,8 +38,23 @@ public class AppSession extends WebServerSession {
Statement executingStatement;
ResultSet result;
AppSession(WebServer server) {
super(server);
WebSession(WebServer server) {
this.server = server;
}
public void put(String key, Object value) {
map.put(key, value);
}
public Object get(String key) {
if("sessions".equals(key)) {
return server.getSessions();
}
return map.get(key);
}
public void remove(String key) {
map.remove(key);
}
public Bnf getBnf() {
......@@ -98,8 +120,16 @@ public class AppSession extends WebServerSession {
return commandHistory;
}
public HashMap getMainInfo() {
int todoRefactorMergeWithGetInfo;
HashMap m = new HashMap();
m.putAll(map);
m.put("lastAccess", new Timestamp(lastAccess).toString());
return m;
}
public HashMap getInfo() {
HashMap m = super.getInfo();
HashMap m = getMainInfo();
try {
m.put("url", conn == null ? "not connected" : conn.getMetaData().getURL());
m.put("user", conn == null ? "-" : conn.getMetaData().getUserName());
......
......@@ -33,8 +33,6 @@ public class DateTimeUtils {
public static Time cloneAndNormalizeTime(Time value) {
Calendar cal = Calendar.getInstance();
cal.setTime(value);
// TODO gcj: required so that the millis are calculated?
cal.get(Calendar.HOUR_OF_DAY);
cal.set(1970, 0, 1);
return new Time(cal.getTime().getTime());
}
......@@ -42,8 +40,6 @@ public class DateTimeUtils {
public static Date cloneAndNormalizeDate(Date value) {
Calendar cal = Calendar.getInstance();
cal.setTime(value);
// TODO gcj: required so that the millis are calculated?
cal.get(Calendar.YEAR);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
......
......@@ -33,8 +33,6 @@ public class FileUtils {
// TODO detection of 'case in sensitive filesystem' could maybe implemented using some other means
private static final boolean isCaseInsensitiveFileSystem = (File.separatorChar == '\\');
// TODO gcj: use our own UTF-8 encoder
public static RandomAccessFile openRandomAccessFile(String fileName, String mode) throws IOException {
fileName = translateFileName(fileName);
try {
......@@ -222,10 +220,7 @@ public class FileUtils {
wait(i);
}
}
// TODO GCJ: it seems gcj throws 'CreateFile failed' if the file already exists?!
return false;
// TODO is this message used elsewhere?
// throw Message.getSQLException(Message.FILE_CREATION_FAILED_1, fileName);
}
public static void delete(String fileName) throws SQLException {
......
......@@ -23,21 +23,6 @@ import org.h2.message.Message;
public class StringUtils {
// TODO hack for gcj
//#GCJHACK private static final Class[] gcjClasses = {
//#GCJHACK gnu.gcj.convert.Input_ASCII.class,
//#GCJHACK gnu.gcj.convert.Input_UTF8.class,
//#GCJHACK gnu.gcj.convert.Input_8859_1.class,
//#GCJHACK gnu.gcj.convert.Output_ASCII.class,
//#GCJHACK gnu.gcj.convert.Output_UTF8.class,
//#GCJHACK gnu.gcj.convert.UnicodeToBytes.class,
//#GCJHACK gnu.gcj.convert.BytesToUnicode.class,
//#GCJHACK gnu.java.locale.Calendar.class,
//#GCJHACK gnu.java.locale.LocaleInformation.class,
//#GCJHACK gnu.java.locale.LocaleInformation_de.class,
//#GCJHACK java.util.GregorianCalendar.class,
//#GCJHACK };
public static boolean equals(String a, String b) {
if(a==null) {
return b==null;
......
......@@ -558,7 +558,7 @@ public class DataType {
} else if(Timestamp.class.isAssignableFrom(x)) {
return Value.TIMESTAMP;
} else if(java.util.Date.class.isAssignableFrom(x)) {
return Value.DATE;
return Value.TIMESTAMP;
} else if(java.io.Reader.class.isAssignableFrom(x)) {
return Value.CLOB;
} else if(java.sql.Clob.class.isAssignableFrom(x)) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论