Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3468848d
提交
3468848d
authored
6月 25, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow to start the H2 Console using an existing, open connection
上级
c1a0ab19
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
141 行增加
和
63 行删除
+141
-63
TcpServer.java
h2/src/main/org/h2/server/TcpServer.java
+8
-8
FtpServer.java
h2/src/main/org/h2/server/ftp/FtpServer.java
+2
-2
PgServer.java
h2/src/main/org/h2/server/pg/PgServer.java
+6
-6
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+30
-9
WebSession.java
h2/src/main/org/h2/server/web/WebSession.java
+12
-0
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+10
-1
Server.java
h2/src/main/org/h2/tools/Server.java
+48
-37
Tool.java
h2/src/main/org/h2/util/Tool.java
+25
-0
没有找到文件。
h2/src/main/org/h2/server/TcpServer.java
浏览文件 @
3468848d
...
...
@@ -27,10 +27,10 @@ import org.h2.constant.SysProperties;
import
org.h2.engine.Constants
;
import
org.h2.message.Message
;
import
org.h2.message.TraceSystem
;
import
org.h2.tools.Server
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.Tool
;
/**
* The TCP server implements the native H2 database server protocol.
...
...
@@ -155,11 +155,11 @@ public class TcpServer implements Service {
if
(
"-trace"
.
equals
(
a
))
{
trace
=
true
;
}
else
if
(
"-log"
.
equals
(
a
)
&&
SysProperties
.
OLD_COMMAND_LINE_OPTIONS
)
{
trace
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
trace
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
if
(
"-tcpSSL"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ssl
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ssl
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
ssl
=
true
;
...
...
@@ -171,15 +171,15 @@ public class TcpServer implements Service {
}
else
if
(
"-baseDir"
.
equals
(
a
))
{
baseDir
=
args
[++
i
];
}
else
if
(
"-tcpAllowOthers"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
allowOthers
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
allowOthers
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
allowOthers
=
true
;
}
}
else
if
(
"-ifExists"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ifExists
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ifExists
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
ifExists
=
true
;
...
...
h2/src/main/org/h2/server/ftp/FtpServer.java
浏览文件 @
3468848d
...
...
@@ -23,12 +23,12 @@ import org.h2.constant.SysProperties;
import
org.h2.engine.Constants
;
import
org.h2.server.Service
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.tools.Server
;
import
org.h2.util.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.SortedProperties
;
import
org.h2.util.Tool
;
/**
* Small FTP Server. Intended for ad-hoc networks in a secure environment.
...
...
@@ -235,7 +235,7 @@ public class FtpServer implements Service {
}
else
if
(
"-trace"
.
equals
(
a
))
{
trace
=
true
;
}
else
if
(
"-log"
.
equals
(
a
)
&&
SysProperties
.
OLD_COMMAND_LINE_OPTIONS
)
{
trace
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
trace
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
if
(
"-ftpTask"
.
equals
(
a
))
{
allowTask
=
true
;
...
...
h2/src/main/org/h2/server/pg/PgServer.java
浏览文件 @
3468848d
...
...
@@ -22,9 +22,9 @@ import java.util.Set;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.server.Service
;
import
org.h2.tools.Server
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.Tool
;
/**
* This class implements a subset of the PostgreSQL protocol as described here:
...
...
@@ -54,22 +54,22 @@ public class PgServer implements Service {
if
(
"-trace"
.
equals
(
a
))
{
trace
=
true
;
}
else
if
(
"-log"
.
equals
(
a
)
&&
SysProperties
.
OLD_COMMAND_LINE_OPTIONS
)
{
trace
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
trace
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
if
(
"-pgPort"
.
equals
(
a
))
{
port
=
MathUtils
.
decodeInt
(
args
[++
i
]);
}
else
if
(
"-baseDir"
.
equals
(
a
))
{
baseDir
=
args
[++
i
];
}
else
if
(
"-pgAllowOthers"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
allowOthers
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
allowOthers
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
allowOthers
=
true
;
}
}
else
if
(
"-ifExists"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ifExists
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ifExists
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
ifExists
=
true
;
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
3468848d
...
...
@@ -33,7 +33,6 @@ import org.h2.engine.Constants;
import
org.h2.message.TraceSystem
;
import
org.h2.server.Service
;
import
org.h2.server.ShutdownHandler
;
import
org.h2.tools.Server
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.JdbcUtils
;
...
...
@@ -42,6 +41,7 @@ import org.h2.util.NetUtils;
import
org.h2.util.RandomUtils
;
import
org.h2.util.Resources
;
import
org.h2.util.SortedProperties
;
import
org.h2.util.Tool
;
/**
* The web server is a simple standalone HTTP server that implements the H2
...
...
@@ -224,15 +224,15 @@ public class WebServer implements Service {
if
(
"-webPort"
.
equals
(
a
))
{
port
=
MathUtils
.
decodeInt
(
args
[++
i
]);
}
else
if
(
"-webSSL"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ssl
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ssl
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
ssl
=
true
;
}
}
else
if
(
"-webAllowOthers"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
allowOthers
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
allowOthers
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
allowOthers
=
true
;
...
...
@@ -243,8 +243,8 @@ public class WebServer implements Service {
String
baseDir
=
args
[++
i
];
SysProperties
.
setBaseDir
(
baseDir
);
}
else
if
(
"-ifExists"
.
equals
(
a
))
{
if
(
Server
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ifExists
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
ifExists
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
ifExists
=
true
;
...
...
@@ -252,7 +252,7 @@ public class WebServer implements Service {
}
else
if
(
"-trace"
.
equals
(
a
))
{
trace
=
true
;
}
else
if
(
"-log"
.
equals
(
a
)
&&
SysProperties
.
OLD_COMMAND_LINE_OPTIONS
)
{
trace
=
Server
.
readArgBoolean
(
args
,
i
)
==
1
;
trace
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
}
...
...
@@ -278,15 +278,21 @@ public class WebServer implements Service {
for
(
int
i
=
0
;
i
<
LANGUAGES
.
length
;
i
++)
{
languages
.
add
(
LANGUAGES
[
i
][
0
]);
}
u
rl
=
(
ssl
?
"https"
:
"http"
)
+
"://"
+
NetUtils
.
getLocalAddress
()
+
":"
+
port
;
u
pdateURL
()
;
}
public
String
getURL
()
{
return
url
;
}
private
void
updateURL
()
{
url
=
(
ssl
?
"https"
:
"http"
)
+
"://"
+
NetUtils
.
getLocalAddress
()
+
":"
+
port
;
}
public
void
start
()
throws
SQLException
{
serverSocket
=
NetUtils
.
createServerSocket
(
port
,
ssl
);
port
=
serverSocket
.
getLocalPort
();
updateURL
();
}
public
void
listen
()
{
...
...
@@ -645,4 +651,19 @@ public class WebServer implements Service {
return
allowScript
;
}
/**
* Create a session with a given connection.
*
* @param conn the connection
* @return the URL of the web site to access this connection
*/
public
String
addSession
(
Connection
conn
)
throws
SQLException
{
WebSession
session
=
createNewSession
(
"local"
);
session
.
setShutdownServerOnDisconnect
();
session
.
setConnection
(
conn
);
session
.
put
(
"url"
,
conn
.
getMetaData
().
getURL
());
String
s
=
(
String
)
session
.
get
(
"sessionId"
);
return
url
+
"/frame.jsp?jsessionid="
+
s
;
}
}
h2/src/main/org/h2/server/web/WebSession.java
浏览文件 @
3468848d
...
...
@@ -66,6 +66,7 @@ class WebSession {
private
DbContextRule
aliasRule
;
private
DbContextRule
columnAliasRule
;
private
Bnf
bnf
;
private
boolean
shutdownServerOnDisconnect
;
WebSession
(
WebServer
server
)
{
this
.
server
=
server
;
...
...
@@ -233,5 +234,16 @@ class WebSession {
DbContents
getContents
()
{
return
contents
;
}
/**
* Shutdown the server when disconnecting.
*/
void
setShutdownServerOnDisconnect
()
{
this
.
shutdownServerOnDisconnect
=
true
;
}
boolean
getShutdownServerOnDisconnect
()
{
return
shutdownServerOnDisconnect
;
}
}
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
3468848d
...
...
@@ -119,6 +119,11 @@ class WebThread extends Thread implements DatabaseEventListener {
*/
void
stopNow
()
{
this
.
stop
=
true
;
try
{
socket
.
close
();
}
catch
(
IOException
e
)
{
// ignore
}
}
private
String
getAllowedFile
(
String
requestedFile
)
{
...
...
@@ -1197,7 +1202,11 @@ class WebThread extends Thread implements DatabaseEventListener {
session
.
remove
(
"user"
);
session
.
remove
(
"tool"
);
if
(
conn
!=
null
)
{
conn
.
close
();
if
(
session
.
getShutdownServerOnDisconnect
())
{
server
.
shutdown
();
}
else
{
conn
.
close
();
}
}
}
catch
(
Exception
e
)
{
trace
(
e
.
toString
());
...
...
h2/src/main/org/h2/tools/Server.java
浏览文件 @
3468848d
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
tools
;
import
java.io.PrintStream
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
...
...
@@ -21,6 +22,7 @@ import org.h2.server.ftp.FtpServer;
import
org.h2.server.pg.PgServer
;
import
org.h2.server.web.WebServer
;
import
org.h2.util.StartBrowser
;
import
org.h2.util.Tool
;
/**
* This tool can be used to start various database servers (listeners).
...
...
@@ -129,12 +131,12 @@ public class Server implements Runnable, ShutdownHandler {
* @param args the command line arguments
* @throws SQLException
*/
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
int
exitCode
=
new
Server
().
run
(
args
,
System
.
out
);
if
(
exitCode
!=
0
)
{
System
.
exit
(
exitCode
);
}
}
//
public static void main(String[] args) throws SQLException {
//
int exitCode = new Server().run(args, System.out);
//
if (exitCode != 0) {
//
System.exit(exitCode);
//
}
//
}
/**
* INTERNAL
...
...
@@ -158,11 +160,11 @@ public class Server implements Runnable, ShutdownHandler {
startDefaultServers
=
false
;
webStart
=
true
;
}
else
if
(
"-webAllowOthers"
.
equals
(
arg
))
{
if
(
readArgBoolean
(
args
,
i
)
!=
0
)
{
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
i
++;
}
}
else
if
(
"-webSSL"
.
equals
(
arg
))
{
if
(
readArgBoolean
(
args
,
i
)
!=
0
)
{
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
i
++;
}
}
else
if
(
"-webPort"
.
equals
(
arg
))
{
...
...
@@ -181,11 +183,11 @@ public class Server implements Runnable, ShutdownHandler {
startDefaultServers
=
false
;
tcpStart
=
true
;
}
else
if
(
"-tcpAllowOthers"
.
equals
(
arg
))
{
if
(
readArgBoolean
(
args
,
i
)
!=
0
)
{
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
i
++;
}
}
else
if
(
"-tcpSSL"
.
equals
(
arg
))
{
if
(
readArgBoolean
(
args
,
i
)
!=
0
)
{
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
i
++;
}
}
else
if
(
"-tcpPort"
.
equals
(
arg
))
{
...
...
@@ -197,8 +199,8 @@ public class Server implements Runnable, ShutdownHandler {
tcpShutdown
=
true
;
tcpShutdownServer
=
args
[++
i
];
}
else
if
(
"-tcpShutdownForce"
.
equals
(
arg
))
{
if
(
readArgBoolean
(
args
,
i
)
!=
0
)
{
tcpShutdownForce
=
readArgBoolean
(
args
,
i
)
==
1
;
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
tcpShutdownForce
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
i
++;
}
else
{
tcpShutdownForce
=
true
;
...
...
@@ -212,7 +214,7 @@ public class Server implements Runnable, ShutdownHandler {
startDefaultServers
=
false
;
pgStart
=
true
;
}
else
if
(
"-pgAllowOthers"
.
equals
(
arg
))
{
if
(
readArgBoolean
(
args
,
i
)
!=
0
)
{
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
i
++;
}
}
else
if
(
"-pgPort"
.
equals
(
arg
))
{
...
...
@@ -246,7 +248,7 @@ public class Server implements Runnable, ShutdownHandler {
}
else
if
(
"-log"
.
equals
(
arg
)
&&
SysProperties
.
OLD_COMMAND_LINE_OPTIONS
)
{
i
++;
}
else
if
(
"-ifExists"
.
equals
(
arg
))
{
if
(
readArgBoolean
(
args
,
i
)
!=
0
)
{
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
i
++;
}
}
else
if
(
"-baseDir"
.
equals
(
arg
))
{
...
...
@@ -322,29 +324,6 @@ public class Server implements Runnable, ShutdownHandler {
return
exitCode
;
}
/**
* Read an argument and check if it is true (1), false (-1), or not (0).
* This method is used for compatibility with older versions only.
*
* @param args the list of arguments
* @param i the index - 1
* @return 1, -1, or 0
*/
public
static
int
readArgBoolean
(
String
[]
args
,
int
i
)
{
if
(!
SysProperties
.
OLD_COMMAND_LINE_OPTIONS
)
{
return
0
;
}
if
(
i
+
1
<
args
.
length
)
{
String
a
=
args
[++
i
];
if
(
"true"
.
equals
(
a
))
{
return
1
;
}
else
if
(
"false"
.
equals
(
a
))
{
return
-
1
;
}
}
return
0
;
}
/**
* Shutdown a TCP server. If force is set to false, the server will not
* allow new connections, but not kill existing connections, instead it will
...
...
@@ -564,4 +543,36 @@ public class Server implements Runnable, ShutdownHandler {
public
Service
getService
()
{
return
service
;
}
/**
* Start a web server and a browser that uses the given connection. The
* current transaction is preserved. This is specially useful to manually
* inspect the database when debugging.
*
* @param conn the database connection (the database must be open)
*/
public
static
void
startWebServer
(
Connection
conn
)
throws
SQLException
{
final
Object
waitUntilDisconnected
=
new
Object
();
WebServer
webServer
=
new
WebServer
();
Server
server
=
new
Server
(
webServer
,
new
String
[]
{
"-webPort"
,
"0"
});
webServer
.
setShutdownHandler
(
new
ShutdownHandler
()
{
public
void
shutdown
()
{
synchronized
(
waitUntilDisconnected
)
{
waitUntilDisconnected
.
notifyAll
();
}
}
});
server
.
start
();
String
url
=
webServer
.
addSession
(
conn
);
StartBrowser
.
openURL
(
url
);
synchronized
(
waitUntilDisconnected
)
{
try
{
waitUntilDisconnected
.
wait
();
}
catch
(
InterruptedException
e
)
{
// ignore
}
}
webServer
.
stop
();
}
}
h2/src/main/org/h2/util/Tool.java
浏览文件 @
3468848d
...
...
@@ -9,6 +9,8 @@ package org.h2.util;
import
java.io.PrintStream
;
import
java.sql.SQLException
;
import
org.h2.constant.SysProperties
;
/**
* Command line tools implement the tool interface so that they can be used in
* the H2 Console.
...
...
@@ -54,5 +56,28 @@ public abstract class Tool {
}
out
.
println
(
buff
.
toString
());
}
/**
* Read an argument and check if it is true (1), false (-1), or not (0).
* This method is used for compatibility with older versions only.
*
* @param args the list of arguments
* @param i the index - 1
* @return 1 for true, -1 for false, or 0 for not read
*/
public
static
int
readArgBoolean
(
String
[]
args
,
int
i
)
{
if
(!
SysProperties
.
OLD_COMMAND_LINE_OPTIONS
)
{
return
0
;
}
if
(
i
+
1
<
args
.
length
)
{
String
a
=
args
[++
i
];
if
(
"true"
.
equals
(
a
))
{
return
1
;
}
else
if
(
"false"
.
equals
(
a
))
{
return
-
1
;
}
}
return
0
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论