Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0324fd77
提交
0324fd77
authored
6月 01, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test
上级
344f2633
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
24 行删除
+25
-24
TestReadOnly.java
h2/src/test/org/h2/test/db/TestReadOnly.java
+25
-24
没有找到文件。
h2/src/test/org/h2/test/db/TestReadOnly.java
浏览文件 @
0324fd77
...
@@ -49,63 +49,64 @@ public class TestReadOnly extends TestBase {
...
@@ -49,63 +49,64 @@ public class TestReadOnly extends TestBase {
testReadOnlyFiles
(
true
);
testReadOnlyFiles
(
true
);
}
}
testReadOnlyFiles
(
false
);
testReadOnlyFiles
(
false
);
deleteDb
(
"readonly"
);
}
}
private
void
testReadOnlyInZip
()
throws
SQLException
{
private
void
testReadOnlyInZip
()
throws
SQLException
{
if
(
config
.
cipher
!=
null
)
{
if
(
config
.
cipher
!=
null
)
{
return
;
return
;
}
}
deleteDb
(
"readonly"
);
deleteDb
(
"readonly
InZip
"
);
String
dir
=
getBaseDir
();
String
dir
=
getBaseDir
();
Connection
conn
=
getConnection
(
"readonly"
);
Connection
conn
=
getConnection
(
"readonly
InZip
"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)"
);
conn
.
close
();
conn
.
close
();
Backup
.
execute
(
dir
+
"/readonly.zip"
,
dir
,
"readonly"
,
true
);
Backup
.
execute
(
dir
+
"/readonly.zip"
,
dir
,
"readonly
InZip
"
,
true
);
conn
=
getConnection
(
conn
=
getConnection
(
"jdbc:h2:zip:"
+
dir
+
"/readonly.zip!/readonly"
,
getUser
(),
getPassword
());
"jdbc:h2:zip:"
+
dir
+
"/readonly.zip!/readonly
InZip
"
,
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
close
();
conn
.
close
();
Server
server
=
Server
.
createTcpServer
(
"-tcpPort"
,
"9081"
,
"-baseDir"
,
dir
);
Server
server
=
Server
.
createTcpServer
(
"-tcpPort"
,
"9081"
,
"-baseDir"
,
dir
);
server
.
start
();
server
.
start
();
try
{
try
{
conn
=
getConnection
(
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonly"
,
"jdbc:h2:tcp://localhost:9081/zip:readonly.zip!/readonly
InZip
"
,
getUser
(),
getPassword
());
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
close
();
conn
.
close
();
FilePathZip2
.
register
();
FilePathZip2
.
register
();
conn
=
getConnection
(
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonly"
,
"jdbc:h2:tcp://localhost:9081/zip2:readonly.zip!/readonly
InZip
"
,
getUser
(),
getPassword
());
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
createStatement
().
execute
(
"select * from test where id=1"
);
conn
.
close
();
conn
.
close
();
}
finally
{
}
finally
{
server
.
stop
();
server
.
stop
();
}
}
deleteDb
(
"readonlyInZip"
);
}
}
private
void
testReadOnlyTempTableResult
()
throws
SQLException
{
private
void
testReadOnlyTempTableResult
()
throws
SQLException
{
deleteDb
(
"readonly"
);
deleteDb
(
"readonly
Temp
"
);
Connection
conn
=
getConnection
(
"readonly"
);
Connection
conn
=
getConnection
(
"readonly
Temp
"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT) AS SELECT X FROM SYSTEM_RANGE(1, 20)"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"readonly;ACCESS_MODE_DATA=r;MAX_MEMORY_ROWS_DISTINCT=10"
);
conn
=
getConnection
(
"readonly
Temp
;ACCESS_MODE_DATA=r;MAX_MEMORY_ROWS_DISTINCT=10"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT DISTINCT ID FROM TEST"
);
stat
.
execute
(
"SELECT DISTINCT ID FROM TEST"
);
conn
.
close
();
conn
.
close
();
deleteDb
(
"readonlyTemp"
);
}
}
private
void
testReadOnlyDbCreate
()
throws
SQLException
{
private
void
testReadOnlyDbCreate
()
throws
SQLException
{
deleteDb
(
"readonly"
);
deleteDb
(
"readonly
DbCreate
"
);
Connection
conn
=
getConnection
(
"readonly"
);
Connection
conn
=
getConnection
(
"readonly
DbCreate
"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table a(id int)"
);
stat
.
execute
(
"create table a(id int)"
);
stat
.
execute
(
"create index ai on a(id)"
);
stat
.
execute
(
"create index ai on a(id)"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"read
only
;ACCESS_MODE_DATA=r"
);
conn
=
getConnection
(
"read
OnlyDbCreate
;ACCESS_MODE_DATA=r"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table if not exists a(id int)"
);
stat
.
execute
(
"create table if not exists a(id int)"
);
stat
.
execute
(
"create index if not exists ai on a(id)"
);
stat
.
execute
(
"create index if not exists ai on a(id)"
);
...
@@ -136,8 +137,8 @@ public class TestReadOnly extends TestBase {
...
@@ -136,8 +137,8 @@ public class TestReadOnly extends TestBase {
assertTrue
(!
f
.
canWrite
());
assertTrue
(!
f
.
canWrite
());
f
.
delete
();
f
.
delete
();
deleteDb
(
"readonly"
);
deleteDb
(
"readonly
Files
"
);
Connection
conn
=
getConnection
(
"readonly"
);
Connection
conn
=
getConnection
(
"readonly
Files
"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
...
@@ -147,9 +148,9 @@ public class TestReadOnly extends TestBase {
...
@@ -147,9 +148,9 @@ public class TestReadOnly extends TestBase {
if
(
setReadOnly
)
{
if
(
setReadOnly
)
{
setReadOnly
();
setReadOnly
();
conn
=
getConnection
(
"readonly"
);
conn
=
getConnection
(
"readonly
Files
"
);
}
else
{
}
else
{
conn
=
getConnection
(
"readonly;ACCESS_MODE_DATA=r"
);
conn
=
getConnection
(
"readonly
Files
;ACCESS_MODE_DATA=r"
);
}
}
assertTrue
(
conn
.
isReadOnly
());
assertTrue
(
conn
.
isReadOnly
());
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
...
@@ -159,9 +160,9 @@ public class TestReadOnly extends TestBase {
...
@@ -159,9 +160,9 @@ public class TestReadOnly extends TestBase {
conn
.
close
();
conn
.
close
();
if
(
setReadOnly
)
{
if
(
setReadOnly
)
{
conn
=
getConnection
(
"readonly;DB_CLOSE_DELAY=1"
);
conn
=
getConnection
(
"readonly
Files
;DB_CLOSE_DELAY=1"
);
}
else
{
}
else
{
conn
=
getConnection
(
"readonly;DB_CLOSE_DELAY=1;ACCESS_MODE_DATA=r"
);
conn
=
getConnection
(
"readonly
Files
;DB_CLOSE_DELAY=1;ACCESS_MODE_DATA=r"
);
}
}
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM TEST"
);
stat
.
execute
(
"SELECT * FROM TEST"
);
...
@@ -172,22 +173,22 @@ public class TestReadOnly extends TestBase {
...
@@ -172,22 +173,22 @@ public class TestReadOnly extends TestBase {
}
}
private
void
setReadOnly
()
{
private
void
setReadOnly
()
{
ArrayList
<
String
>
list
=
FileLister
.
getDatabaseFiles
(
getBaseDir
(),
"readonly"
,
true
);
ArrayList
<
String
>
list
=
FileLister
.
getDatabaseFiles
(
getBaseDir
(),
"readonly
Files
"
,
true
);
for
(
String
fileName
:
list
)
{
for
(
String
fileName
:
list
)
{
FileUtils
.
setReadOnly
(
fileName
);
FileUtils
.
setReadOnly
(
fileName
);
}
}
}
}
private
void
testReadOnlyConnect
()
throws
SQLException
{
private
void
testReadOnlyConnect
()
throws
SQLException
{
deleteDb
(
"readonly"
);
deleteDb
(
"readonly
Connect
"
);
Connection
conn
=
getConnection
(
"readonly;OPEN_NEW=TRUE"
);
Connection
conn
=
getConnection
(
"readonly
Connect
;OPEN_NEW=TRUE"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity)"
);
stat
.
execute
(
"create table test(id identity)"
);
stat
.
execute
(
"insert into test select x from system_range(1, 11)"
);
stat
.
execute
(
"insert into test select x from system_range(1, 11)"
);
assertThrows
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
this
).
assertThrows
(
ErrorCode
.
DATABASE_ALREADY_OPEN_1
,
this
).
getConnection
(
"readonly;ACCESS_MODE_DATA=r;OPEN_NEW=TRUE"
);
getConnection
(
"readonly
Connect
;ACCESS_MODE_DATA=r;OPEN_NEW=TRUE"
);
conn
.
close
();
conn
.
close
();
deleteDb
(
"readonly"
);
deleteDb
(
"readonly
Connect
"
);
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论