Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d8542d7b
提交
d8542d7b
authored
16 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow remote connections but only allow to open this database
上级
f9b48da1
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
47 行增加
和
14 行删除
+47
-14
ConnectionInfo.java
h2/src/main/org/h2/engine/ConnectionInfo.java
+4
-4
Constants.java
h2/src/main/org/h2/engine/Constants.java
+7
-2
Database.java
h2/src/main/org/h2/engine/Database.java
+6
-3
JdbcConnection.java
h2/src/main/org/h2/jdbc/JdbcConnection.java
+3
-3
TcpServer.java
h2/src/main/org/h2/server/TcpServer.java
+24
-0
TcpServerThread.java
h2/src/main/org/h2/server/TcpServerThread.java
+3
-2
没有找到文件。
h2/src/main/org/h2/engine/ConnectionInfo.java
浏览文件 @
d8542d7b
...
...
@@ -511,14 +511,14 @@ public class ConnectionInfo implements Cloneable {
}
/**
* Switch to server mode
.
* Switch to server mode
, and set the server name and database key.
*
* @param server
the server
* @param server
Key the server name, '/', and the security key
*/
public
void
setServer
(
String
server
)
{
public
void
setServer
Key
(
String
serverKey
)
{
remote
=
true
;
persistent
=
false
;
name
=
server
+
"/"
+
name
;
this
.
name
=
serverKey
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
d8542d7b
...
...
@@ -117,8 +117,13 @@ public class Constants {
/**
* The minor version of this product.
*/
public
static
final
int
VERSION_MINOR
=
0
;
public
static
final
int
VERSION_MINOR
=
1
;
/**
* The version number (major.minor) of this product.
*/
public
static
final
double
VERSION
=
VERSION_MAJOR
+
VERSION_MINOR
/
10
.;
/**
* If empty b-tree pages are allowed. This is supported for backward
* compatibility.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Database.java
浏览文件 @
d8542d7b
...
...
@@ -527,7 +527,7 @@ public class Database implements DataHandler {
lock
=
new
FileLock
(
traceSystem
,
Constants
.
LOCK_SLEEP
);
lock
.
lock
(
databaseName
+
Constants
.
SUFFIX_LOCK_FILE
,
fileLockMethod
==
FileLock
.
LOCK_SOCKET
);
if
(
autoServerMode
)
{
startServer
();
startServer
(
lock
.
getUniqueId
()
);
}
}
deleteOldTempFiles
();
...
...
@@ -622,8 +622,11 @@ public class Database implements DataHandler {
traceSystem
.
getTrace
(
Trace
.
DATABASE
).
info
(
"opened "
+
databaseName
);
}
private
void
startServer
()
throws
SQLException
{
server
=
Server
.
createTcpServer
(
new
String
[]{
"-tcpPort"
,
"0"
});
private
void
startServer
(
String
key
)
throws
SQLException
{
server
=
Server
.
createTcpServer
(
new
String
[]{
"-tcpPort"
,
"0"
,
"-tcpAllowOthers"
,
"true"
,
"-key"
,
key
,
databaseName
});
server
.
start
();
String
address
=
NetUtils
.
getLocalAddress
()
+
":"
+
server
.
getPort
();
lock
.
addProperty
(
"server"
,
address
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcConnection.java
浏览文件 @
d8542d7b
...
...
@@ -117,9 +117,9 @@ public class JdbcConnection extends TraceObject implements Connection {
int
errorCode
=
e
.
getErrorCode
();
if
(
errorCode
==
ErrorCode
.
DATABASE_ALREADY_OPEN_1
)
{
if
(
autoServerMode
)
{
String
server
=
(
String
)
((
JdbcSQLException
)
e
).
getPayload
();
if
(
server
!=
null
)
{
backup
.
setServer
(
server
);
String
server
Key
=
(
String
)
((
JdbcSQLException
)
e
).
getPayload
();
if
(
server
Key
!=
null
)
{
backup
.
setServer
Key
(
serverKey
);
session
=
new
SessionRemote
().
createSession
(
backup
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/TcpServer.java
浏览文件 @
d8542d7b
...
...
@@ -23,6 +23,7 @@ import java.util.Properties;
import
java.util.Set
;
import
org.h2.Driver
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.message.Message
;
...
...
@@ -72,6 +73,7 @@ public class TcpServer implements Service {
private
String
managementPassword
=
""
;
private
Thread
listenerThread
;
private
int
nextThreadId
;
private
String
key
,
keyDatabase
;
/**
* Get the database name of the management database.
...
...
@@ -169,6 +171,9 @@ public class TcpServer implements Service {
managementPassword
=
args
[++
i
];
}
else
if
(
"-baseDir"
.
equals
(
a
))
{
baseDir
=
args
[++
i
];
}
else
if
(
"-key"
.
equals
(
a
))
{
key
=
args
[++
i
];
keyDatabase
=
args
[++
i
];
}
else
if
(
"-tcpAllowOthers"
.
equals
(
a
))
{
if
(
Tool
.
readArgBoolean
(
args
,
i
)
!=
0
)
{
allowOthers
=
Tool
.
readArgBoolean
(
args
,
i
)
==
1
;
...
...
@@ -448,4 +453,23 @@ public class TcpServer implements Service {
}
}
/**
* If no key is set, return the original database name. If a key is set,
* check if the key matches. If yes, return the correct database name. If
* not, throw an exception.
*
* @param db the key to test (or database name if no key is used)
* @return the database name
* @throws SQLException if a key is set but doesn't match
*/
public
String
checkKeyAndGetDatabaseName
(
String
db
)
throws
SQLException
{
if
(
key
==
null
)
{
return
db
;
}
if
(
key
.
equals
(
db
))
{
return
keyDatabase
;
}
throw
Message
.
getSQLException
(
ErrorCode
.
WRONG_USER_OR_PASSWORD
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/TcpServerThread.java
浏览文件 @
d8542d7b
...
...
@@ -62,8 +62,8 @@ public class TcpServerThread implements Runnable {
try
{
transfer
.
init
();
trace
(
"Connect"
);
// TODO server: should support a list of allowed databases
and a
// list of allowed clients
// TODO server: should support a list of allowed databases
//
and a
list of allowed clients
try
{
clientVersion
=
transfer
.
readInt
();
if
(!
server
.
allow
(
transfer
.
getSocket
()))
{
...
...
@@ -91,6 +91,7 @@ public class TcpServerThread implements Runnable {
if
(
baseDir
==
null
)
{
baseDir
=
SysProperties
.
getBaseDir
();
}
db
=
server
.
checkKeyAndGetDatabaseName
(
db
);
ConnectionInfo
ci
=
new
ConnectionInfo
(
db
);
if
(
baseDir
!=
null
)
{
ci
.
setBaseDir
(
baseDir
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论