Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
11eed7a3
提交
11eed7a3
authored
5月 31, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid using DriverManager
上级
4cbda601
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
30 行删除
+29
-30
TestCluster.java
h2/src/test/org/h2/test/db/TestCluster.java
+25
-26
TestReadOnly.java
h2/src/test/org/h2/test/db/TestReadOnly.java
+4
-4
没有找到文件。
h2/src/test/org/h2/test/db/TestCluster.java
浏览文件 @
11eed7a3
...
...
@@ -7,7 +7,6 @@
package
org
.
h2
.
test
.
db
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
...
...
@@ -58,23 +57,23 @@ public class TestCluster extends TestBase {
Connection
conn
;
Statement
stat
;
String
url1
=
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
;
String
url1
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
,
false
)
;
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
conn
=
DriverManager
.
getConnection
(
url1
,
user
,
password
);
conn
=
getConnection
(
url1
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table t1(id int, name clob)"
);
stat
.
execute
(
"insert into t1 values(1, repeat('Hello', 50))"
);
conn
.
close
();
String
url2
=
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
;
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
false
)
;
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
String
urlCluster
=
"jdbc:h2:tcp://"
+
serverList
+
"/test"
;
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
conn
=
DriverManager
.
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
conn
.
close
();
n1
.
stop
();
...
...
@@ -108,7 +107,7 @@ public class TestCluster extends TestBase {
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
conn
=
DriverManager
.
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table t1(id int, name varchar(30))"
);
stat
.
execute
(
"insert into t1 values(1, 'a'), (2, 'b'), (3, 'c')"
);
...
...
@@ -130,7 +129,7 @@ public class TestCluster extends TestBase {
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"select count(*) from t1"
);
rs
.
next
();
...
...
@@ -166,7 +165,7 @@ public class TestCluster extends TestBase {
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
conn
=
DriverManager
.
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
stat
=
conn
.
createStatement
();
assertTrue
(
conn
.
getAutoCommit
());
stat
.
execute
(
"create table test(id int, name varchar)"
);
...
...
@@ -211,7 +210,7 @@ public class TestCluster extends TestBase {
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
conn
=
DriverManager
.
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
stat
=
conn
.
createStatement
();
assertTrue
(
conn
.
getAutoCommit
());
stat
.
execute
(
"create table test(name int)"
);
...
...
@@ -230,7 +229,7 @@ public class TestCluster extends TestBase {
// stop server 2, and test if only one server is available
n2
.
stop
();
conn
=
DriverManager
.
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"select * from test"
);
assertTrue
(
rs
.
next
());
...
...
@@ -252,14 +251,14 @@ public class TestCluster extends TestBase {
String
user
=
getUser
(),
password
=
getPassword
();
Connection
conn
;
Statement
stat
;
String
url1
=
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
;
String
url2
=
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
;
String
urlCluster
=
"jdbc:h2:tcp://"
+
serverList
+
"/test"
;
String
url1
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
,
false
)
;
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
false
)
;
String
urlCluster
=
getURL
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
false
)
;
int
len
=
10
;
// initialize the database
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
conn
=
DriverManager
.
getConnection
(
url1
,
user
,
password
);
conn
=
getConnection
(
url1
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar) as "
+
"select x, 'Data' || x from system_range(0, "
+
(
len
-
1
)
+
")"
);
...
...
@@ -279,7 +278,7 @@ public class TestCluster extends TestBase {
JdbcUtils
.
closeSilently
(
conn
);
// test the cluster connection
Connection
connApp
=
DriverManager
.
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user
,
password
);
Connection
connApp
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user
,
password
);
check
(
connApp
,
len
,
"'"
+
serverList
+
"'"
);
// delete the rows, but don't commit
...
...
@@ -306,18 +305,18 @@ public class TestCluster extends TestBase {
// test a non-admin user
String
user2
=
"test"
,
password2
=
getPassword
(
"test"
);
connApp
=
DriverManager
.
getConnection
(
urlCluster
,
user2
,
password2
);
connApp
=
getConnection
(
urlCluster
,
user2
,
password2
);
check
(
connApp
,
len
,
"'"
+
serverList
+
"'"
);
connApp
.
close
();
n1
.
stop
();
// test non-admin cluster connection if only one server runs
Connection
connApp2
=
DriverManager
.
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
Connection
connApp2
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
check
(
connApp2
,
len
,
"''"
);
connApp2
.
close
();
// test non-admin cluster connection if only one server runs
connApp2
=
DriverManager
.
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
connApp2
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
check
(
connApp2
,
len
,
"''"
);
connApp2
.
close
();
...
...
@@ -340,7 +339,7 @@ public class TestCluster extends TestBase {
String
urlNode1
=
getURL
(
"node1/test"
,
true
);
String
urlNode2
=
getURL
(
"node2/test"
,
true
);
String
user
=
getUser
(),
password
=
getPassword
();
conn
=
DriverManager
.
getConnection
(
urlNode1
,
user
,
password
);
conn
=
getConnection
(
urlNode1
,
user
,
password
);
Statement
stat
;
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
...
...
@@ -372,21 +371,21 @@ public class TestCluster extends TestBase {
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
user
,
password
);
// test a cluster connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
check
(
conn
,
len
,
"'"
+
serverList
+
"'"
);
conn
.
close
();
// stop server 2, and test if only one server is available
n2
.
stop
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
conn
.
close
();
// disable the cluster
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
conn
.
close
();
n1
.
stop
();
...
...
@@ -398,7 +397,7 @@ public class TestCluster extends TestBase {
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE BOTH(ID INT)"
);
...
...
@@ -409,13 +408,13 @@ public class TestCluster extends TestBase {
n2
.
stop
();
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
conn
.
close
();
n1
.
stop
();
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test;CLUSTER=''"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test;CLUSTER=''"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
conn
.
createStatement
().
execute
(
"SELECT * FROM A"
);
conn
.
close
();
...
...
h2/src/test/org/h2/test/db/TestReadOnly.java
浏览文件 @
11eed7a3
...
...
@@ -9,11 +9,11 @@ package org.h2.test.db;
import
java.io.File
;
import
java.io.RandomAccessFile
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
org.h2.constant.ErrorCode
;
import
org.h2.dev.fs.FilePathZip2
;
import
org.h2.store.FileLister
;
...
...
@@ -63,20 +63,20 @@ public class TestReadOnly extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)"
);
conn
.
close
();
Backup
.
execute
(
dir
+
"/readonly.zip"
,
dir
,
"readonly"
,
true
);
conn
=
DriverManager
.
getConnection
(
conn
=
getConnection
(
"jdbc:h2:zip:"
+
dir
+
"/readonly.zip!/readonly"
,
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
close
();
Server
server
=
Server
.
createTcpServer
(
"-tcpPort"
,
"9081"
,
"-baseDir"
,
dir
);
server
.
start
();
try
{
conn
=
DriverManager
.
getConnection
(
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonly"
,
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
close
();
FilePathZip2
.
register
();
conn
=
DriverManager
.
getConnection
(
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonly"
,
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论