Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a55cd699
提交
a55cd699
authored
11月 26, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
26e617c5
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
225 行增加
和
89 行删除
+225
-89
Service.java
h2/src/main/org/h2/server/Service.java
+1
-0
TcpServer.java
h2/src/main/org/h2/server/TcpServer.java
+4
-0
FtpServer.java
h2/src/main/org/h2/server/ftp/FtpServer.java
+12
-7
PgServer.java
h2/src/main/org/h2/server/pg/PgServer.java
+4
-0
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+4
-0
Server.java
h2/src/main/org/h2/tools/Server.java
+145
-81
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+7
-0
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+48
-1
没有找到文件。
h2/src/main/org/h2/server/Service.java
浏览文件 @
a55cd699
...
@@ -14,5 +14,6 @@ public interface Service {
...
@@ -14,5 +14,6 @@ public interface Service {
void
stop
();
void
stop
();
boolean
isRunning
();
boolean
isRunning
();
boolean
getAllowOthers
();
boolean
getAllowOthers
();
String
getName
();
String
getType
();
String
getType
();
}
}
h2/src/main/org/h2/server/TcpServer.java
浏览文件 @
a55cd699
...
@@ -248,6 +248,10 @@ public class TcpServer implements Service {
...
@@ -248,6 +248,10 @@ public class TcpServer implements Service {
return
"TCP"
;
return
"TCP"
;
}
}
public
String
getName
()
{
return
"H2 TCP Server"
;
}
public
void
logInternalError
(
String
string
)
{
public
void
logInternalError
(
String
string
)
{
if
(
TcpServer
.
logInternalErrors
)
{
if
(
TcpServer
.
logInternalErrors
)
{
System
.
out
.
println
(
string
);
System
.
out
.
println
(
string
);
...
...
h2/src/main/org/h2/server/ftp/FtpServer.java
浏览文件 @
a55cd699
...
@@ -157,19 +157,20 @@ public class FtpServer implements Service {
...
@@ -157,19 +157,20 @@ public class FtpServer implements Service {
public
void
init
(
String
[]
args
)
throws
Exception
{
public
void
init
(
String
[]
args
)
throws
Exception
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
if
(
"-ftpPort"
.
equals
(
args
[
i
]))
{
String
a
=
args
[
i
];
if
(
"-ftpPort"
.
equals
(
a
))
{
port
=
MathUtils
.
decodeInt
(
args
[++
i
]);
port
=
MathUtils
.
decodeInt
(
args
[++
i
]);
}
else
if
(
"-ftpDir"
.
equals
(
a
rgs
[
i
]
))
{
}
else
if
(
"-ftpDir"
.
equals
(
a
))
{
root
=
FileUtils
.
normalize
(
args
[++
i
]);
root
=
FileUtils
.
normalize
(
args
[++
i
]);
}
else
if
(
"-ftpRead"
.
equals
(
a
rgs
[
i
]
))
{
}
else
if
(
"-ftpRead"
.
equals
(
a
))
{
readUserName
=
args
[++
i
];
readUserName
=
args
[++
i
];
}
else
if
(
"-ftpWrite"
.
equals
(
a
rgs
[
i
]
))
{
}
else
if
(
"-ftpWrite"
.
equals
(
a
))
{
writeUserName
=
args
[++
i
];
writeUserName
=
args
[++
i
];
}
else
if
(
"-ftpWritePassword"
.
equals
(
a
rgs
[
i
]
))
{
}
else
if
(
"-ftpWritePassword"
.
equals
(
a
))
{
writePassword
=
args
[++
i
];
writePassword
=
args
[++
i
];
}
else
if
(
"-log"
.
equals
(
a
rgs
[
i
]
))
{
}
else
if
(
"-log"
.
equals
(
a
))
{
log
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
log
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
if
(
"-ftpTask"
.
equals
(
a
rgs
[
i
]
))
{
}
else
if
(
"-ftpTask"
.
equals
(
a
))
{
allowTask
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
allowTask
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
}
}
}
...
@@ -216,6 +217,10 @@ public class FtpServer implements Service {
...
@@ -216,6 +217,10 @@ public class FtpServer implements Service {
return
"FTP"
;
return
"FTP"
;
}
}
public
String
getName
()
{
return
"H2 FTP Server"
;
}
void
log
(
String
s
)
{
void
log
(
String
s
)
{
if
(
log
)
{
if
(
log
)
{
System
.
out
.
println
(
s
);
System
.
out
.
println
(
s
);
...
...
h2/src/main/org/h2/server/pg/PgServer.java
浏览文件 @
a55cd699
...
@@ -177,6 +177,10 @@ public class PgServer implements Service {
...
@@ -177,6 +177,10 @@ public class PgServer implements Service {
public
String
getType
()
{
public
String
getType
()
{
return
"PG"
;
return
"PG"
;
}
}
public
String
getName
()
{
return
"H2 PG Server"
;
}
public
boolean
getIfExists
()
{
public
boolean
getIfExists
()
{
return
ifExists
;
return
ifExists
;
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
a55cd699
...
@@ -336,6 +336,10 @@ public class WebServer implements Service {
...
@@ -336,6 +336,10 @@ public class WebServer implements Service {
return
"Web"
;
return
"Web"
;
}
}
public
String
getName
()
{
return
"H2 Console Server"
;
}
void
setAllowOthers
(
boolean
b
)
{
void
setAllowOthers
(
boolean
b
)
{
allowOthers
=
b
;
allowOthers
=
b
;
}
}
...
...
h2/src/main/org/h2/tools/Server.java
浏览文件 @
a55cd699
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
*/
*/
package
org
.
h2
.
tools
;
package
org
.
h2
.
tools
;
import
java.io.PrintStream
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
...
@@ -28,47 +29,52 @@ import org.h2.util.StartBrowser;
...
@@ -28,47 +29,52 @@ import org.h2.util.StartBrowser;
*/
*/
public
class
Server
implements
Runnable
,
ShutdownHandler
{
public
class
Server
implements
Runnable
,
ShutdownHandler
{
private
String
name
;
private
Service
service
;
private
Service
service
;
private
static
final
int
EXIT_ERROR
=
1
;
private
static
final
int
EXIT_ERROR
=
1
;
private
Server
web
,
tcp
,
pg
,
ftp
;
private
Server
web
,
tcp
,
pg
,
ftp
;
private
ShutdownHandler
shutdownHandler
;
private
ShutdownHandler
shutdownHandler
;
private
void
showUsage
()
{
private
void
showUsage
(
String
a
,
PrintStream
out
)
{
System
.
out
.
println
(
"java "
+
getClass
().
getName
()
+
" [options]"
);
if
(
a
!=
null
)
{
System
.
out
.
println
(
"By default, -tcp, -web, -browser and -pg are started."
);
out
.
println
(
"Unknown option: "
+
a
);
System
.
out
.
println
(
"Options are case sensitive. Options:"
);
out
.
println
();
System
.
out
.
println
(
"-tcp (start the TCP Server)"
);
}
System
.
out
.
println
(
"-tcpPort <port> (default: "
+
TcpServer
.
DEFAULT_PORT
+
")"
);
out
.
println
(
"java "
+
getClass
().
getName
()
+
" [options]"
);
System
.
out
.
println
(
"-tcpSSL [true|false]"
);
out
.
println
(
"By default, -tcp, -web, -browser and -pg are started."
);
System
.
out
.
println
(
"-tcpAllowOthers [true|false]"
);
out
.
println
(
"Options are case sensitive. Options:"
);
System
.
out
.
println
(
"-tcpPassword {password} (the password for shutting down a TCP Server)"
);
out
.
println
();
System
.
out
.
println
(
"-tcpShutdown {url} (shutdown the TCP Server, URL example: tcp://localhost:9094)"
);
out
.
println
(
"-web (start the Web Server and H2 Console)"
);
System
.
out
.
println
(
"-tcpShutdownForce [true|false] (don't wait for other connections to close)"
);
out
.
println
(
"-webAllowOthers [true|false}"
);
out
.
println
(
"-webPort <port> (default: "
+
Constants
.
DEFAULT_HTTP_PORT
+
")"
);
System
.
out
.
println
(
"-web (start the Web Server)"
);
out
.
println
(
"-webSSL [true|false}"
);
System
.
out
.
println
(
"-webPort <port> (default: "
+
Constants
.
DEFAULT_HTTP_PORT
+
")"
);
out
.
println
();
System
.
out
.
println
(
"-webSSL [true|false}"
);
out
.
println
(
"-browser (start a browser to connect to the H2 Console)"
);
System
.
out
.
println
(
"-webAllowOthers [true|false}"
);
out
.
println
();
System
.
out
.
println
(
"-browser (start a browser)"
);
out
.
println
(
"-tcp (start the TCP Server)"
);
out
.
println
(
"-tcpAllowOthers {true|false}"
);
System
.
out
.
println
(
"-pg (start the PG Server)"
);
out
.
println
(
"-tcpPort <port> (default: "
+
TcpServer
.
DEFAULT_PORT
+
")"
);
System
.
out
.
println
(
"-pgPort <port> (default: "
+
PgServer
.
DEFAULT_PORT
+
")"
);
out
.
println
(
"-tcpSSL {true|false}"
);
System
.
out
.
println
(
"-pgAllowOthers [true|false]"
);
out
.
println
(
"-tcpPassword {password} (the password for shutting down a TCP Server)"
);
out
.
println
(
"-tcpShutdown {url} (shutdown the TCP Server, URL example: tcp://localhost:9094)"
);
System
.
out
.
println
(
"-ftp (start the FTP Server)"
);
out
.
println
(
"-tcpShutdownForce {true|false} (don't wait for other connections to close)"
);
System
.
out
.
println
(
"-ftpPort <port> (default: "
+
Constants
.
DEFAULT_FTP_PORT
+
")"
);
out
.
println
();
System
.
out
.
println
(
"-ftpDir <directory> (default: "
+
FtpServer
.
DEFAULT_ROOT
+
", use jdbc:... to access a database)"
);
out
.
println
(
"-pg (start the PG Server)"
);
System
.
out
.
println
(
"-ftpRead <readUserName> (default: "
+
FtpServer
.
DEFAULT_READ
+
")"
);
out
.
println
(
"-pgAllowOthers {true|false}"
);
System
.
out
.
println
(
"-ftpWrite <writeUserName> (default: "
+
FtpServer
.
DEFAULT_WRITE
+
")"
);
out
.
println
(
"-pgPort <port> (default: "
+
PgServer
.
DEFAULT_PORT
+
")"
);
System
.
out
.
println
(
"-ftpWritePassword <password> (default: "
+
FtpServer
.
DEFAULT_WRITE_PASSWORD
+
")"
);
out
.
println
();
out
.
println
(
"-ftp (start the FTP Server)"
);
System
.
out
.
println
(
"-log [true|false] (for all servers)"
);
out
.
println
(
"-ftpPort <port> (default: "
+
Constants
.
DEFAULT_FTP_PORT
+
")"
);
System
.
out
.
println
(
"-baseDir <directory> (sets the base directory for H2 databases, for all servers)"
);
out
.
println
(
"-ftpDir <directory> (default: "
+
FtpServer
.
DEFAULT_ROOT
+
", use jdbc:... to access a database)"
);
System
.
out
.
println
(
"-ifExists [true|false] (only existing databases may be opened, for all servers)"
);
out
.
println
(
"-ftpRead <readUserName> (default: "
+
FtpServer
.
DEFAULT_READ
+
")"
);
out
.
println
(
"-ftpWrite <writeUserName> (default: "
+
FtpServer
.
DEFAULT_WRITE
+
")"
);
out
.
println
(
"-ftpWritePassword <password> (default: "
+
FtpServer
.
DEFAULT_WRITE_PASSWORD
+
")"
);
out
.
println
();
out
.
println
(
"-log {true|false} (enable or disable logging, for all servers)"
);
out
.
println
(
"-baseDir <directory> (sets the base directory for H2 databases, for all servers)"
);
out
.
println
(
"-ifExists {true|false} (only existing databases may be opened, for all servers)"
);
}
}
p
rivate
Server
()
{
p
ublic
Server
()
{
}
}
/**
/**
...
@@ -80,28 +86,28 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -80,28 +86,28 @@ public class Server implements Runnable, ShutdownHandler {
* The following options are supported:
* The following options are supported:
* <ul>
* <ul>
* <li>-help or -? (print the list of options)
* <li>-help or -? (print the list of options)
* </li><li>-web (start the Web Server
/ H2 Console application
)
* </li><li>-web (start the Web Server
and H2 Console
)
* </li><li>-tcp (start the TCP Server)
* </li><li>-tcp (start the TCP Server)
* </li><li>-tcpShutdown {url} (shutdown the running TCP Server, URL example: tcp://localhost:9094)
* </li><li>-tcpShutdown {url} (shutdown the running TCP Server, URL example: tcp://localhost:9094)
* </li><li>-pg (start the PG Server)
* </li><li>-pg (start the PG Server)
* </li><li>-browser (start a browser and open a page to connect to the Web Server)
* </li><li>-browser (start a browser and open a page to connect to the Web Server)
* </li><li>-log
[true|false]
(enable or disable logging)
* </li><li>-log
{true|false}
(enable or disable logging)
* </li><li>-baseDir {directory} (sets the base directory for database files; not for H2 Console)
* </li><li>-baseDir {directory} (sets the base directory for database files; not for H2 Console)
* </li><li>-ifExists
[true|false]
(only existing databases may be opened)
* </li><li>-ifExists
{true|false}
(only existing databases may be opened)
* </li><li>-ftp (start the FTP Server)
* </li><li>-ftp (start the FTP Server)
* </li></ul>
* </li></ul>
* For each Server,
there are additional options
available:
* For each Server,
additional options are
available:
* <ul>
* <ul>
* <li>-webPort {port} (the port of Web Server, default: 8082)
* <li>-webPort {port} (the port of Web Server, default: 8082)
* </li><li>-webSSL
[true|false]
(if SSL should be used)
* </li><li>-webSSL
{true|false}
(if SSL should be used)
* </li><li>-webAllowOthers
[true|false]
(enable/disable remote connections)
* </li><li>-webAllowOthers
{true|false}
(enable/disable remote connections)
* </li><li>-tcpPort {port} (the port of TCP Server, default: 9092)
* </li><li>-tcpPort {port} (the port of TCP Server, default: 9092)
* </li><li>-tcpSSL
[true|false]
(if SSL should be used)
* </li><li>-tcpSSL
{true|false}
(if SSL should be used)
* </li><li>-tcpAllowOthers
[true|false]
(enable/disable remote connections)
* </li><li>-tcpAllowOthers
{true|false}
(enable/disable remote connections)
* </li><li>-tcpPassword {password} (the password for shutting down a TCP Server)
* </li><li>-tcpPassword {password} (the password for shutting down a TCP Server)
* </li><li>-tcpShutdownForce
[true|false]
(don't wait for other connections to close)
* </li><li>-tcpShutdownForce
{true|false}
(don't wait for other connections to close)
* </li><li>-pgPort {port} (the port of PG Server, default: 5435)
* </li><li>-pgPort {port} (the port of PG Server, default: 5435)
* </li><li>-pgAllowOthers
[true|false]
(enable/disable remote connections)
* </li><li>-pgAllowOthers
{true|false}
(enable/disable remote connections)
* </li><li>-ftpPort {port}
* </li><li>-ftpPort {port}
* </li><li>-ftpDir {directory}
* </li><li>-ftpDir {directory}
* </li><li>-ftpRead {readUserName}
* </li><li>-ftpRead {readUserName}
...
@@ -113,13 +119,16 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -113,13 +119,16 @@ public class Server implements Runnable, ShutdownHandler {
* @throws SQLException
* @throws SQLException
*/
*/
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
int
exitCode
=
new
Server
().
run
(
args
);
int
exitCode
=
new
Server
().
run
(
args
,
System
.
out
);
if
(
exitCode
!=
0
)
{
if
(
exitCode
!=
0
)
{
System
.
exit
(
exitCode
);
System
.
exit
(
exitCode
);
}
}
}
}
private
int
run
(
String
[]
args
)
throws
SQLException
{
/**
* INTERNAL
*/
public
int
run
(
String
[]
args
,
PrintStream
out
)
throws
SQLException
{
boolean
tcpStart
=
false
,
pgStart
=
false
,
webStart
=
false
,
ftpStart
=
false
;
boolean
tcpStart
=
false
,
pgStart
=
false
,
webStart
=
false
,
ftpStart
=
false
;
boolean
browserStart
=
false
;
boolean
browserStart
=
false
;
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
...
@@ -128,34 +137,90 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -128,34 +137,90 @@ public class Server implements Runnable, ShutdownHandler {
boolean
startDefaultServers
=
true
;
boolean
startDefaultServers
=
true
;
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
String
a
=
args
[
i
];
String
a
=
args
[
i
];
if
(
"-?"
.
equals
(
a
)
||
"-help"
.
equals
(
a
))
{
if
(
a
==
null
)
{
showUsage
();
continue
;
}
else
if
(
"-?"
.
equals
(
a
)
||
"-help"
.
equals
(
a
))
{
showUsage
(
null
,
out
);
return
EXIT_ERROR
;
return
EXIT_ERROR
;
}
else
if
(
"-web"
.
equals
(
a
))
{
}
else
if
(
a
.
startsWith
(
"-web"
))
{
startDefaultServers
=
false
;
if
(
"-web"
.
equals
(
a
))
{
webStart
=
true
;
startDefaultServers
=
false
;
}
else
if
(
"-tcp"
.
equals
(
a
))
{
webStart
=
true
;
startDefaultServers
=
false
;
}
else
if
(
"-webAllowOthers"
.
equals
(
a
))
{
tcpStart
=
true
;
i
++;
}
else
if
(
"-pg"
.
equals
(
a
))
{
}
else
if
(
"-webPort"
.
equals
(
a
))
{
startDefaultServers
=
false
;
i
++;
pgStart
=
true
;
}
else
if
(
"-webSSL"
.
equals
(
a
))
{
}
else
if
(
"-ftp"
.
equals
(
a
))
{
i
++;
startDefaultServers
=
false
;
}
else
{
ftpStart
=
true
;
showUsage
(
a
,
out
);
}
else
if
(
"-tcpShutdown"
.
equals
(
a
))
{
return
EXIT_ERROR
;
startDefaultServers
=
false
;
}
tcpShutdown
=
true
;
tcpShutdownServer
=
args
[++
i
];
}
else
if
(
"-tcpPassword"
.
equals
(
a
))
{
tcpPassword
=
args
[++
i
];
}
else
if
(
"-tcpShutdownForce"
.
equals
(
a
))
{
tcpShutdownForce
=
true
;
}
else
if
(
"-browser"
.
equals
(
a
))
{
}
else
if
(
"-browser"
.
equals
(
a
))
{
startDefaultServers
=
false
;
startDefaultServers
=
false
;
browserStart
=
true
;
browserStart
=
true
;
}
else
if
(
a
.
startsWith
(
"-tcp"
))
{
if
(
"-tcp"
.
equals
(
a
))
{
startDefaultServers
=
false
;
tcpStart
=
true
;
}
else
if
(
"-tcpAllowOthers"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-tcpPort"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-tcpSSL"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-tcpPassword"
.
equals
(
a
))
{
tcpPassword
=
args
[++
i
];
}
else
if
(
"-tcpShutdown"
.
equals
(
a
))
{
startDefaultServers
=
false
;
tcpShutdown
=
true
;
tcpShutdownServer
=
args
[++
i
];
}
else
if
(
"-tcpShutdownForce"
.
equals
(
a
))
{
tcpShutdownForce
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
{
showUsage
(
a
,
out
);
return
EXIT_ERROR
;
}
}
else
if
(
a
.
startsWith
(
"-pg"
))
{
if
(
"-pg"
.
equals
(
a
))
{
startDefaultServers
=
false
;
pgStart
=
true
;
}
else
if
(
"-pgAllowOthers"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-pgPort"
.
equals
(
a
))
{
i
++;
}
else
{
showUsage
(
a
,
out
);
return
EXIT_ERROR
;
}
}
else
if
(
a
.
startsWith
(
"-ftp"
))
{
if
(
"-ftp"
.
equals
(
a
))
{
startDefaultServers
=
false
;
ftpStart
=
true
;
}
else
if
(
"-ftpPort"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-ftpDir"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-ftpRead"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-ftpWrite"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-ftpWritePassword"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-ftpTask"
.
equals
(
a
))
{
i
++;
}
else
{
showUsage
(
a
,
out
);
return
EXIT_ERROR
;
}
}
else
if
(
a
.
startsWith
(
"-log"
))
{
i
++;
}
else
if
(
"-baseDir"
.
equals
(
a
))
{
i
++;
}
else
if
(
"-ifExists"
.
equals
(
a
))
{
i
++;
}
else
{
}
else
{
showUsage
();
showUsage
(
a
,
out
);
return
EXIT_ERROR
;
return
EXIT_ERROR
;
}
}
}
}
...
@@ -168,7 +233,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -168,7 +233,7 @@ public class Server implements Runnable, ShutdownHandler {
}
}
// TODO server: maybe use one single properties file?
// TODO server: maybe use one single properties file?
if
(
tcpShutdown
)
{
if
(
tcpShutdown
)
{
System
.
out
.
println
(
"Shutting down TCP Server at "
+
tcpShutdownServer
);
out
.
println
(
"Shutting down TCP Server at "
+
tcpShutdownServer
);
shutdownTcpServer
(
tcpShutdownServer
,
tcpPassword
,
tcpShutdownForce
);
shutdownTcpServer
(
tcpShutdownServer
,
tcpPassword
,
tcpShutdownForce
);
}
}
if
(
tcpStart
)
{
if
(
tcpStart
)
{
...
@@ -180,7 +245,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -180,7 +245,7 @@ public class Server implements Runnable, ShutdownHandler {
e
.
printStackTrace
();
e
.
printStackTrace
();
exitCode
=
EXIT_ERROR
;
exitCode
=
EXIT_ERROR
;
}
}
System
.
out
.
println
(
tcp
.
getStatus
());
out
.
println
(
tcp
.
getStatus
());
}
}
if
(
pgStart
)
{
if
(
pgStart
)
{
pg
=
createPgServer
(
args
);
pg
=
createPgServer
(
args
);
...
@@ -191,7 +256,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -191,7 +256,7 @@ public class Server implements Runnable, ShutdownHandler {
e
.
printStackTrace
();
e
.
printStackTrace
();
exitCode
=
EXIT_ERROR
;
exitCode
=
EXIT_ERROR
;
}
}
System
.
out
.
println
(
pg
.
getStatus
());
out
.
println
(
pg
.
getStatus
());
}
}
if
(
webStart
)
{
if
(
webStart
)
{
web
=
createWebServer
(
args
);
web
=
createWebServer
(
args
);
...
@@ -203,7 +268,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -203,7 +268,7 @@ public class Server implements Runnable, ShutdownHandler {
e
.
printStackTrace
();
e
.
printStackTrace
();
exitCode
=
EXIT_ERROR
;
exitCode
=
EXIT_ERROR
;
}
}
System
.
out
.
println
(
web
.
getStatus
());
out
.
println
(
web
.
getStatus
());
// start browser anyway (even if the server is already running)
// start browser anyway (even if the server is already running)
// because some people don't look at the output,
// because some people don't look at the output,
// but are wondering why nothing happens
// but are wondering why nothing happens
...
@@ -220,7 +285,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -220,7 +285,7 @@ public class Server implements Runnable, ShutdownHandler {
e
.
printStackTrace
();
e
.
printStackTrace
();
exitCode
=
EXIT_ERROR
;
exitCode
=
EXIT_ERROR
;
}
}
System
.
out
.
println
(
ftp
.
getStatus
());
out
.
println
(
ftp
.
getStatus
());
}
}
return
exitCode
;
return
exitCode
;
}
}
...
@@ -317,7 +382,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -317,7 +382,7 @@ public class Server implements Runnable, ShutdownHandler {
*/
*/
public
static
Server
createWebServer
(
String
[]
args
)
throws
SQLException
{
public
static
Server
createWebServer
(
String
[]
args
)
throws
SQLException
{
WebServer
service
=
new
WebServer
();
WebServer
service
=
new
WebServer
();
Server
server
=
new
Server
(
"H2 Console Server"
,
service
,
args
);
Server
server
=
new
Server
(
service
,
args
);
service
.
setShutdownHandler
(
server
);
service
.
setShutdownHandler
(
server
);
return
server
;
return
server
;
}
}
...
@@ -331,7 +396,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -331,7 +396,7 @@ public class Server implements Runnable, ShutdownHandler {
* @return the server
* @return the server
*/
*/
public
static
Server
createFtpServer
(
String
[]
args
)
throws
SQLException
{
public
static
Server
createFtpServer
(
String
[]
args
)
throws
SQLException
{
return
new
Server
(
"H2 FTP Server"
,
new
FtpServer
(),
args
);
return
new
Server
(
new
FtpServer
(),
args
);
}
}
/**
/**
...
@@ -343,7 +408,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -343,7 +408,7 @@ public class Server implements Runnable, ShutdownHandler {
* @return the server
* @return the server
*/
*/
public
static
Server
createTcpServer
(
String
[]
args
)
throws
SQLException
{
public
static
Server
createTcpServer
(
String
[]
args
)
throws
SQLException
{
return
new
Server
(
"H2 TCP Server"
,
new
TcpServer
(),
args
);
return
new
Server
(
new
TcpServer
(),
args
);
}
}
/**
/**
...
@@ -355,7 +420,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -355,7 +420,7 @@ public class Server implements Runnable, ShutdownHandler {
* @return the server
* @return the server
*/
*/
public
static
Server
createPgServer
(
String
[]
args
)
throws
SQLException
{
public
static
Server
createPgServer
(
String
[]
args
)
throws
SQLException
{
return
new
Server
(
"H2 PG Server"
,
new
PgServer
(),
args
);
return
new
Server
(
new
PgServer
(),
args
);
}
}
/**
/**
...
@@ -366,7 +431,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -366,7 +431,7 @@ public class Server implements Runnable, ShutdownHandler {
public
Server
start
()
throws
SQLException
{
public
Server
start
()
throws
SQLException
{
service
.
start
();
service
.
start
();
Thread
t
=
new
Thread
(
this
);
Thread
t
=
new
Thread
(
this
);
t
.
setName
(
name
+
" ("
+
service
.
getURL
()
+
")"
);
t
.
setName
(
service
.
getName
()
+
" ("
+
service
.
getURL
()
+
")"
);
t
.
start
();
t
.
start
();
for
(
int
i
=
1
;
i
<
64
;
i
+=
i
)
{
for
(
int
i
=
1
;
i
<
64
;
i
+=
i
)
{
wait
(
i
);
wait
(
i
);
...
@@ -430,8 +495,7 @@ public class Server implements Runnable, ShutdownHandler {
...
@@ -430,8 +495,7 @@ public class Server implements Runnable, ShutdownHandler {
return
service
.
getURL
();
return
service
.
getURL
();
}
}
private
Server
(
String
name
,
Service
service
,
String
[]
args
)
throws
SQLException
{
private
Server
(
Service
service
,
String
[]
args
)
throws
SQLException
{
this
.
name
=
name
;
this
.
service
=
service
;
this
.
service
=
service
;
try
{
try
{
service
.
init
(
args
);
service
.
init
(
args
);
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
a55cd699
...
@@ -150,6 +150,13 @@ java org.h2.test.TestAll timer
...
@@ -150,6 +150,13 @@ java org.h2.test.TestAll timer
/*
/*
write more tests for the command line tools
Changelog:
Certain setting in the Server didn't work (see bug...)
avoid creating thousands of trace.db files
Known Problems:
Known Problems:
link to history page, bug page
link to history page, bug page
Add a link to the google code bug page
Add a link to the google code bug page
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
a55cd699
...
@@ -4,7 +4,9 @@
...
@@ -4,7 +4,9 @@
*/
*/
package
org
.
h2
.
test
.
unit
;
package
org
.
h2
.
test
.
unit
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.PrintStream
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
...
@@ -28,6 +30,7 @@ public class TestTools extends TestBase {
...
@@ -28,6 +30,7 @@ public class TestTools extends TestBase {
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
deleteDb
(
"utils"
);
deleteDb
(
"utils"
);
testServerMain
();
testRemove
();
testRemove
();
testConvertTraceFile
();
testConvertTraceFile
();
testManagementDb
();
testManagementDb
();
...
@@ -39,6 +42,51 @@ public class TestTools extends TestBase {
...
@@ -39,6 +42,51 @@ public class TestTools extends TestBase {
testRecover
();
testRecover
();
}
}
private
void
testServerMain
()
throws
Exception
{
String
result
;
Connection
conn
;
org
.
h2
.
Driver
.
load
();
result
=
runServer
(
new
String
[]{
"-?"
},
1
);
check
(
result
.
indexOf
(
"[options]"
)
>=
0
);
check
(
result
.
indexOf
(
"Unknown option"
)
<
0
);
result
=
runServer
(
new
String
[]{
"-xy"
},
1
);
check
(
result
.
indexOf
(
"[options]"
)
>=
0
);
check
(
result
.
indexOf
(
"Unknown option"
)
>=
0
);
result
=
runServer
(
new
String
[]{
"-tcp"
,
"-tcpAllowOthers"
,
"false"
,
"-tcpPort"
,
"9001"
,
"-tcpPassword"
,
"abc"
},
0
);
check
(
result
.
indexOf
(
"tcp://"
)
>=
0
);
check
(
result
.
indexOf
(
":9001"
)
>=
0
);
check
(
result
.
indexOf
(
"only local"
)
>=
0
);
check
(
result
.
indexOf
(
"[options]"
)
<
0
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:9001/mem:"
,
"sa"
,
"sa"
);
conn
.
close
();
result
=
runServer
(
new
String
[]{
"-tcpShutdown"
,
"tcp://localhost:9001"
,
"-tcpPassword"
,
"abc"
,
"-tcpShutdownForce"
,
"true"
},
0
);
check
(
result
.
indexOf
(
"Shutting down"
)
>=
0
);
result
=
runServer
(
new
String
[]{
"-tcp"
,
"-tcpAllowOthers"
,
"true"
,
"-tcpPort"
,
"9001"
,
"-tcpPassword"
,
"def"
,
"-tcpSSL"
,
"true"
},
0
);
check
(
result
.
indexOf
(
"ssl://"
)
>=
0
);
check
(
result
.
indexOf
(
":9001"
)
>=
0
);
check
(
result
.
indexOf
(
"others can"
)
>=
0
);
check
(
result
.
indexOf
(
"[options]"
)
<
0
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:ssl://localhost:9001/mem:"
,
"sa"
,
"sa"
);
conn
.
close
();
result
=
runServer
(
new
String
[]{
"-tcpShutdown"
,
"ssl://localhost:9001"
,
"-tcpPassword"
,
"def"
,
"-tcpShutdownForce"
,
"false"
},
0
);
check
(
result
.
indexOf
(
"Shutting down"
)
>=
0
);
}
private
String
runServer
(
String
[]
args
,
int
exitCode
)
throws
Exception
{
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
PrintStream
ps
=
new
PrintStream
(
buff
);
int
gotCode
=
new
Server
().
run
(
args
,
ps
);
check
(
exitCode
,
gotCode
);
ps
.
flush
();
String
s
=
new
String
(
buff
.
toByteArray
());
return
s
;
}
private
void
testConvertTraceFile
()
throws
Exception
{
private
void
testConvertTraceFile
()
throws
Exception
{
deleteDb
(
"toolsConvertTraceFile"
);
deleteDb
(
"toolsConvertTraceFile"
);
Class
.
forName
(
"org.h2.Driver"
);
Class
.
forName
(
"org.h2.Driver"
);
...
@@ -213,7 +261,6 @@ public class TestTools extends TestBase {
...
@@ -213,7 +261,6 @@ public class TestTools extends TestBase {
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
.
close
();
conn
.
close
();
server
.
stop
();
server
.
stop
();
server
=
Server
.
createTcpServer
(
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
new
String
[]
{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
try
{
try
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论