Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
42e01bf9
提交
42e01bf9
authored
6月 19, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
a326829f
显示空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
566 行增加
和
675 行删除
+566
-675
Function.java
h2/src/main/org/h2/expression/Function.java
+0
-3
SecureSocketFactory.java
h2/src/main/org/h2/security/SecureSocketFactory.java
+0
-2
AppServer.java
h2/src/main/org/h2/server/web/AppServer.java
+0
-223
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+217
-24
WebServerSession.java
h2/src/main/org/h2/server/web/WebServerSession.java
+0
-42
WebServerThread.java
h2/src/main/org/h2/server/web/WebServerThread.java
+0
-292
WebSession.java
h2/src/main/org/h2/server/web/WebSession.java
+35
-5
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+313
-59
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+0
-4
FileUtils.java
h2/src/main/org/h2/util/FileUtils.java
+0
-5
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+0
-15
DataType.java
h2/src/main/org/h2/value/DataType.java
+1
-1
没有找到文件。
h2/src/main/org/h2/expression/Function.java
浏览文件 @
42e01bf9
...
@@ -958,9 +958,6 @@ public class Function extends Expression implements FunctionCall {
...
@@ -958,9 +958,6 @@ public class Function extends Expression implements FunctionCall {
int
nanos
=
d
.
getNanos
()
%
1000000
;
int
nanos
=
d
.
getNanos
()
%
1000000
;
calendar
.
setTime
(
d
);
calendar
.
setTime
(
d
);
calendar
.
add
(
field
,
count
);
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
();
long
t
=
calendar
.
getTime
().
getTime
();
Timestamp
ts
=
new
Timestamp
(
t
);
Timestamp
ts
=
new
Timestamp
(
t
);
ts
.
setNanos
(
ts
.
getNanos
()
+
nanos
);
ts
.
setNanos
(
ts
.
getNanos
()
+
nanos
);
...
...
h2/src/main/org/h2/security/SecureSocketFactory.java
浏览文件 @
42e01bf9
...
@@ -133,8 +133,6 @@ public class SecureSocketFactory {
...
@@ -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)
// 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 ---
// --- generated code start ---
// GCJ hack
//KeyStore store = KeyStore.getInstance("JKS");
KeyStore
store
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
KeyStore
store
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
store
.
load
(
null
,
password
.
toCharArray
());
store
.
load
(
null
,
password
.
toCharArray
());
...
...
h2/src/main/org/h2/server/web/AppServer.java
deleted
100644 → 0
浏览文件 @
a326829f
/*
* 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
);
}
}
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
42e01bf9
...
@@ -6,8 +6,10 @@ package org.h2.server.web;
...
@@ -6,8 +6,10 @@ package org.h2.server.web;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.ServerSocket
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.net.Socket
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -18,9 +20,13 @@ import java.util.Locale;
...
@@ -18,9 +20,13 @@ import java.util.Locale;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
import
org.h2.engine.Constants
;
import
org.h2.message.TraceSystem
;
import
org.h2.message.TraceSystem
;
import
org.h2.server.Service
;
import
org.h2.server.Service
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.RandomUtils
;
import
org.h2.util.Resources
;
import
org.h2.util.Resources
;
...
@@ -43,6 +49,29 @@ public class WebServer implements Service {
...
@@ -43,6 +49,29 @@ public class WebServer implements Service {
{
"pl"
,
"Polski"
},
{
"pl"
,
"Polski"
},
};
};
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
();
/*
/*
String lang = new java.util.Locale("hu").getDisplayLanguage(new java.util.Locale("hu"));
String lang = new java.util.Locale("hu").getDisplayLanguage(new java.util.Locale("hu"));
java.util.Locale.CHINESE.getDisplayLanguage(
java.util.Locale.CHINESE.getDisplayLanguage(
...
@@ -56,11 +85,9 @@ public class WebServer implements Service {
...
@@ -56,11 +85,9 @@ public class WebServer implements Service {
private
HashMap
sessions
=
new
HashMap
();
private
HashMap
sessions
=
new
HashMap
();
private
HashSet
languages
=
new
HashSet
();
private
HashSet
languages
=
new
HashSet
();
private
String
startDateTime
;
private
String
startDateTime
;
private
AppServer
appServer
;
private
ServerSocket
serverSocket
;
private
ServerSocket
serverSocket
;
private
boolean
ssl
;
private
int
port
;
private
String
url
;
private
String
url
;
private
boolean
allowShutdown
;
byte
[]
getFile
(
String
file
)
throws
IOException
{
byte
[]
getFile
(
String
file
)
throws
IOException
{
trace
(
"getFile <"
+
file
+
">"
);
trace
(
"getFile <"
+
file
+
">"
);
...
@@ -83,17 +110,13 @@ public class WebServer implements Service {
...
@@ -83,17 +110,13 @@ public class WebServer implements Service {
return
ByteUtils
.
convertBytesToString
(
buff
);
return
ByteUtils
.
convertBytesToString
(
buff
);
}
}
AppServer
getAppServer
()
{
WebSession
getSession
(
String
sessionId
)
{
return
appServer
;
}
WebServerSession
getSession
(
String
sessionId
)
{
long
now
=
System
.
currentTimeMillis
();
long
now
=
System
.
currentTimeMillis
();
if
(
lastTimeoutCheck
+
SESSION_TIMEOUT
<
now
)
{
if
(
lastTimeoutCheck
+
SESSION_TIMEOUT
<
now
)
{
Object
[]
list
=
sessions
.
keySet
().
toArray
();
Object
[]
list
=
sessions
.
keySet
().
toArray
();
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
String
id
=
(
String
)
list
[
i
];
String
id
=
(
String
)
list
[
i
];
WebSe
rverSession
session
=
(
WebServer
Session
)
sessions
.
get
(
id
);
WebSe
ssion
session
=
(
Web
Session
)
sessions
.
get
(
id
);
Long
last
=
(
Long
)
session
.
get
(
"lastAccess"
);
Long
last
=
(
Long
)
session
.
get
(
"lastAccess"
);
if
(
last
!=
null
&&
last
.
longValue
()
+
SESSION_TIMEOUT
<
now
)
{
if
(
last
!=
null
&&
last
.
longValue
()
+
SESSION_TIMEOUT
<
now
)
{
trace
(
"timeout for "
+
id
);
trace
(
"timeout for "
+
id
);
...
@@ -102,19 +125,19 @@ public class WebServer implements Service {
...
@@ -102,19 +125,19 @@ public class WebServer implements Service {
}
}
lastTimeoutCheck
=
now
;
lastTimeoutCheck
=
now
;
}
}
WebSe
rverSession
session
=
(
WebServer
Session
)
sessions
.
get
(
sessionId
);
WebSe
ssion
session
=
(
Web
Session
)
sessions
.
get
(
sessionId
);
if
(
session
!=
null
)
{
if
(
session
!=
null
)
{
session
.
lastAccess
=
System
.
currentTimeMillis
();
session
.
lastAccess
=
System
.
currentTimeMillis
();
}
}
return
session
;
return
session
;
}
}
WebSe
rverSe
ssion
createNewSession
(
String
hostname
)
{
WebSession
createNewSession
(
String
hostname
)
{
String
newId
;
String
newId
;
do
{
do
{
newId
=
generateSessionId
();
newId
=
generateSessionId
();
}
while
(
sessions
.
get
(
newId
)
!=
null
);
}
while
(
sessions
.
get
(
newId
)
!=
null
);
WebSe
rverSession
session
=
new
App
Session
(
this
);
WebSe
ssion
session
=
new
Web
Session
(
this
);
session
.
put
(
"sessionId"
,
newId
);
session
.
put
(
"sessionId"
,
newId
);
//session.put("ip", socket.getInetAddress().getCanonicalHostName());
//session.put("ip", socket.getInetAddress().getCanonicalHostName());
session
.
put
(
"ip"
,
hostname
);
session
.
put
(
"ip"
,
hostname
);
...
@@ -131,7 +154,34 @@ public class WebServer implements Service {
...
@@ -131,7 +154,34 @@ public class WebServer implements Service {
public
void
init
(
String
[]
args
)
throws
Exception
{
public
void
init
(
String
[]
args
)
throws
Exception
{
// TODO web: support using a different properties file
// TODO web: support using a different properties file
appServer
=
new
AppServer
(
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];
}
}
// 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);
// }
// }
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"EEE, d MMM yyyy HH:mm:ss z"
,
new
Locale
(
"en"
,
""
));
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"EEE, d MMM yyyy HH:mm:ss z"
,
new
Locale
(
"en"
,
""
));
synchronized
(
format
)
{
synchronized
(
format
)
{
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
...
@@ -140,10 +190,7 @@ public class WebServer implements Service {
...
@@ -140,10 +190,7 @@ public class WebServer implements Service {
trace
(
startDateTime
);
trace
(
startDateTime
);
for
(
int
i
=
0
;
i
<
LANGUAGES
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
LANGUAGES
.
length
;
i
++)
{
languages
.
add
(
LANGUAGES
[
i
][
0
]);
languages
.
add
(
LANGUAGES
[
i
][
0
]);
}
}
url
=
(
ssl
?
"https"
:
"http"
)
+
"://localhost:"
+
port
;
port
=
appServer
.
getPort
();
ssl
=
appServer
.
getSSL
();
url
=
(
ssl
?
"https"
:
"http"
)
+
"://localhost:"
+
port
;
}
}
public
String
getURL
()
{
public
String
getURL
()
{
...
@@ -158,7 +205,7 @@ public class WebServer implements Service {
...
@@ -158,7 +205,7 @@ public class WebServer implements Service {
try
{
try
{
while
(
serverSocket
!=
null
)
{
while
(
serverSocket
!=
null
)
{
Socket
s
=
serverSocket
.
accept
();
Socket
s
=
serverSocket
.
accept
();
Web
ServerThread
c
=
new
AppThread
(
s
,
this
,
true
);
Web
Thread
c
=
new
WebThread
(
s
,
this
);
c
.
start
();
c
.
start
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -196,7 +243,7 @@ public class WebServer implements Service {
...
@@ -196,7 +243,7 @@ public class WebServer implements Service {
return
languages
.
contains
(
language
);
return
languages
.
contains
(
language
);
}
}
public
void
readTranslations
(
WebSe
rverSe
ssion
session
,
String
language
)
{
public
void
readTranslations
(
WebSession
session
,
String
language
)
{
Properties
text
=
new
Properties
();
Properties
text
=
new
Properties
();
try
{
try
{
trace
(
"translation: "
+
language
);
trace
(
"translation: "
+
language
);
...
@@ -216,18 +263,164 @@ public class WebServer implements Service {
...
@@ -216,18 +263,164 @@ public class WebServer implements Service {
public
ArrayList
getSessions
()
{
public
ArrayList
getSessions
()
{
ArrayList
list
=
new
ArrayList
(
sessions
.
values
());
ArrayList
list
=
new
ArrayList
(
sessions
.
values
());
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
WebSe
rverSession
s
=
(
WebServer
Session
)
list
.
get
(
i
);
WebSe
ssion
s
=
(
Web
Session
)
list
.
get
(
i
);
list
.
set
(
i
,
s
.
getInfo
());
list
.
set
(
i
,
s
.
getInfo
());
}
}
return
list
;
return
list
;
}
}
public
String
getType
()
{
return
"Web"
;
}
void
setAllowOthers
(
boolean
b
)
{
allowOthers
=
b
;
}
public
boolean
getAllowOthers
()
{
public
boolean
getAllowOthers
()
{
return
appServer
.
getAllowOthers
()
;
return
allowOthers
;
}
}
public
String
getType
()
{
void
setSSL
(
boolean
b
)
{
return
"Web"
;
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
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
);
}
}
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
);
}
public
void
setAllowShutdown
(
boolean
b
)
{
this
.
allowShutdown
=
b
;
}
boolean
getAllowShutdown
()
{
return
allowShutdown
;
}
}
}
}
h2/src/main/org/h2/server/web/WebServerSession.java
deleted
100644 → 0
浏览文件 @
a326829f
/*
* 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
;
}
}
h2/src/main/org/h2/server/web/WebServerThread.java
deleted
100644 → 0
浏览文件 @
a326829f
/*
* 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.BufferedOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.Socket
;
import
java.util.Locale
;
import
java.util.Properties
;
import
java.util.StringTokenizer
;
import
org.h2.message.TraceSystem
;
import
org.h2.util.StringUtils
;
abstract
class
WebServerThread
extends
Thread
{
protected
WebServer
server
;
protected
WebServerSession
session
;
protected
Properties
attributes
;
protected
Socket
socket
;
private
InputStream
input
;
private
String
ifModifiedSince
;
WebServerThread
(
Socket
socket
,
WebServer
server
)
{
this
.
server
=
server
;
this
.
socket
=
socket
;
}
void
setSession
(
WebServerSession
session
,
Properties
attributes
)
{
int
todoRefactor
;
this
.
session
=
session
;
this
.
attributes
=
attributes
;
}
abstract
String
process
(
String
file
);
protected
String
getComboBox
(
String
[]
elements
,
String
selected
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
elements
.
length
;
i
++)
{
String
value
=
elements
[
i
];
buff
.
append
(
"<option value=\""
);
buff
.
append
(
PageParser
.
escapeHtml
(
value
));
buff
.
append
(
"\""
);
if
(
value
.
equals
(
selected
))
{
buff
.
append
(
" selected"
);
}
buff
.
append
(
">"
);
buff
.
append
(
PageParser
.
escapeHtml
(
value
));
buff
.
append
(
"</option>"
);
}
return
buff
.
toString
();
}
protected
String
getComboBox
(
String
[][]
elements
,
String
selected
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
elements
.
length
;
i
++)
{
String
[]
n
=
elements
[
i
];
buff
.
append
(
"<option value=\""
);
buff
.
append
(
PageParser
.
escapeHtml
(
n
[
0
]));
buff
.
append
(
"\""
);
if
(
n
[
0
].
equals
(
selected
))
{
buff
.
append
(
" selected"
);
}
buff
.
append
(
">"
);
buff
.
append
(
PageParser
.
escapeHtml
(
n
[
1
]));
buff
.
append
(
"</option>"
);
}
return
buff
.
toString
();
}
public
void
run
()
{
try
{
input
=
socket
.
getInputStream
();
String
head
=
readHeaderLine
();
if
(
head
.
startsWith
(
"GET "
)
||
head
.
startsWith
(
"POST "
))
{
int
begin
=
head
.
indexOf
(
'/'
),
end
=
head
.
lastIndexOf
(
' '
);
String
file
=
head
.
substring
(
begin
+
1
,
end
).
trim
();
if
(
file
.
length
()
==
0
)
{
file
=
"index.do"
;
}
if
(!
allow
())
{
file
=
"notAllowed.jsp"
;
}
server
.
trace
(
head
+
" :"
+
file
);
attributes
=
new
Properties
();
int
paramIndex
=
file
.
indexOf
(
"?"
);
session
=
null
;
if
(
paramIndex
>=
0
)
{
String
attrib
=
file
.
substring
(
paramIndex
+
1
);
parseAttributes
(
attrib
);
String
sessionId
=
attributes
.
getProperty
(
"jsessionid"
);
file
=
file
.
substring
(
0
,
paramIndex
);
session
=
server
.
getSession
(
sessionId
);
}
// TODO web: support errors
String
mimeType
;
boolean
cache
;
int
index
=
file
.
lastIndexOf
(
'.'
);
String
suffix
;
if
(
index
>=
0
)
{
suffix
=
file
.
substring
(
index
+
1
);
}
else
{
suffix
=
""
;
}
if
(
suffix
.
equals
(
"ico"
))
{
mimeType
=
"image/x-icon"
;
cache
=
true
;
}
else
if
(
suffix
.
equals
(
"gif"
))
{
mimeType
=
"image/gif"
;
cache
=
true
;
}
else
if
(
suffix
.
equals
(
"css"
))
{
cache
=
true
;
mimeType
=
"text/css"
;
}
else
if
(
suffix
.
equals
(
"html"
)
||
suffix
.
equals
(
"do"
)
||
suffix
.
equals
(
"jsp"
))
{
cache
=
false
;
mimeType
=
"text/html"
;
if
(
session
==
null
)
{
String
hostname
=
socket
.
getInetAddress
().
getHostName
();
session
=
server
.
createNewSession
(
hostname
);
if
(!
file
.
equals
(
"notAllowed.jsp"
))
{
file
=
"index.do"
;
}
}
}
else
if
(
suffix
.
equals
(
"js"
))
{
cache
=
true
;
mimeType
=
"text/javascript"
;
}
else
{
cache
=
false
;
mimeType
=
"text/html"
;
file
=
"error.jsp"
;
server
.
trace
(
"unknown mime type, file "
+
file
);
}
server
.
trace
(
"mimeType="
+
mimeType
);
parseHeader
();
server
.
trace
(
file
);
if
(
file
.
endsWith
(
".do"
))
{
file
=
process
(
file
);
}
String
message
;
byte
[]
bytes
;
if
(
cache
&&
ifModifiedSince
!=
null
&&
ifModifiedSince
.
equals
(
server
.
getStartDateTime
()))
{
bytes
=
null
;
message
=
"HTTP/1.1 304 Not Modified\n"
;
}
else
{
bytes
=
server
.
getFile
(
file
);
if
(
bytes
==
null
)
{
message
=
"HTTP/1.0 404 Not Found\n"
;
bytes
=
StringUtils
.
utf8Encode
(
"File not found: "
+
file
);
}
else
{
if
(
session
!=
null
&&
file
.
endsWith
(
".jsp"
))
{
bytes
=
StringUtils
.
utf8Encode
(
fill
(
StringUtils
.
utf8Decode
(
bytes
)));
}
message
=
"HTTP/1.1 200 OK\n"
;
message
+=
"Content-Type: "
+
mimeType
+
"\n"
;
if
(!
cache
)
{
message
+=
"Cache-Control: no-cache\n"
;
}
else
{
message
+=
"Cache-Control: max-age=10\n"
;
message
+=
"Last-Modified: "
+
server
.
getStartDateTime
()+
"\n"
;
}
}
}
message
+=
"\n"
;
server
.
trace
(
message
);
DataOutputStream
output
;
output
=
new
DataOutputStream
(
new
BufferedOutputStream
(
socket
.
getOutputStream
()));
output
.
write
(
message
.
getBytes
());
if
(
bytes
!=
null
)
{
output
.
write
(
bytes
);
}
output
.
flush
();
output
.
close
();
output
.
close
();
socket
.
close
();
return
;
}
}
catch
(
Exception
e
)
{
TraceSystem
.
traceThrowable
(
e
);
}
}
abstract
boolean
allow
();
private
String
readHeaderLine
()
throws
IOException
{
StringBuffer
buff
=
new
StringBuffer
();
while
(
true
)
{
int
i
=
input
.
read
();
if
(
i
==
-
1
)
{
throw
new
IOException
(
"Unexpected EOF"
);
}
else
if
(
i
==
'\r'
&&
input
.
read
()==
'\n'
)
{
return
buff
.
length
()
>
0
?
buff
.
toString
()
:
null
;
}
else
{
buff
.
append
((
char
)
i
);
}
}
}
private
void
parseAttributes
(
String
s
)
throws
Exception
{
server
.
trace
(
"data="
+
s
);
while
(
s
!=
null
)
{
int
idx
=
s
.
indexOf
(
'='
);
if
(
idx
>=
0
)
{
String
property
=
s
.
substring
(
0
,
idx
);
s
=
s
.
substring
(
idx
+
1
);
idx
=
s
.
indexOf
(
'&'
);
String
value
;
if
(
idx
>=
0
)
{
value
=
s
.
substring
(
0
,
idx
);
s
=
s
.
substring
(
idx
+
1
);
}
else
{
value
=
s
;
}
// TODO compatibility problem with JDK 1.3
//String attr = URLDecoder.decode(value, "UTF-8");
// String attr = URLDecoder.decode(value);
String
attr
=
StringUtils
.
urlDecode
(
value
);
attributes
.
put
(
property
,
attr
);
}
else
{
break
;
}
}
server
.
trace
(
attributes
.
toString
());
}
private
void
parseHeader
()
throws
Exception
{
server
.
trace
(
"parseHeader"
);
int
len
=
0
;
ifModifiedSince
=
null
;
while
(
true
)
{
String
line
=
readHeaderLine
();
if
(
line
==
null
)
{
break
;
}
server
.
trace
(
" "
+
line
);
String
lower
=
StringUtils
.
toLowerEnglish
(
line
);
if
(
lower
.
startsWith
(
"if-modified-since"
))
{
ifModifiedSince
=
line
.
substring
(
line
.
indexOf
(
':'
)+
1
).
trim
();
}
else
if
(
lower
.
startsWith
(
"content-length"
))
{
len
=
Integer
.
parseInt
(
line
.
substring
(
line
.
indexOf
(
':'
)+
1
).
trim
());
server
.
trace
(
"len="
+
len
);
}
else
if
(
lower
.
startsWith
(
"accept-language"
))
{
if
(
session
!=
null
)
{
Locale
locale
=
session
.
locale
;
if
(
locale
==
null
)
{
String
languages
=
line
.
substring
(
line
.
indexOf
(
':'
)+
1
).
trim
();
StringTokenizer
tokenizer
=
new
StringTokenizer
(
languages
,
",;"
);
while
(
tokenizer
.
hasMoreTokens
())
{
String
token
=
tokenizer
.
nextToken
();
if
(!
token
.
startsWith
(
"q="
))
{
if
(
server
.
supportsLanguage
(
token
))
{
int
dash
=
token
.
indexOf
(
'-'
);
if
(
dash
>=
0
)
{
String
language
=
token
.
substring
(
0
,
dash
);
String
country
=
token
.
substring
(
dash
+
1
);
locale
=
new
Locale
(
language
,
country
);
}
else
{
locale
=
new
Locale
(
token
,
""
);
}
session
.
locale
=
locale
;
String
language
=
locale
.
getLanguage
();
session
.
put
(
"language"
,
language
);
server
.
readTranslations
(
session
,
language
);
break
;
}
}
}
}
}
}
else
if
(
line
.
trim
().
length
()==
0
)
{
break
;
}
}
if
(
session
!=
null
&&
len
>
0
)
{
byte
[]
bytes
=
new
byte
[
len
];
for
(
int
pos
=
0
;
pos
<
len
;)
{
pos
+=
input
.
read
(
bytes
,
pos
,
len
-
pos
);
}
String
s
=
new
String
(
bytes
);
parseAttributes
(
s
);
}
}
private
String
fill
(
String
page
)
{
return
PageParser
.
parse
(
server
,
page
,
session
.
map
);
}
}
h2/src/main/org/h2/server/web/
App
Session.java
→
h2/src/main/org/h2/server/web/
Web
Session.java
浏览文件 @
42e01bf9
...
@@ -9,13 +9,20 @@ import java.sql.DatabaseMetaData;
...
@@ -9,13 +9,20 @@ import java.sql.DatabaseMetaData;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
org.h2.bnf.Bnf
;
import
org.h2.bnf.Bnf
;
import
org.h2.message.TraceSystem
;
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
static
final
int
MAX_HISTORY
=
1000
;
private
ArrayList
commandHistory
=
new
ArrayList
();
private
ArrayList
commandHistory
=
new
ArrayList
();
...
@@ -31,8 +38,23 @@ public class AppSession extends WebServerSession {
...
@@ -31,8 +38,23 @@ public class AppSession extends WebServerSession {
Statement
executingStatement
;
Statement
executingStatement
;
ResultSet
result
;
ResultSet
result
;
AppSession
(
WebServer
server
)
{
WebSession
(
WebServer
server
)
{
super
(
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
()
{
public
Bnf
getBnf
()
{
...
@@ -98,8 +120,16 @@ public class AppSession extends WebServerSession {
...
@@ -98,8 +120,16 @@ public class AppSession extends WebServerSession {
return
commandHistory
;
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
()
{
public
HashMap
getInfo
()
{
HashMap
m
=
super
.
get
Info
();
HashMap
m
=
getMain
Info
();
try
{
try
{
m
.
put
(
"url"
,
conn
==
null
?
"not connected"
:
conn
.
getMetaData
().
getURL
());
m
.
put
(
"url"
,
conn
==
null
?
"not connected"
:
conn
.
getMetaData
().
getURL
());
m
.
put
(
"user"
,
conn
==
null
?
"-"
:
conn
.
getMetaData
().
getUserName
());
m
.
put
(
"user"
,
conn
==
null
?
"-"
:
conn
.
getMetaData
().
getUserName
());
...
...
h2/src/main/org/h2/server/web/
App
Thread.java
→
h2/src/main/org/h2/server/web/
Web
Thread.java
浏览文件 @
42e01bf9
...
@@ -4,6 +4,10 @@
...
@@ -4,6 +4,10 @@
*/
*/
package
org
.
h2
.
server
.
web
;
package
org
.
h2
.
server
.
web
;
import
java.io.BufferedOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.io.StringReader
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
...
@@ -22,10 +26,13 @@ import java.util.HashMap;
...
@@ -22,10 +26,13 @@ import java.util.HashMap;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.StringTokenizer
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
org.h2.bnf.Bnf
;
import
org.h2.bnf.Bnf
;
import
org.h2.message.TraceSystem
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
...
@@ -35,24 +42,276 @@ import org.h2.util.ObjectArray;
...
@@ -35,24 +42,276 @@ import org.h2.util.ObjectArray;
import
org.h2.util.ScriptReader
;
import
org.h2.util.ScriptReader
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
/**
class
WebThread
extends
Thread
{
* @author Thomas
protected
WebServer
server
;
*/
protected
WebSession
session
;
protected
Properties
attributes
;
protected
Socket
socket
;
public
class
AppThread
extends
WebServerThread
{
private
InputStream
input
;
private
String
ifModifiedSince
;
// TODO web: support online data editing like http://numsum.com/
// TODO web: support online data editing like http://numsum.com/
private
boolean
allowShutdown
;
WebThread
(
Socket
socket
,
WebServer
server
)
{
this
.
server
=
server
;
AppThread
(
Socket
socket
,
WebServer
server
,
boolean
allowShutdown
)
{
this
.
socket
=
socket
;
super
(
socket
,
server
);
setName
(
"H2 Console thread"
);
setName
(
"H2 Console thread"
);
this
.
allowShutdown
=
allowShutdown
;
}
}
AppSession
getAppSession
()
{
void
setSession
(
WebSession
session
,
Properties
attributes
)
{
return
(
AppSession
)
session
;
int
todoRefactor
;
this
.
session
=
session
;
this
.
attributes
=
attributes
;
}
protected
String
getComboBox
(
String
[]
elements
,
String
selected
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
elements
.
length
;
i
++)
{
String
value
=
elements
[
i
];
buff
.
append
(
"<option value=\""
);
buff
.
append
(
PageParser
.
escapeHtml
(
value
));
buff
.
append
(
"\""
);
if
(
value
.
equals
(
selected
))
{
buff
.
append
(
" selected"
);
}
buff
.
append
(
">"
);
buff
.
append
(
PageParser
.
escapeHtml
(
value
));
buff
.
append
(
"</option>"
);
}
return
buff
.
toString
();
}
protected
String
getComboBox
(
String
[][]
elements
,
String
selected
)
{
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
elements
.
length
;
i
++)
{
String
[]
n
=
elements
[
i
];
buff
.
append
(
"<option value=\""
);
buff
.
append
(
PageParser
.
escapeHtml
(
n
[
0
]));
buff
.
append
(
"\""
);
if
(
n
[
0
].
equals
(
selected
))
{
buff
.
append
(
" selected"
);
}
buff
.
append
(
">"
);
buff
.
append
(
PageParser
.
escapeHtml
(
n
[
1
]));
buff
.
append
(
"</option>"
);
}
return
buff
.
toString
();
}
public
void
run
()
{
try
{
input
=
socket
.
getInputStream
();
String
head
=
readHeaderLine
();
if
(
head
.
startsWith
(
"GET "
)
||
head
.
startsWith
(
"POST "
))
{
int
begin
=
head
.
indexOf
(
'/'
),
end
=
head
.
lastIndexOf
(
' '
);
String
file
=
head
.
substring
(
begin
+
1
,
end
).
trim
();
if
(
file
.
length
()
==
0
)
{
file
=
"index.do"
;
}
if
(!
allow
())
{
file
=
"notAllowed.jsp"
;
}
server
.
trace
(
head
+
" :"
+
file
);
attributes
=
new
Properties
();
int
paramIndex
=
file
.
indexOf
(
"?"
);
session
=
null
;
if
(
paramIndex
>=
0
)
{
String
attrib
=
file
.
substring
(
paramIndex
+
1
);
parseAttributes
(
attrib
);
String
sessionId
=
attributes
.
getProperty
(
"jsessionid"
);
file
=
file
.
substring
(
0
,
paramIndex
);
session
=
server
.
getSession
(
sessionId
);
}
// TODO web: support errors
String
mimeType
;
boolean
cache
;
int
index
=
file
.
lastIndexOf
(
'.'
);
String
suffix
;
if
(
index
>=
0
)
{
suffix
=
file
.
substring
(
index
+
1
);
}
else
{
suffix
=
""
;
}
if
(
suffix
.
equals
(
"ico"
))
{
mimeType
=
"image/x-icon"
;
cache
=
true
;
}
else
if
(
suffix
.
equals
(
"gif"
))
{
mimeType
=
"image/gif"
;
cache
=
true
;
}
else
if
(
suffix
.
equals
(
"css"
))
{
cache
=
true
;
mimeType
=
"text/css"
;
}
else
if
(
suffix
.
equals
(
"html"
)
||
suffix
.
equals
(
"do"
)
||
suffix
.
equals
(
"jsp"
))
{
cache
=
false
;
mimeType
=
"text/html"
;
if
(
session
==
null
)
{
String
hostname
=
socket
.
getInetAddress
().
getHostName
();
session
=
server
.
createNewSession
(
hostname
);
if
(!
file
.
equals
(
"notAllowed.jsp"
))
{
file
=
"index.do"
;
}
}
}
else
if
(
suffix
.
equals
(
"js"
))
{
cache
=
true
;
mimeType
=
"text/javascript"
;
}
else
{
cache
=
false
;
mimeType
=
"text/html"
;
file
=
"error.jsp"
;
server
.
trace
(
"unknown mime type, file "
+
file
);
}
server
.
trace
(
"mimeType="
+
mimeType
);
parseHeader
();
server
.
trace
(
file
);
if
(
file
.
endsWith
(
".do"
))
{
file
=
process
(
file
);
}
String
message
;
byte
[]
bytes
;
if
(
cache
&&
ifModifiedSince
!=
null
&&
ifModifiedSince
.
equals
(
server
.
getStartDateTime
()))
{
bytes
=
null
;
message
=
"HTTP/1.1 304 Not Modified\n"
;
}
else
{
bytes
=
server
.
getFile
(
file
);
if
(
bytes
==
null
)
{
message
=
"HTTP/1.0 404 Not Found\n"
;
bytes
=
StringUtils
.
utf8Encode
(
"File not found: "
+
file
);
}
else
{
if
(
session
!=
null
&&
file
.
endsWith
(
".jsp"
))
{
bytes
=
StringUtils
.
utf8Encode
(
fill
(
StringUtils
.
utf8Decode
(
bytes
)));
}
message
=
"HTTP/1.1 200 OK\n"
;
message
+=
"Content-Type: "
+
mimeType
+
"\n"
;
if
(!
cache
)
{
message
+=
"Cache-Control: no-cache\n"
;
}
else
{
message
+=
"Cache-Control: max-age=10\n"
;
message
+=
"Last-Modified: "
+
server
.
getStartDateTime
()+
"\n"
;
}
}
}
message
+=
"\n"
;
server
.
trace
(
message
);
DataOutputStream
output
;
output
=
new
DataOutputStream
(
new
BufferedOutputStream
(
socket
.
getOutputStream
()));
output
.
write
(
message
.
getBytes
());
if
(
bytes
!=
null
)
{
output
.
write
(
bytes
);
}
output
.
flush
();
output
.
close
();
output
.
close
();
socket
.
close
();
return
;
}
}
catch
(
Exception
e
)
{
TraceSystem
.
traceThrowable
(
e
);
}
}
private
String
readHeaderLine
()
throws
IOException
{
StringBuffer
buff
=
new
StringBuffer
();
while
(
true
)
{
int
i
=
input
.
read
();
if
(
i
==
-
1
)
{
throw
new
IOException
(
"Unexpected EOF"
);
}
else
if
(
i
==
'\r'
&&
input
.
read
()==
'\n'
)
{
return
buff
.
length
()
>
0
?
buff
.
toString
()
:
null
;
}
else
{
buff
.
append
((
char
)
i
);
}
}
}
private
void
parseAttributes
(
String
s
)
throws
Exception
{
server
.
trace
(
"data="
+
s
);
while
(
s
!=
null
)
{
int
idx
=
s
.
indexOf
(
'='
);
if
(
idx
>=
0
)
{
String
property
=
s
.
substring
(
0
,
idx
);
s
=
s
.
substring
(
idx
+
1
);
idx
=
s
.
indexOf
(
'&'
);
String
value
;
if
(
idx
>=
0
)
{
value
=
s
.
substring
(
0
,
idx
);
s
=
s
.
substring
(
idx
+
1
);
}
else
{
value
=
s
;
}
// TODO compatibility problem with JDK 1.3
//String attr = URLDecoder.decode(value, "UTF-8");
// String attr = URLDecoder.decode(value);
String
attr
=
StringUtils
.
urlDecode
(
value
);
attributes
.
put
(
property
,
attr
);
}
else
{
break
;
}
}
server
.
trace
(
attributes
.
toString
());
}
private
void
parseHeader
()
throws
Exception
{
server
.
trace
(
"parseHeader"
);
int
len
=
0
;
ifModifiedSince
=
null
;
while
(
true
)
{
String
line
=
readHeaderLine
();
if
(
line
==
null
)
{
break
;
}
server
.
trace
(
" "
+
line
);
String
lower
=
StringUtils
.
toLowerEnglish
(
line
);
if
(
lower
.
startsWith
(
"if-modified-since"
))
{
ifModifiedSince
=
line
.
substring
(
line
.
indexOf
(
':'
)+
1
).
trim
();
}
else
if
(
lower
.
startsWith
(
"content-length"
))
{
len
=
Integer
.
parseInt
(
line
.
substring
(
line
.
indexOf
(
':'
)+
1
).
trim
());
server
.
trace
(
"len="
+
len
);
}
else
if
(
lower
.
startsWith
(
"accept-language"
))
{
if
(
session
!=
null
)
{
Locale
locale
=
session
.
locale
;
if
(
locale
==
null
)
{
String
languages
=
line
.
substring
(
line
.
indexOf
(
':'
)+
1
).
trim
();
StringTokenizer
tokenizer
=
new
StringTokenizer
(
languages
,
",;"
);
while
(
tokenizer
.
hasMoreTokens
())
{
String
token
=
tokenizer
.
nextToken
();
if
(!
token
.
startsWith
(
"q="
))
{
if
(
server
.
supportsLanguage
(
token
))
{
int
dash
=
token
.
indexOf
(
'-'
);
if
(
dash
>=
0
)
{
String
language
=
token
.
substring
(
0
,
dash
);
String
country
=
token
.
substring
(
dash
+
1
);
locale
=
new
Locale
(
language
,
country
);
}
else
{
locale
=
new
Locale
(
token
,
""
);
}
session
.
locale
=
locale
;
String
language
=
locale
.
getLanguage
();
session
.
put
(
"language"
,
language
);
server
.
readTranslations
(
session
,
language
);
break
;
}
}
}
}
}
}
else
if
(
line
.
trim
().
length
()==
0
)
{
break
;
}
}
if
(
session
!=
null
&&
len
>
0
)
{
byte
[]
bytes
=
new
byte
[
len
];
for
(
int
pos
=
0
;
pos
<
len
;)
{
pos
+=
input
.
read
(
bytes
,
pos
,
len
-
pos
);
}
String
s
=
new
String
(
bytes
);
parseAttributes
(
s
);
}
}
private
String
fill
(
String
page
)
{
return
PageParser
.
parse
(
server
,
page
,
session
.
map
);
}
}
String
process
(
String
file
)
{
String
process
(
String
file
)
{
...
@@ -130,7 +389,7 @@ public class AppThread extends WebServerThread {
...
@@ -130,7 +389,7 @@ public class AppThread extends WebServerThread {
if
(
sql
.
trim
().
length
()>
0
&&
Character
.
isLowerCase
(
sql
.
trim
().
charAt
(
0
)))
{
if
(
sql
.
trim
().
length
()>
0
&&
Character
.
isLowerCase
(
sql
.
trim
().
charAt
(
0
)))
{
lowercase
=
true
;
lowercase
=
true
;
}
}
Bnf
bnf
=
getAppSession
()
.
getBnf
();
Bnf
bnf
=
session
.
getBnf
();
if
(
bnf
==
null
)
{
if
(
bnf
==
null
)
{
return
"autoCompleteList.jsp"
;
return
"autoCompleteList.jsp"
;
}
}
...
@@ -184,21 +443,19 @@ public class AppThread extends WebServerThread {
...
@@ -184,21 +443,19 @@ public class AppThread extends WebServerThread {
}
}
private
String
admin
()
{
private
String
admin
()
{
AppServer
app
=
server
.
getAppServer
();
session
.
put
(
"port"
,
""
+
server
.
getPort
());
session
.
put
(
"port"
,
""
+
app
.
getPort
());
session
.
put
(
"allowOthers"
,
""
+
server
.
getAllowOthers
());
session
.
put
(
"allowOthers"
,
""
+
app
.
getAllowOthers
());
session
.
put
(
"ssl"
,
String
.
valueOf
(
server
.
getSSL
()));
session
.
put
(
"ssl"
,
String
.
valueOf
(
app
.
getSSL
()));
session
.
put
(
"sessions"
,
server
.
getSessions
());
session
.
put
(
"sessions"
,
server
.
getSessions
());
return
"admin.jsp"
;
return
"admin.jsp"
;
}
}
private
String
adminSave
()
{
private
String
adminSave
()
{
AppServer
app
=
server
.
getAppServer
();
try
{
try
{
app
.
setPort
(
MathUtils
.
decodeInt
((
String
)
attributes
.
get
(
"port"
)));
server
.
setPort
(
MathUtils
.
decodeInt
((
String
)
attributes
.
get
(
"port"
)));
app
.
setAllowOthers
(
Boolean
.
valueOf
((
String
)
attributes
.
get
(
"allowOthers"
)).
booleanValue
());
server
.
setAllowOthers
(
Boolean
.
valueOf
((
String
)
attributes
.
get
(
"allowOthers"
)).
booleanValue
());
app
.
setSSL
(
Boolean
.
valueOf
((
String
)
attributes
.
get
(
"ssl"
)).
booleanValue
());
server
.
setSSL
(
Boolean
.
valueOf
((
String
)
attributes
.
get
(
"ssl"
)).
booleanValue
());
app
.
saveSettings
();
server
.
saveSettings
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
server
.
trace
(
e
.
toString
());
server
.
trace
(
e
.
toString
());
}
}
...
@@ -206,7 +463,7 @@ public class AppThread extends WebServerThread {
...
@@ -206,7 +463,7 @@ public class AppThread extends WebServerThread {
}
}
private
String
adminShutdown
()
{
private
String
adminShutdown
()
{
if
(
allowShutdown
)
{
if
(
server
.
getAllowShutdown
()
)
{
System
.
exit
(
0
);
System
.
exit
(
0
);
}
}
return
"admin.jsp"
;
return
"admin.jsp"
;
...
@@ -227,14 +484,14 @@ public class AppThread extends WebServerThread {
...
@@ -227,14 +484,14 @@ public class AppThread extends WebServerThread {
language
=
(
String
)
session
.
get
(
"language"
);
language
=
(
String
)
session
.
get
(
"language"
);
}
}
session
.
put
(
"languageCombo"
,
getComboBox
(
languageArray
,
language
));
session
.
put
(
"languageCombo"
,
getComboBox
(
languageArray
,
language
));
String
[]
settingNames
=
server
.
get
AppServer
().
get
SettingNames
();
String
[]
settingNames
=
server
.
getSettingNames
();
String
setting
=
attributes
.
getProperty
(
"setting"
);
String
setting
=
attributes
.
getProperty
(
"setting"
);
if
(
setting
==
null
&&
settingNames
.
length
>
0
)
{
if
(
setting
==
null
&&
settingNames
.
length
>
0
)
{
setting
=
settingNames
[
0
];
setting
=
settingNames
[
0
];
}
}
String
combobox
=
getComboBox
(
settingNames
,
setting
);
String
combobox
=
getComboBox
(
settingNames
,
setting
);
session
.
put
(
"settingsList"
,
combobox
);
session
.
put
(
"settingsList"
,
combobox
);
ConnectionInfo
info
=
server
.
get
AppServer
().
get
Setting
(
setting
);
ConnectionInfo
info
=
server
.
getSetting
(
setting
);
if
(
info
==
null
)
{
if
(
info
==
null
)
{
info
=
new
ConnectionInfo
();
info
=
new
ConnectionInfo
();
}
}
...
@@ -248,7 +505,7 @@ public class AppThread extends WebServerThread {
...
@@ -248,7 +505,7 @@ public class AppThread extends WebServerThread {
private
String
getHistory
()
{
private
String
getHistory
()
{
int
id
=
Integer
.
parseInt
(
attributes
.
getProperty
(
"id"
));
int
id
=
Integer
.
parseInt
(
attributes
.
getProperty
(
"id"
));
String
sql
=
getAppSession
()
.
getCommand
(
id
);
String
sql
=
session
.
getCommand
(
id
);
session
.
put
(
"query"
,
PageParser
.
escapeHtmlNoBreak
(
sql
));
session
.
put
(
"query"
,
PageParser
.
escapeHtmlNoBreak
(
sql
));
return
"query.jsp"
;
return
"query.jsp"
;
}
}
...
@@ -330,9 +587,8 @@ public class AppThread extends WebServerThread {
...
@@ -330,9 +587,8 @@ public class AppThread extends WebServerThread {
if
(
schema
==
null
)
{
if
(
schema
==
null
)
{
return
treeIndex
;
return
treeIndex
;
}
}
AppSession
app
=
getAppSession
();
Connection
conn
=
session
.
getConnection
();
Connection
conn
=
getAppSession
().
getConnection
();
DatabaseMetaData
meta
=
session
.
getMetaData
();
DatabaseMetaData
meta
=
app
.
getMetaData
();
int
level
=
mainSchema
?
0
:
1
;
int
level
=
mainSchema
?
0
:
1
;
String
indentation
=
", "
+
level
+
", "
+(
level
+
1
)+
", "
;
String
indentation
=
", "
+
level
+
", "
+(
level
+
1
)+
", "
;
String
indentNode
=
", "
+(
level
+
1
)+
", "
+(
level
+
1
)+
", "
;
String
indentNode
=
", "
+(
level
+
1
)+
", "
+(
level
+
1
)+
", "
;
...
@@ -404,13 +660,12 @@ public class AppThread extends WebServerThread {
...
@@ -404,13 +660,12 @@ public class AppThread extends WebServerThread {
}
}
private
String
tables
()
{
private
String
tables
()
{
AppSession
app
=
getAppSession
();
DbContents
contents
=
session
.
getContents
();
DbContents
contents
=
app
.
getContents
();
try
{
try
{
contents
.
readContents
(
app
.
getMetaData
());
contents
.
readContents
(
session
.
getMetaData
());
app
.
loadBnf
();
session
.
loadBnf
();
Connection
conn
=
app
.
getConnection
();
Connection
conn
=
session
.
getConnection
();
DatabaseMetaData
meta
=
app
.
getMetaData
();
DatabaseMetaData
meta
=
session
.
getMetaData
();
boolean
isH2
=
contents
.
isH2
;
boolean
isH2
=
contents
.
isH2
;
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
...
@@ -512,7 +767,7 @@ public class AppThread extends WebServerThread {
...
@@ -512,7 +767,7 @@ public class AppThread extends WebServerThread {
session
.
put
(
"url"
,
url
);
session
.
put
(
"url"
,
url
);
session
.
put
(
"user"
,
user
);
session
.
put
(
"user"
,
user
);
try
{
try
{
Connection
conn
=
server
.
get
AppServer
().
get
Connection
(
driver
,
url
,
user
,
password
);
Connection
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
);
JdbcUtils
.
closeSilently
(
conn
);
JdbcUtils
.
closeSilently
(
conn
);
session
.
put
(
"error"
,
"${text.login.testSuccessful}"
);
session
.
put
(
"error"
,
"${text.login.testSuccessful}"
);
return
"index.jsp"
;
return
"index.jsp"
;
...
@@ -536,9 +791,8 @@ public class AppThread extends WebServerThread {
...
@@ -536,9 +791,8 @@ public class AppThread extends WebServerThread {
String
user
=
attributes
.
getProperty
(
"user"
,
""
);
String
user
=
attributes
.
getProperty
(
"user"
,
""
);
String
password
=
attributes
.
getProperty
(
"password"
,
""
);
String
password
=
attributes
.
getProperty
(
"password"
,
""
);
try
{
try
{
Connection
conn
=
server
.
getAppServer
().
getConnection
(
driver
,
url
,
user
,
password
);
Connection
conn
=
server
.
getConnection
(
driver
,
url
,
user
,
password
);
AppSession
appSession
=
getAppSession
();
session
.
setConnection
(
conn
);
appSession
.
setConnection
(
conn
);
session
.
put
(
"url"
,
url
);
session
.
put
(
"url"
,
url
);
session
.
put
(
"user"
,
user
);
session
.
put
(
"user"
,
user
);
session
.
put
(
"autoCommit"
,
"checked"
);
session
.
put
(
"autoCommit"
,
"checked"
);
...
@@ -555,8 +809,8 @@ public class AppThread extends WebServerThread {
...
@@ -555,8 +809,8 @@ public class AppThread extends WebServerThread {
private
String
logout
()
{
private
String
logout
()
{
try
{
try
{
Connection
conn
=
getAppSession
()
.
getConnection
();
Connection
conn
=
session
.
getConnection
();
getAppSession
()
.
setConnection
(
null
);
session
.
setConnection
(
null
);
session
.
remove
(
"conn"
);
session
.
remove
(
"conn"
);
session
.
remove
(
"result"
);
session
.
remove
(
"result"
);
session
.
remove
(
"tables"
);
session
.
remove
(
"tables"
);
...
@@ -573,7 +827,7 @@ public class AppThread extends WebServerThread {
...
@@ -573,7 +827,7 @@ public class AppThread extends WebServerThread {
private
String
query
()
{
private
String
query
()
{
String
sql
=
attributes
.
getProperty
(
"sql"
).
trim
();
String
sql
=
attributes
.
getProperty
(
"sql"
).
trim
();
try
{
try
{
Connection
conn
=
getAppSession
()
.
getConnection
();
Connection
conn
=
session
.
getConnection
();
String
result
;
String
result
;
if
(
sql
.
equals
(
"@AUTOCOMMIT TRUE"
))
{
if
(
sql
.
equals
(
"@AUTOCOMMIT TRUE"
))
{
conn
.
setAutoCommit
(
true
);
conn
.
setAutoCommit
(
true
);
...
@@ -626,7 +880,7 @@ public class AppThread extends WebServerThread {
...
@@ -626,7 +880,7 @@ public class AppThread extends WebServerThread {
}
}
private
String
editResult
()
{
private
String
editResult
()
{
ResultSet
rs
=
getAppSession
()
.
result
;
ResultSet
rs
=
session
.
result
;
int
row
=
Integer
.
parseInt
(
attributes
.
getProperty
(
"row"
));
int
row
=
Integer
.
parseInt
(
attributes
.
getProperty
(
"row"
));
int
op
=
Integer
.
parseInt
(
attributes
.
getProperty
(
"op"
));
int
op
=
Integer
.
parseInt
(
attributes
.
getProperty
(
"op"
));
String
result
=
""
,
error
=
""
;
String
result
=
""
,
error
=
""
;
...
@@ -658,7 +912,7 @@ public class AppThread extends WebServerThread {
...
@@ -658,7 +912,7 @@ public class AppThread extends WebServerThread {
error
=
formatAsError
(
e
.
getMessage
());
error
=
formatAsError
(
e
.
getMessage
());
}
}
String
sql
=
"@EDIT "
+
(
String
)
session
.
get
(
"resultSetSQL"
);
String
sql
=
"@EDIT "
+
(
String
)
session
.
get
(
"resultSetSQL"
);
Connection
conn
=
getAppSession
()
.
getConnection
();
Connection
conn
=
session
.
getConnection
();
result
=
error
+
getResult
(
conn
,
-
1
,
sql
,
true
)
+
result
;
result
=
error
+
getResult
(
conn
,
-
1
,
sql
,
true
)
+
result
;
session
.
put
(
"result"
,
result
);
session
.
put
(
"result"
,
result
);
return
"result.jsp"
;
return
"result.jsp"
;
...
@@ -904,7 +1158,7 @@ public class AppThread extends WebServerThread {
...
@@ -904,7 +1158,7 @@ public class AppThread extends WebServerThread {
boolean
generatedKeys
=
false
;
boolean
generatedKeys
=
false
;
boolean
edit
=
false
;
boolean
edit
=
false
;
if
(
sql
.
equals
(
"@CANCEL"
))
{
if
(
sql
.
equals
(
"@CANCEL"
))
{
stat
=
getAppSession
()
.
executingStatement
;
stat
=
session
.
executingStatement
;
if
(
stat
!=
null
)
{
if
(
stat
!=
null
)
{
stat
.
cancel
();
stat
.
cancel
();
buff
.
append
(
"${text.result.statementWasCancelled}"
);
buff
.
append
(
"${text.result.statementWasCancelled}"
);
...
@@ -942,9 +1196,9 @@ public class AppThread extends WebServerThread {
...
@@ -942,9 +1196,9 @@ public class AppThread extends WebServerThread {
}
else
{
}
else
{
int
maxrows
=
getMaxrows
();
int
maxrows
=
getMaxrows
();
stat
.
setMaxRows
(
maxrows
);
stat
.
setMaxRows
(
maxrows
);
getAppSession
()
.
executingStatement
=
stat
;
session
.
executingStatement
=
stat
;
boolean
isResultSet
=
stat
.
execute
(
sql
);
boolean
isResultSet
=
stat
.
execute
(
sql
);
getAppSession
()
.
addCommand
(
sql
);
session
.
addCommand
(
sql
);
if
(
generatedKeys
)
{
if
(
generatedKeys
)
{
rs
=
null
;
rs
=
null
;
//#ifdef JDK14
//#ifdef JDK14
...
@@ -977,7 +1231,7 @@ public class AppThread extends WebServerThread {
...
@@ -977,7 +1231,7 @@ public class AppThread extends WebServerThread {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
getStackTrace
(
id
,
e
);
return
getStackTrace
(
id
,
e
);
}
finally
{
}
finally
{
getAppSession
()
.
executingStatement
=
null
;
session
.
executingStatement
=
null
;
}
}
}
}
...
@@ -1038,7 +1292,7 @@ public class AppThread extends WebServerThread {
...
@@ -1038,7 +1292,7 @@ public class AppThread extends WebServerThread {
prep
.
setInt
(
j
+
1
,
i
);
prep
.
setInt
(
j
+
1
,
i
);
}
}
}
}
if
(
getAppSession
()
.
getContents
().
isSQLite
)
{
if
(
session
.
getContents
().
isSQLite
)
{
// SQLite currently throws an exception on prep.execute()
// SQLite currently throws an exception on prep.execute()
prep
.
executeUpdate
();
prep
.
executeUpdate
();
}
else
{
}
else
{
...
@@ -1075,7 +1329,7 @@ public class AppThread extends WebServerThread {
...
@@ -1075,7 +1329,7 @@ public class AppThread extends WebServerThread {
private
String
getHistoryString
()
{
private
String
getHistoryString
()
{
StringBuffer
buff
=
new
StringBuffer
();
StringBuffer
buff
=
new
StringBuffer
();
ArrayList
history
=
getAppSession
()
.
getCommands
();
ArrayList
history
=
session
.
getCommands
();
buff
.
append
(
"<table cellspacing=0 cellpadding=0>"
);
buff
.
append
(
"<table cellspacing=0 cellpadding=0>"
);
buff
.
append
(
"<tr><th></th><th>Command</th></tr>"
);
buff
.
append
(
"<tr><th></th><th>Command</th></tr>"
);
for
(
int
i
=
history
.
size
()-
1
;
i
>=
0
;
i
--)
{
for
(
int
i
=
history
.
size
()-
1
;
i
>=
0
;
i
--)
{
...
@@ -1178,11 +1432,11 @@ public class AppThread extends WebServerThread {
...
@@ -1178,11 +1432,11 @@ public class AppThread extends WebServerThread {
}
}
boolean
isUpdatable
=
rs
.
getConcurrency
()
==
ResultSet
.
CONCUR_UPDATABLE
;
boolean
isUpdatable
=
rs
.
getConcurrency
()
==
ResultSet
.
CONCUR_UPDATABLE
;
if
(
edit
)
{
if
(
edit
)
{
ResultSet
old
=
getAppSession
()
.
result
;
ResultSet
old
=
session
.
result
;
if
(
old
!=
null
)
{
if
(
old
!=
null
)
{
old
.
close
();
old
.
close
();
}
}
getAppSession
()
.
result
=
rs
;
session
.
result
=
rs
;
}
else
{
}
else
{
rs
.
close
();
rs
.
close
();
}
}
...
@@ -1228,25 +1482,25 @@ public class AppThread extends WebServerThread {
...
@@ -1228,25 +1482,25 @@ public class AppThread extends WebServerThread {
info
.
driver
=
attributes
.
getProperty
(
"driver"
,
""
);
info
.
driver
=
attributes
.
getProperty
(
"driver"
,
""
);
info
.
url
=
attributes
.
getProperty
(
"url"
,
""
);
info
.
url
=
attributes
.
getProperty
(
"url"
,
""
);
info
.
user
=
attributes
.
getProperty
(
"user"
,
""
);
info
.
user
=
attributes
.
getProperty
(
"user"
,
""
);
server
.
getAppServer
().
updateSetting
(
info
);
server
.
updateSetting
(
info
);
attributes
.
put
(
"setting"
,
info
.
name
);
attributes
.
put
(
"setting"
,
info
.
name
);
server
.
getAppServer
().
saveSettings
();
server
.
saveSettings
();
return
"index.do"
;
return
"index.do"
;
}
}
private
String
settingRemove
()
{
private
String
settingRemove
()
{
String
setting
=
attributes
.
getProperty
(
"name"
,
""
);
String
setting
=
attributes
.
getProperty
(
"name"
,
""
);
server
.
getAppServer
().
removeSetting
(
setting
);
server
.
removeSetting
(
setting
);
ArrayList
settings
=
server
.
get
AppServer
().
get
Settings
();
ArrayList
settings
=
server
.
getSettings
();
if
(
settings
.
size
()
>
0
)
{
if
(
settings
.
size
()
>
0
)
{
attributes
.
put
(
"setting"
,
settings
.
get
(
0
));
attributes
.
put
(
"setting"
,
settings
.
get
(
0
));
}
}
server
.
getAppServer
().
saveSettings
();
server
.
saveSettings
();
return
"index.do"
;
return
"index.do"
;
}
}
boolean
allow
()
{
boolean
allow
()
{
if
(
server
.
getA
ppServer
().
getA
llowOthers
())
{
if
(
server
.
getAllowOthers
())
{
return
true
;
return
true
;
}
}
return
NetUtils
.
isLoopbackAddress
(
socket
);
return
NetUtils
.
isLoopbackAddress
(
socket
);
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
42e01bf9
...
@@ -33,8 +33,6 @@ public class DateTimeUtils {
...
@@ -33,8 +33,6 @@ public class DateTimeUtils {
public
static
Time
cloneAndNormalizeTime
(
Time
value
)
{
public
static
Time
cloneAndNormalizeTime
(
Time
value
)
{
Calendar
cal
=
Calendar
.
getInstance
();
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
value
);
cal
.
setTime
(
value
);
// TODO gcj: required so that the millis are calculated?
cal
.
get
(
Calendar
.
HOUR_OF_DAY
);
cal
.
set
(
1970
,
0
,
1
);
cal
.
set
(
1970
,
0
,
1
);
return
new
Time
(
cal
.
getTime
().
getTime
());
return
new
Time
(
cal
.
getTime
().
getTime
());
}
}
...
@@ -42,8 +40,6 @@ public class DateTimeUtils {
...
@@ -42,8 +40,6 @@ public class DateTimeUtils {
public
static
Date
cloneAndNormalizeDate
(
Date
value
)
{
public
static
Date
cloneAndNormalizeDate
(
Date
value
)
{
Calendar
cal
=
Calendar
.
getInstance
();
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
value
);
cal
.
setTime
(
value
);
// TODO gcj: required so that the millis are calculated?
cal
.
get
(
Calendar
.
YEAR
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
cal
.
set
(
Calendar
.
SECOND
,
0
);
cal
.
set
(
Calendar
.
SECOND
,
0
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
...
...
h2/src/main/org/h2/util/FileUtils.java
浏览文件 @
42e01bf9
...
@@ -33,8 +33,6 @@ public class FileUtils {
...
@@ -33,8 +33,6 @@ public class FileUtils {
// TODO detection of 'case in sensitive filesystem' could maybe implemented using some other means
// TODO detection of 'case in sensitive filesystem' could maybe implemented using some other means
private
static
final
boolean
isCaseInsensitiveFileSystem
=
(
File
.
separatorChar
==
'\\'
);
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
{
public
static
RandomAccessFile
openRandomAccessFile
(
String
fileName
,
String
mode
)
throws
IOException
{
fileName
=
translateFileName
(
fileName
);
fileName
=
translateFileName
(
fileName
);
try
{
try
{
...
@@ -222,10 +220,7 @@ public class FileUtils {
...
@@ -222,10 +220,7 @@ public class FileUtils {
wait
(
i
);
wait
(
i
);
}
}
}
}
// TODO GCJ: it seems gcj throws 'CreateFile failed' if the file already exists?!
return
false
;
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
{
public
static
void
delete
(
String
fileName
)
throws
SQLException
{
...
...
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
42e01bf9
...
@@ -23,21 +23,6 @@ import org.h2.message.Message;
...
@@ -23,21 +23,6 @@ import org.h2.message.Message;
public
class
StringUtils
{
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
)
{
public
static
boolean
equals
(
String
a
,
String
b
)
{
if
(
a
==
null
)
{
if
(
a
==
null
)
{
return
b
==
null
;
return
b
==
null
;
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
42e01bf9
...
@@ -558,7 +558,7 @@ public class DataType {
...
@@ -558,7 +558,7 @@ public class DataType {
}
else
if
(
Timestamp
.
class
.
isAssignableFrom
(
x
))
{
}
else
if
(
Timestamp
.
class
.
isAssignableFrom
(
x
))
{
return
Value
.
TIMESTAMP
;
return
Value
.
TIMESTAMP
;
}
else
if
(
java
.
util
.
Date
.
class
.
isAssignableFrom
(
x
))
{
}
else
if
(
java
.
util
.
Date
.
class
.
isAssignableFrom
(
x
))
{
return
Value
.
DATE
;
return
Value
.
TIMESTAMP
;
}
else
if
(
java
.
io
.
Reader
.
class
.
isAssignableFrom
(
x
))
{
}
else
if
(
java
.
io
.
Reader
.
class
.
isAssignableFrom
(
x
))
{
return
Value
.
CLOB
;
return
Value
.
CLOB
;
}
else
if
(
java
.
sql
.
Clob
.
class
.
isAssignableFrom
(
x
))
{
}
else
if
(
java
.
sql
.
Clob
.
class
.
isAssignableFrom
(
x
))
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论