Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d28d8c3a
提交
d28d8c3a
authored
7月 13, 2017
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue#556 close connections in tests (at least in case of successful execution)
上级
1a04f20c
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
446 行增加
和
441 行删除
+446
-441
TestFullText.java
h2/src/test/org/h2/test/db/TestFullText.java
+4
-6
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+18
-15
TestMultiThread.java
h2/src/test/org/h2/test/db/TestMultiThread.java
+244
-251
TestQueryCache.java
h2/src/test/org/h2/test/db/TestQueryCache.java
+62
-62
TestShow.java
h2/src/test/org/h2/test/db/TestShow.java
+24
-22
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+88
-85
TestConnection.java
h2/src/test/org/h2/test/jdbc/TestConnection.java
+6
-0
没有找到文件。
h2/src/test/org/h2/test/db/TestFullText.java
浏览文件 @
d28d8c3a
...
...
@@ -92,7 +92,7 @@ public class TestFullText extends TestBase {
private
static
void
close
(
Collection
<
Connection
>
list
)
throws
SQLException
{
for
(
Connection
conn
:
list
)
{
conn
.
close
();
try
{
conn
.
close
();
}
catch
(
SQLException
ignore
)
{
/**/
}
}
}
...
...
@@ -491,8 +491,7 @@ public class TestFullText extends TestBase {
return
;
}
deleteDb
(
"fullText"
);
ArrayList
<
Connection
>
connList
=
new
ArrayList
<
Connection
>();
Connection
conn
=
getConnection
(
"fullText"
,
connList
);
Connection
conn
=
getConnection
(
"fullText"
);
String
prefix
=
lucene
?
"FTL_"
:
"FT_"
;
Statement
stat
=
conn
.
createStatement
();
String
className
=
lucene
?
"FullTextLucene"
:
"FullText"
;
...
...
@@ -590,15 +589,15 @@ public class TestFullText extends TestBase {
if
(!
config
.
memory
)
{
conn
.
close
();
conn
=
getConnection
(
"fullText"
);
}
conn
=
getConnection
(
"fullText"
,
connList
);
stat
=
conn
.
createStatement
();
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 0, 0)"
);
stat
.
execute
(
"CALL "
+
prefix
+
"DROP_ALL()"
);
c
lose
(
connList
);
c
onn
.
close
(
);
}
private
void
testDropIndex
(
boolean
lucene
)
throws
SQLException
{
...
...
@@ -625,7 +624,6 @@ public class TestFullText extends TestBase {
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME1, NAME2')"
);
stat
.
execute
(
"UPDATE TEST SET NAME2=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME2='Hello World' WHERE ID=1"
);
conn
.
close
();
conn
.
close
();
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullTextDropIndex"
,
false
);
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
d28d8c3a
...
...
@@ -1285,6 +1285,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
String
.
format
(
"SELECT ORA_HASH('%s', 0) FROM DUAL"
,
testStr
));
assertResult
(
String
.
valueOf
(
"foo"
.
hashCode
()),
stat
,
String
.
format
(
"SELECT ORA_HASH('%s', 0, 0) FROM DUAL"
,
testStr
));
conn
.
close
();
}
private
void
testToDateException
()
{
...
...
@@ -2058,6 +2059,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertFalse
(
parsed
.
before
(
before
));
assertFalse
(
parsed
.
after
(
after
));
conn
.
close
();
}
...
...
@@ -2083,6 +2085,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs
.
close
();
assertEquals
(
first
,
second
);
conn
.
close
();
}
private
void
testThatCurrentTimestampUpdatesOutsideATransaction
()
...
...
@@ -2107,26 +2110,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs
.
close
();
assertTrue
(
second
.
after
(
first
));
conn
.
close
();
}
private
void
callCompiledFunction
(
String
functionName
)
throws
SQLException
{
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
stat
.
execute
(
"create alias "
+
functionName
+
" AS "
+
"$$ boolean "
+
functionName
+
"() "
+
"{ return true; } $$;"
);
PreparedStatement
stmt
=
conn
.
prepareStatement
(
"select "
+
functionName
+
"() from dual"
);
rs
=
stmt
.
executeQuery
();
rs
.
next
();
assertEquals
(
Boolean
.
class
.
getName
(),
rs
.
getObject
(
1
).
getClass
().
getName
());
stat
.
execute
(
"drop alias "
+
functionName
+
""
);
try
(
Connection
conn
=
getConnection
(
"functions"
))
{
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
stat
.
execute
(
"create alias "
+
functionName
+
" AS "
+
"$$ boolean "
+
functionName
+
"() "
+
"{ return true; } $$;"
);
PreparedStatement
stmt
=
conn
.
prepareStatement
(
"select "
+
functionName
+
"() from dual"
);
rs
=
stmt
.
executeQuery
();
rs
.
next
();
assertEquals
(
Boolean
.
class
.
getName
(),
rs
.
getObject
(
1
).
getClass
().
getName
());
conn
.
close
();
stat
.
execute
(
"drop alias "
+
functionName
+
""
);
}
}
private
void
assertCallResult
(
String
expected
,
Statement
stat
,
String
sql
)
...
...
h2/src/test/org/h2/test/db/TestMultiThread.java
浏览文件 @
d28d8c3a
...
...
@@ -38,20 +38,15 @@ public class TestMultiThread extends TestBase implements Runnable {
private
boolean
stop
;
private
TestMultiThread
parent
;
private
Random
random
;
private
Connection
threadConn
;
private
Statement
threadStat
;
public
TestMultiThread
()
{
// nothing to do
}
private
TestMultiThread
(
TestAll
config
,
TestMultiThread
parent
)
throws
SQLException
{
private
TestMultiThread
(
TestAll
config
,
TestMultiThread
parent
)
{
this
.
config
=
config
;
this
.
parent
=
parent
;
random
=
new
Random
();
threadConn
=
getConnection
();
threadStat
=
threadConn
.
createStatement
();
}
/**
...
...
@@ -81,64 +76,64 @@ public class TestMultiThread extends TestBase implements Runnable {
String
db
=
getTestName
();
deleteDb
(
db
);
final
String
url
=
getURL
(
db
+
";MULTI_THREADED=1;LOCK_TIMEOUT=10000"
,
true
);
Connection
conn
=
getConnection
(
url
);
Task
[]
tasks
=
new
Task
[
2
];
for
(
int
i
=
0
;
i
<
tasks
.
length
;
i
++)
{
final
int
x
=
i
;
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
try
(
Connection
c2
=
getConnection
(
url
))
{
Statement
stat
=
c2
.
createStatement
();
for
(
int
i
=
0
;
!
stop
;
i
++)
{
stat
.
execute
(
"create table test"
+
x
+
"_"
+
i
);
c2
.
getMetaData
().
getTables
(
null
,
null
,
null
,
null
);
stat
.
execute
(
"drop table test"
+
x
+
"_"
+
i
);
try
(
Connection
conn
=
getConnection
(
url
))
{
Task
[]
tasks
=
new
Task
[
2
];
for
(
int
i
=
0
;
i
<
tasks
.
length
;
i
++)
{
final
int
x
=
i
;
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
try
(
Connection
c2
=
getConnection
(
url
))
{
Statement
stat
=
c2
.
createStatement
();
for
(
int
i
=
0
;
!
stop
;
i
++)
{
stat
.
execute
(
"create table test"
+
x
+
"_"
+
i
);
c2
.
getMetaData
().
getTables
(
null
,
null
,
null
,
null
);
stat
.
execute
(
"drop table test"
+
x
+
"_"
+
i
);
}
}
}
}
}
;
tasks
[
i
]
=
t
;
t
.
execute
();
}
Thread
.
sleep
(
1000
);
for
(
Task
t
:
tasks
)
{
t
.
get
();
}
;
tasks
[
i
]
=
t
;
t
.
execute
()
;
}
Thread
.
sleep
(
1000
);
for
(
Task
t
:
tasks
)
{
t
.
get
();
}
}
conn
.
close
();
}
private
void
testConcurrentLobAdd
()
throws
Exception
{
String
db
=
getTestName
();
deleteDb
(
db
);
final
String
url
=
getURL
(
db
+
";MULTI_THREADED=1"
,
true
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, data clob)"
);
Task
[]
tasks
=
new
Task
[
2
];
for
(
int
i
=
0
;
i
<
tasks
.
length
;
i
++)
{
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
try
(
Connection
c2
=
getConnection
(
url
))
{
PreparedStatement
p2
=
c2
.
prepareStatement
(
"insert into test(data) values(?)"
);
while
(!
stop
)
{
p2
.
setCharacterStream
(
1
,
new
StringReader
(
new
String
(
new
char
[
10
*
1024
])));
p2
.
execute
();
try
(
Connection
conn
=
getConnection
(
url
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, data clob)"
);
Task
[]
tasks
=
new
Task
[
2
];
for
(
int
i
=
0
;
i
<
tasks
.
length
;
i
++)
{
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
try
(
Connection
c2
=
getConnection
(
url
))
{
PreparedStatement
p2
=
c2
.
prepareStatement
(
"insert into test(data) values(?)"
);
while
(!
stop
)
{
p2
.
setCharacterStream
(
1
,
new
StringReader
(
new
String
(
new
char
[
10
*
1024
])));
p2
.
execute
();
}
}
}
}
}
;
tasks
[
i
]
=
t
;
t
.
execute
();
}
Thread
.
sleep
(
500
);
for
(
Task
t
:
tasks
)
{
t
.
get
();
}
;
tasks
[
i
]
=
t
;
t
.
execute
()
;
}
Thread
.
sleep
(
500
);
for
(
Task
t
:
tasks
)
{
t
.
get
();
}
}
conn
.
close
();
}
private
void
testConcurrentView
()
throws
Exception
{
...
...
@@ -149,60 +144,60 @@ public class TestMultiThread extends TestBase implements Runnable {
deleteDb
(
db
);
final
String
url
=
getURL
(
db
+
";MULTI_THREADED=1"
,
true
);
final
Random
r
=
new
Random
();
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"create table test(id int"
);
final
int
len
=
3
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
", x"
+
i
+
" int"
);
}
buff
.
append
(
")"
);
stat
.
execute
(
buff
.
toString
());
stat
.
execute
(
"create view test_view as select * from test"
);
stat
.
execute
(
"insert into test(id) select x from system_range(1, 2)"
);
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
Connection
c2
=
getConnection
(
url
);
while
(!
stop
)
{
c2
.
prepareStatement
(
"select * from test_view where x"
+
r
.
nextInt
(
len
)
+
"=1"
);
try
(
Connection
conn
=
getConnection
(
url
))
{
Statement
stat
=
conn
.
createStatement
();
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"create table test(id int"
);
final
int
len
=
3
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
", x"
+
i
+
" int"
);
}
buff
.
append
(
")"
);
stat
.
execute
(
buff
.
toString
());
stat
.
execute
(
"create view test_view as select * from test"
);
stat
.
execute
(
"insert into test(id) select x from system_range(1, 2)"
);
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
Connection
c2
=
getConnection
(
url
);
while
(!
stop
)
{
c2
.
prepareStatement
(
"select * from test_view where x"
+
r
.
nextInt
(
len
)
+
"=1"
);
}
c2
.
close
();
}
c2
.
close
();
};
t
.
execute
();
SynchronizedVerifier
.
setDetect
(
SmallLRUCache
.
class
,
true
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
conn
.
prepareStatement
(
"select * from test_view where x"
+
r
.
nextInt
(
len
)
+
"=1"
);
}
};
t
.
execute
();
SynchronizedVerifier
.
setDetect
(
SmallLRUCache
.
class
,
true
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
conn
.
prepareStatement
(
"select * from test_view where x"
+
r
.
nextInt
(
len
)
+
"=1"
);
t
.
get
();
SynchronizedVerifier
.
setDetect
(
SmallLRUCache
.
class
,
false
);
}
t
.
get
();
SynchronizedVerifier
.
setDetect
(
SmallLRUCache
.
class
,
false
);
conn
.
close
();
}
private
void
testConcurrentAlter
()
throws
Exception
{
deleteDb
(
getTestName
());
final
Connection
conn
=
getConnection
(
getTestName
());
Statement
stat
=
conn
.
createStatement
();
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
while
(!
stop
)
{
conn
.
prepareStatement
(
"select * from test"
);
try
(
final
Connection
conn
=
getConnection
(
getTestName
()))
{
Statement
stat
=
conn
.
createStatement
();
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
while
(!
stop
)
{
conn
.
prepareStatement
(
"select * from test"
);
}
}
};
stat
.
execute
(
"create table test(id int)"
);
t
.
execute
();
for
(
int
i
=
0
;
i
<
200
;
i
++)
{
stat
.
execute
(
"alter table test add column x int"
);
stat
.
execute
(
"alter table test drop column x"
);
}
};
stat
.
execute
(
"create table test(id int)"
);
t
.
execute
();
for
(
int
i
=
0
;
i
<
200
;
i
++)
{
stat
.
execute
(
"alter table test add column x int"
);
stat
.
execute
(
"alter table test drop column x"
);
t
.
get
();
}
t
.
get
();
conn
.
close
();
}
private
void
testConcurrentAnalyze
()
throws
Exception
{
...
...
@@ -211,53 +206,52 @@ public class TestMultiThread extends TestBase implements Runnable {
}
deleteDb
(
getTestName
());
final
String
url
=
getURL
(
"concurrentAnalyze;MULTI_THREADED=1"
,
true
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id bigint primary key) "
+
"as select x from system_range(1, 1000)"
);
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
SQLException
{
Connection
conn2
;
conn2
=
getConnection
(
url
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
conn2
.
createStatement
().
execute
(
"analyze"
);
try
(
Connection
conn
=
getConnection
(
url
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id bigint primary key) "
+
"as select x from system_range(1, 1000)"
);
Task
t
=
new
Task
()
{
@Override
public
void
call
()
throws
SQLException
{
try
(
Connection
conn2
=
getConnection
(
url
))
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
conn2
.
createStatement
().
execute
(
"analyze"
);
}
}
}
conn2
.
close
();
};
t
.
execute
();
Thread
.
yield
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
conn
.
createStatement
().
execute
(
"analyze"
);
}
};
t
.
execute
();
Thread
.
yield
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
conn
.
createStatement
().
execute
(
"analyze"
);
}
t
.
get
();
t
.
get
();
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testConcurrentInsertUpdateSelect
()
throws
Exception
{
threadConn
=
getConnection
();
threadStat
=
threadConn
.
createStatement
();
threadStat
.
execute
(
"CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"
);
int
len
=
getSize
(
10
,
200
);
Thread
[]
threads
=
new
Thread
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
threads
[
i
]
=
new
Thread
(
new
TestMultiThread
(
config
,
this
));
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
threads
[
i
].
start
();
}
int
sleep
=
getSize
(
400
,
10000
);
Thread
.
sleep
(
sleep
);
this
.
stop
=
true
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
threads
[
i
].
join
();
try
(
Connection
conn
=
getConnection
())
{
Statement
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"
);
int
len
=
getSize
(
10
,
200
);
Thread
[]
threads
=
new
Thread
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
threads
[
i
]
=
new
Thread
(
new
TestMultiThread
(
config
,
this
));
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
threads
[
i
].
start
();
}
int
sleep
=
getSize
(
400
,
10000
);
Thread
.
sleep
(
sleep
);
this
.
stop
=
true
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
threads
[
i
].
join
();
}
ResultSet
rs
=
stmt
.
executeQuery
(
"SELECT COUNT(*) FROM TEST"
);
rs
.
next
();
trace
(
"max id="
+
rs
.
getInt
(
1
));
}
ResultSet
rs
=
threadStat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST"
);
rs
.
next
();
trace
(
"max id="
+
rs
.
getInt
(
1
));
threadConn
.
close
();
}
private
Connection
getConnection
()
throws
SQLException
{
...
...
@@ -266,22 +260,22 @@ public class TestMultiThread extends TestBase implements Runnable {
@Override
public
void
run
()
{
try
{
try
(
Connection
conn
=
getConnection
())
{
Statement
stmt
=
conn
.
createStatement
();
while
(!
parent
.
stop
)
{
threadSta
t
.
execute
(
"SELECT COUNT(*) FROM TEST"
);
threadSta
t
.
execute
(
"INSERT INTO TEST VALUES(NULL, 'Hi')"
);
PreparedStatement
prep
=
threadC
onn
.
prepareStatement
(
stm
t
.
execute
(
"SELECT COUNT(*) FROM TEST"
);
stm
t
.
execute
(
"INSERT INTO TEST VALUES(NULL, 'Hi')"
);
PreparedStatement
prep
=
c
onn
.
prepareStatement
(
"UPDATE TEST SET NAME='Hello' WHERE ID=?"
);
prep
.
setInt
(
1
,
random
.
nextInt
(
10000
));
prep
.
execute
();
prep
=
threadC
onn
.
prepareStatement
(
"SELECT * FROM TEST WHERE ID=?"
);
prep
=
c
onn
.
prepareStatement
(
"SELECT * FROM TEST WHERE ID=?"
);
prep
.
setInt
(
1
,
random
.
nextInt
(
10000
));
ResultSet
rs
=
prep
.
executeQuery
();
while
(
rs
.
next
())
{
rs
.
getString
(
"NAME"
);
}
}
threadConn
.
close
();
}
catch
(
Exception
e
)
{
logError
(
"multi"
,
e
);
}
...
...
@@ -292,11 +286,11 @@ public class TestMultiThread extends TestBase implements Runnable {
// is not supported
deleteDb
(
"lockMode"
);
final
String
url
=
getURL
(
"lockMode;MULTI_THREADED=1"
,
true
);
Connection
conn
=
getConnection
(
url
);
DatabaseMetaData
meta
=
conn
.
getMetaData
();
assertFalse
(
meta
.
supportsTransactionIsolationLevel
(
Connection
.
TRANSACTION_READ_UNCOMMITTED
));
conn
.
close
();
try
(
Connection
conn
=
getConnection
(
url
))
{
DatabaseMetaData
meta
=
conn
.
getMetaData
();
assertFalse
(
meta
.
supportsTransactionIsolationLevel
(
Connection
.
TRANSACTION_READ_UNCOMMITTED
));
}
deleteDb
(
"lockMode"
);
}
...
...
@@ -307,55 +301,55 @@ public class TestMultiThread extends TestBase implements Runnable {
final
String
url
=
getURL
(
"lockMode;MULTI_THREADED=1"
,
true
);
// create some common tables and views
final
Connection
conn
=
getConnection
(
url
);
final
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE INVOICE(INVOICE_ID INT PRIMARY KEY, AMOUNT DECIMAL)"
);
stat
.
execute
(
"CREATE VIEW INVOICE_VIEW as SELECT * FROM INVOICE"
);
stat
.
execute
(
"CREATE TABLE INVOICE_DETAIL(DETAIL_ID INT PRIMARY KEY, "
+
"INVOICE_ID INT, DESCRIPTION VARCHAR)"
);
stat
.
execute
(
"CREATE VIEW INVOICE_DETAIL_VIEW as SELECT * FROM INVOICE_DETAIL"
);
stat
.
close
();
// create views that reference the common views in different threads
final
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
8
);
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
8
);
Connection
conn
=
getConnection
(
url
);
try
{
final
ArrayList
<
Future
<
Void
>>
jobs
=
new
ArrayList
<
Future
<
Void
>>();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE INVOICE(INVOICE_ID INT PRIMARY KEY, AMOUNT DECIMAL)"
);
stat
.
execute
(
"CREATE VIEW INVOICE_VIEW as SELECT * FROM INVOICE"
);
stat
.
execute
(
"CREATE TABLE INVOICE_DETAIL(DETAIL_ID INT PRIMARY KEY, "
+
"INVOICE_ID INT, DESCRIPTION VARCHAR)"
);
stat
.
execute
(
"CREATE VIEW INVOICE_DETAIL_VIEW as SELECT * FROM INVOICE_DETAIL"
);
stat
.
close
();
// create views that reference the common views in different threads
ArrayList
<
Future
<
Void
>>
jobs
=
new
ArrayList
<
Future
<
Void
>>();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
final
int
j
=
i
;
jobs
.
add
(
executor
.
submit
(
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
Exception
{
final
Connection
conn2
=
getConnection
(
url
);
Statement
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"CREATE VIEW INVOICE_VIEW"
+
j
+
" as SELECT * FROM INVOICE_VIEW"
);
// the following query intermittently results in a
// NullPointerException
stat2
.
execute
(
"CREATE VIEW INVOICE_DETAIL_VIEW"
+
j
+
" as SELECT DTL.* FROM INVOICE_VIEW"
+
j
+
" INV JOIN INVOICE_DETAIL_VIEW DTL "
+
"ON INV.INVOICE_ID = DTL.INVOICE_ID"
+
" WHERE DESCRIPTION='TEST'"
);
ResultSet
rs
=
stat2
.
executeQuery
(
"SELECT * FROM INVOICE_VIEW"
+
j
);
rs
.
next
();
rs
.
close
();
rs
=
stat2
.
executeQuery
(
"SELECT * FROM INVOICE_DETAIL_VIEW"
+
j
);
rs
.
next
();
rs
.
close
();
stat
.
close
();
conn
.
close
();
try
(
Connection
conn2
=
getConnection
(
url
))
{
Statement
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"CREATE VIEW INVOICE_VIEW"
+
j
+
" as SELECT * FROM INVOICE_VIEW"
);
// the following query intermittently results in a
// NullPointerException
stat2
.
execute
(
"CREATE VIEW INVOICE_DETAIL_VIEW"
+
j
+
" as SELECT DTL.* FROM INVOICE_VIEW"
+
j
+
" INV JOIN INVOICE_DETAIL_VIEW DTL "
+
"ON INV.INVOICE_ID = DTL.INVOICE_ID"
+
" WHERE DESCRIPTION='TEST'"
);
ResultSet
rs
=
stat2
.
executeQuery
(
"SELECT * FROM INVOICE_VIEW"
+
j
);
rs
.
next
();
rs
.
close
();
rs
=
stat2
.
executeQuery
(
"SELECT * FROM INVOICE_DETAIL_VIEW"
+
j
);
rs
.
next
();
rs
.
close
();
stat2
.
close
();
}
return
null
;
}
}));
...
...
@@ -388,37 +382,36 @@ public class TestMultiThread extends TestBase implements Runnable {
deleteDb
(
"lockMode"
);
final
String
url
=
getURL
(
"lockMode;MULTI_THREADED=1"
,
true
);
final
Connection
conn
=
getConnection
(
url
);
conn
.
createStatement
().
execute
(
"CREATE TABLE IF NOT EXISTS TRAN (ID NUMBER(18,0) not null PRIMARY KEY)"
);
final
int
threadCount
=
25
;
final
ArrayList
<
Callable
<
Void
>>
callables
=
new
ArrayList
<
Callable
<
Void
>>();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
final
Connection
taskConn
=
getConnection
(
url
);
taskConn
.
setAutoCommit
(
false
);
final
PreparedStatement
insertTranStmt
=
taskConn
.
prepareStatement
(
"INSERT INTO tran (id) values(?)"
);
// to guarantee uniqueness
final
long
initialTransactionId
=
i
*
1000000L
;
callables
.
add
(
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
Exception
{
long
tranId
=
initialTransactionId
;
for
(
int
j
=
0
;
j
<
1000
;
j
++)
{
insertTranStmt
.
setLong
(
1
,
tranId
++);
insertTranStmt
.
execute
();
taskConn
.
commit
();
int
threadCount
=
25
;
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadCount
);
Connection
conn
=
getConnection
(
url
);
try
{
conn
.
createStatement
().
execute
(
"CREATE TABLE IF NOT EXISTS TRAN (ID NUMBER(18,0) not null PRIMARY KEY)"
);
final
ArrayList
<
Callable
<
Void
>>
callables
=
new
ArrayList
<
Callable
<
Void
>>();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
final
long
initialTransactionId
=
i
*
1000000L
;
callables
.
add
(
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
Exception
{
try
(
Connection
taskConn
=
getConnection
(
url
))
{
taskConn
.
setAutoCommit
(
false
);
PreparedStatement
insertTranStmt
=
taskConn
.
prepareStatement
(
"INSERT INTO tran (id) VALUES(?)"
);
// to guarantee uniqueness
long
tranId
=
initialTransactionId
;
for
(
int
j
=
0
;
j
<
1000
;
j
++)
{
insertTranStmt
.
setLong
(
1
,
tranId
++);
insertTranStmt
.
execute
();
taskConn
.
commit
();
}
}
return
null
;
}
taskConn
.
close
();
return
null
;
}
});
}
});
}
final
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadCount
);
try
{
final
ArrayList
<
Future
<
Void
>>
jobs
=
new
ArrayList
<
Future
<
Void
>>();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
jobs
.
add
(
executor
.
submit
(
callables
.
get
(
i
)));
...
...
@@ -441,42 +434,42 @@ public class TestMultiThread extends TestBase implements Runnable {
final
int
objectCount
=
10000
;
final
String
url
=
getURL
(
"lockMode;MULTI_THREADED=1;LOCK_TIMEOUT=10000"
,
true
);
final
Connection
conn
=
getConnection
(
url
);
conn
.
createStatement
().
execute
(
"CREATE TABLE IF NOT EXISTS ACCOUNT"
+
"(ID NUMBER(18,0) not null PRIMARY KEY, BALANCE NUMBER null)"
);
final
PreparedStatement
mergeAcctStmt
=
conn
.
prepareStatement
(
"MERGE INTO Account(id, balance) key (id) VALUES (?, ?)"
);
for
(
int
i
=
0
;
i
<
objectCount
;
i
++)
{
mergeAcctStmt
.
setLong
(
1
,
i
);
mergeAcctStmt
.
setBigDecimal
(
2
,
BigDecimal
.
ZERO
);
mergeAcctStmt
.
execute
();
}
int
threadCount
=
25
;
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadCount
);
Connection
conn
=
getConnection
(
url
);
try
{
conn
.
createStatement
().
execute
(
"CREATE TABLE IF NOT EXISTS ACCOUNT"
+
"(ID NUMBER(18,0) not null PRIMARY KEY, BALANCE NUMBER null)"
);
final
PreparedStatement
mergeAcctStmt
=
conn
.
prepareStatement
(
"MERGE INTO Account(id, balance) key (id) VALUES (?, ?)"
);
for
(
int
i
=
0
;
i
<
objectCount
;
i
++)
{
mergeAcctStmt
.
setLong
(
1
,
i
);
mergeAcctStmt
.
setBigDecimal
(
2
,
BigDecimal
.
ZERO
);
mergeAcctStmt
.
execute
();
}
final
int
threadCount
=
25
;
final
ArrayList
<
Callable
<
Void
>>
callables
=
new
ArrayList
<
Callable
<
Void
>>();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
final
Connection
taskConn
=
getConnection
(
url
);
taskConn
.
setAutoCommit
(
false
);
final
PreparedStatement
updateAcctStmt
=
taskConn
.
prepareStatement
(
"UPDATE account set balance = ? where id = ?"
);
callables
.
add
(
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
Exception
{
for
(
int
j
=
0
;
j
<
1000
;
j
++)
{
updateAcctStmt
.
setDouble
(
1
,
Math
.
random
());
updateAcctStmt
.
setLong
(
2
,
(
int
)
(
Math
.
random
()
*
objectCount
));
updateAcctStmt
.
execute
();
taskConn
.
commit
();
final
ArrayList
<
Callable
<
Void
>>
callables
=
new
ArrayList
<
Callable
<
Void
>>();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
callables
.
add
(
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
Exception
{
try
(
Connection
taskConn
=
getConnection
(
url
))
{
taskConn
.
setAutoCommit
(
false
);
final
PreparedStatement
updateAcctStmt
=
taskConn
.
prepareStatement
(
"UPDATE account SET balance = ? WHERE id = ?"
);
for
(
int
j
=
0
;
j
<
1000
;
j
++)
{
updateAcctStmt
.
setDouble
(
1
,
Math
.
random
());
updateAcctStmt
.
setLong
(
2
,
(
int
)
(
Math
.
random
()
*
objectCount
));
updateAcctStmt
.
execute
();
taskConn
.
commit
();
}
}
return
null
;
}
taskConn
.
close
();
return
null
;
}
});
}
});
}
final
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadCount
);
try
{
final
ArrayList
<
Future
<
Void
>>
jobs
=
new
ArrayList
<
Future
<
Void
>>();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
jobs
.
add
(
executor
.
submit
(
callables
.
get
(
i
)));
...
...
h2/src/test/org/h2/test/db/TestQueryCache.java
浏览文件 @
d28d8c3a
...
...
@@ -36,75 +36,75 @@ public class TestQueryCache extends TestBase {
}
private
void
test1
()
throws
Exception
{
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar)"
);
PreparedStatement
prep
;
// query execution may be fast here but the parsing must be slow
StringBuilder
queryBuilder
=
new
StringBuilder
(
"select count(*) from test t1 where \n"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
if
(
i
!=
0
)
{
queryBuilder
.
append
(
" and "
);
try
(
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar)"
);
PreparedStatement
prep
;
// query execution may be fast here but the parsing must be slow
StringBuilder
queryBuilder
=
new
StringBuilder
(
"select count(*) from test t1 where \n"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
if
(
i
!=
0
)
{
queryBuilder
.
append
(
" and "
);
}
queryBuilder
.
append
(
" TIMESTAMP '2005-12-31 23:59:59' = TIMESTAMP '2005-12-31 23:59:59' "
);
}
queryBuilder
.
append
(
" TIMESTAMP '2005-12-31 23:59:59' = TIMESTAMP '2005-12-31 23:59:59' "
);
}
String
query
=
queryBuilder
.
toString
();
conn
.
prepareStatement
(
query
);
int
firstGreater
=
0
;
int
firstSmaller
=
0
;
long
time
;
ResultSet
rs
;
long
first
=
0
;
// 1000 iterations to warm up and avoid JIT effects
for
(
int
i
=
0
;
i
<
1005
;
i
++)
{
// this should both ensure results are not re-used
// stat.execute("set mode regular");
// stat.execute("create table x()");
// stat.execute("drop table x");
time
=
System
.
nanoTime
();
prep
=
conn
.
prepareStatement
(
query
);
execute
(
prep
);
prep
.
close
();
rs
=
stat
.
executeQuery
(
query
);
rs
.
next
();
int
c
=
rs
.
getInt
(
1
);
rs
.
close
();
assertEquals
(
0
,
c
);
time
=
System
.
nanoTime
()
-
time
;
if
(
i
==
1000
)
{
// take from cache and do not close, so that next iteration will have a cache miss
String
query
=
queryBuilder
.
toString
();
conn
.
prepareStatement
(
query
);
int
firstGreater
=
0
;
int
firstSmaller
=
0
;
long
time
;
ResultSet
rs
;
long
first
=
0
;
// 1000 iterations to warm up and avoid JIT effects
for
(
int
i
=
0
;
i
<
1005
;
i
++)
{
// this should both ensure results are not re-used
// stat.execute("set mode regular");
// stat.execute("create table x()");
// stat.execute("drop table x");
time
=
System
.
nanoTime
();
prep
=
conn
.
prepareStatement
(
query
);
}
else
if
(
i
==
1001
)
{
first
=
time
;
// try to avoid pauses in subsequent iterations
System
.
gc
();
}
else
if
(
i
>
1001
)
{
if
(
first
>
time
)
{
firstGreater
++;
}
else
{
firstSmaller
++;
execute
(
prep
);
prep
.
close
();
rs
=
stat
.
executeQuery
(
query
);
rs
.
next
();
int
c
=
rs
.
getInt
(
1
);
rs
.
close
();
assertEquals
(
0
,
c
);
time
=
System
.
nanoTime
()
-
time
;
if
(
i
==
1000
)
{
// take from cache and do not close, so that next iteration will have a cache miss
prep
=
conn
.
prepareStatement
(
query
);
}
else
if
(
i
==
1001
)
{
first
=
time
;
// try to avoid pauses in subsequent iterations
System
.
gc
();
}
else
if
(
i
>
1001
)
{
if
(
first
>
time
)
{
firstGreater
++;
}
else
{
firstSmaller
++;
}
}
}
// first prepare time must be always greater because of query cache,
// but JVM is too unpredictable to assert that, so just check that
// usually this is true
assertSmaller
(
firstSmaller
,
firstGreater
);
stat
.
execute
(
"drop table test"
);
}
// first prepare time must be always greater because of query cache,
// but JVM is too unpredictable to assert that, so just check that
// usually this is true
assertSmaller
(
firstSmaller
,
firstGreater
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testClearingCacheWithTableStructureChanges
()
throws
Exception
{
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
conn
).
prepareStatement
(
"SELECT * FROM TEST"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
executeUpdate
(
"CREATE TABLE TEST(col1 bigint, col2 varchar(255))"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST"
);
prep
.
close
();
stat
.
executeUpdate
(
"DROP TABLE TEST"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
conn
).
prepareStatement
(
"SELECT * FROM TEST"
);
conn
.
close
();
try
(
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
))
{
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
conn
).
prepareStatement
(
"SELECT * FROM TEST"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
executeUpdate
(
"CREATE TABLE TEST(col1 bigint, col2 varchar(255))"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST"
);
prep
.
close
();
stat
.
executeUpdate
(
"DROP TABLE TEST"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
conn
).
prepareStatement
(
"SELECT * FROM TEST"
);
}
}
}
h2/src/test/org/h2/test/db/TestShow.java
浏览文件 @
d28d8c3a
...
...
@@ -33,34 +33,36 @@ public class TestShow extends TestBase {
}
private
void
testPgCompatibility
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"mem:pg"
);
Statement
stat
=
conn
.
createStatement
();
try
(
Connection
conn
=
getConnection
(
"mem:pg"
))
{
Statement
stat
=
conn
.
createStatement
();
assertResult
(
"UNICODE"
,
stat
,
"SHOW CLIENT_ENCODING"
);
assertResult
(
"read committed"
,
stat
,
"SHOW DEFAULT_TRANSACTION_ISOLATION"
);
assertResult
(
"read committed"
,
stat
,
"SHOW TRANSACTION ISOLATION LEVEL"
);
assertResult
(
"ISO"
,
stat
,
"SHOW DATESTYLE"
);
assertResult
(
"8.1.4"
,
stat
,
"SHOW SERVER_VERSION"
);
assertResult
(
"UTF8"
,
stat
,
"SHOW SERVER_ENCODING"
);
assertResult
(
"UNICODE"
,
stat
,
"SHOW CLIENT_ENCODING"
);
assertResult
(
"read committed"
,
stat
,
"SHOW DEFAULT_TRANSACTION_ISOLATION"
);
assertResult
(
"read committed"
,
stat
,
"SHOW TRANSACTION ISOLATION LEVEL"
);
assertResult
(
"ISO"
,
stat
,
"SHOW DATESTYLE"
);
assertResult
(
"8.1.4"
,
stat
,
"SHOW SERVER_VERSION"
);
assertResult
(
"UTF8"
,
stat
,
"SHOW SERVER_ENCODING"
);
}
}
private
void
testMysqlCompatibility
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"mem:pg"
);
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
try
(
Connection
conn
=
getConnection
(
"mem:pg"
))
{
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
// show tables without a schema
stat
.
execute
(
"create table person(id int, name varchar)"
);
rs
=
stat
.
executeQuery
(
"SHOW TABLES"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"PERSON"
,
rs
.
getString
(
1
));
assertEquals
(
"PUBLIC"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
// show tables without a schema
stat
.
execute
(
"create table person(id int, name varchar)"
);
rs
=
stat
.
executeQuery
(
"SHOW TABLES"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"PERSON"
,
rs
.
getString
(
1
));
assertEquals
(
"PUBLIC"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
// show tables with a schema
assertResultRowCount
(
1
,
stat
.
executeQuery
(
"SHOW TABLES FROM PUBLIC"
));
// show tables with a schema
assertResultRowCount
(
1
,
stat
.
executeQuery
(
"SHOW TABLES FROM PUBLIC"
));
// columns
assertResultRowCount
(
2
,
stat
.
executeQuery
(
"SHOW COLUMNS FROM person"
));
// columns
assertResultRowCount
(
2
,
stat
.
executeQuery
(
"SHOW COLUMNS FROM person"
));
}
}
}
h2/src/test/org/h2/test/db/TestSpatial.java
浏览文件 @
d28d8c3a
...
...
@@ -1064,96 +1064,99 @@ public class TestSpatial extends TestBase {
private
void
testInsertNull
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"\n"
+
"drop table if exists PUBLIC.DUMMY_12;\n"
+
"CREATE TABLE PUBLIC.DUMMY_12 (\n"
+
" \"fid\" serial,\n"
+
" Z_ID INTEGER,\n"
+
" GEOM GEOMETRY,\n"
+
" CONSTRAINT CONSTRAINT_DUMMY_12 PRIMARY KEY (\"fid\")\n"
+
");\n"
+
"CREATE INDEX PRIMARY_KEY_DUMMY_12 ON PUBLIC.DUMMY_12 (\"fid\");\n"
+
"CREATE spatial INDEX PUBLIC_DUMMY_12_SPATIAL_INDEX_ ON PUBLIC.DUMMY_12 (GEOM);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (123,3125163,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (124,3125164,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (125,3125173,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (126,3125174,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (127,3125175,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (128,3125176,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (129,3125177,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (130,3125178,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (131,3125179,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (132,3125180,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (133,3125335,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (134,3125336,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (135,3125165,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (136,3125337,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (137,3125338,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (138,3125339,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (139,3125340,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (140,3125341,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (141,3125342,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (142,3125343,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (143,3125344,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (144,3125345,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (145,3125346,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (146,3125166,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (147,3125347,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (148,3125348,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (149,3125349,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (150,3125350,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (151,3125351,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (152,3125352,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (153,3125353,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (154,3125354,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (155,3125355,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (156,3125356,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (157,3125167,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (158,3125357,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (159,3125358,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (160,3125359,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (161,3125360,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (162,3125361,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (163,3125362,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (164,3125363,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (165,3125364,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (166,3125365,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (167,3125366,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (168,3125168,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (169,3125367,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (170,3125368,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (171,3125369,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (172,3125370,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (173,3125169,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (174,3125170,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (175,3125171,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (176,3125172,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (177,-2,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (178,-1,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (179,"
+
"-1,NULL);"
);
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"select * from DUMMY_12"
))
{
assertTrue
(
rs
.
next
());
try
(
Connection
conn
=
getConnection
(
URL
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"\n"
+
"drop table if exists PUBLIC.DUMMY_12;\n"
+
"CREATE TABLE PUBLIC.DUMMY_12 (\n"
+
" \"fid\" serial,\n"
+
" Z_ID INTEGER,\n"
+
" GEOM GEOMETRY,\n"
+
" CONSTRAINT CONSTRAINT_DUMMY_12 PRIMARY KEY (\"fid\")\n"
+
");\n"
+
"CREATE INDEX PRIMARY_KEY_DUMMY_12 ON PUBLIC.DUMMY_12 (\"fid\");\n"
+
"CREATE spatial INDEX PUBLIC_DUMMY_12_SPATIAL_INDEX_ ON PUBLIC.DUMMY_12 (GEOM);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (123,3125163,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (124,3125164,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (125,3125173,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (126,3125174,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (127,3125175,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (128,3125176,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (129,3125177,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (130,3125178,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (131,3125179,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (132,3125180,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (133,3125335,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (134,3125336,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (135,3125165,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (136,3125337,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (137,3125338,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (138,3125339,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (139,3125340,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (140,3125341,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (141,3125342,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (142,3125343,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (143,3125344,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (144,3125345,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (145,3125346,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (146,3125166,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (147,3125347,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (148,3125348,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (149,3125349,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (150,3125350,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (151,3125351,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (152,3125352,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (153,3125353,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (154,3125354,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (155,3125355,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (156,3125356,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (157,3125167,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (158,3125357,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (159,3125358,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (160,3125359,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (161,3125360,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (162,3125361,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (163,3125362,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (164,3125363,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (165,3125364,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (166,3125365,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (167,3125366,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (168,3125168,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (169,3125367,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (170,3125368,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (171,3125369,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (172,3125370,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (173,3125169,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (174,3125170,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (175,3125171,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (176,3125172,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (177,-2,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (178,-1,NULL);\n"
+
"INSERT INTO PUBLIC.DUMMY_12 (\"fid\",Z_ID,GEOM) VALUES (179,"
+
"-1,NULL);"
);
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"select * from DUMMY_12"
))
{
assertTrue
(
rs
.
next
());
}
}
deleteDb
(
"spatial"
);
}
private
void
testSpatialIndexWithOrder
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
URL
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE IF EXISTS BUILDINGS;"
+
"CREATE TABLE BUILDINGS (PK serial, THE_GEOM geometry);"
+
"insert into buildings(the_geom) SELECT 'POINT(1 1)"
+
"'::geometry from SYSTEM_RANGE(1,10000);\n"
+
"CREATE SPATIAL INDEX ON PUBLIC.BUILDINGS(THE_GEOM);\n"
);
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"EXPLAIN SELECT * FROM "
+
"BUILDINGS ORDER BY PK LIMIT 51;"
))
{
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
getString
(
1
).
contains
(
"PRIMARY_KEY"
));
try
(
Connection
conn
=
getConnection
(
URL
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE IF EXISTS BUILDINGS;"
+
"CREATE TABLE BUILDINGS (PK serial, THE_GEOM geometry);"
+
"insert into buildings(the_geom) SELECT 'POINT(1 1)"
+
"'::geometry from SYSTEM_RANGE(1,10000);\n"
+
"CREATE SPATIAL INDEX ON PUBLIC.BUILDINGS(THE_GEOM);\n"
);
try
(
ResultSet
rs
=
stat
.
executeQuery
(
"EXPLAIN SELECT * FROM "
+
"BUILDINGS ORDER BY PK LIMIT 51;"
))
{
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
getString
(
1
).
contains
(
"PRIMARY_KEY"
));
}
}
deleteDb
(
"spatial"
);
}
}
h2/src/test/org/h2/test/jdbc/TestConnection.java
浏览文件 @
d28d8c3a
...
...
@@ -45,6 +45,7 @@ public class TestConnection extends TestBase {
assertThrows
(
SQLClientInfoException
.
class
,
conn
).
setClientInfo
(
"numServers"
,
"SomeValue"
);
assertThrows
(
SQLClientInfoException
.
class
,
conn
).
setClientInfo
(
"server23"
,
"SomeValue"
);
conn
.
close
();
}
private
void
testSetUnsupportedClientInfoProperties
()
throws
SQLException
{
...
...
@@ -54,6 +55,7 @@ public class TestConnection extends TestBase {
properties
.
put
(
"ClientUser"
,
"someUser"
);
assertThrows
(
SQLClientInfoException
.
class
,
conn
).
setClientInfo
(
properties
);
conn
.
close
();
}
private
void
testSetSupportedClientInfoProperties
()
throws
SQLException
{
...
...
@@ -67,6 +69,7 @@ public class TestConnection extends TestBase {
assertNull
(
conn
.
getClientInfo
(
"ApplicationName"
));
// new property has been set
assertEquals
(
conn
.
getClientInfo
(
"ClientUser"
),
"someUser"
);
conn
.
close
();
}
private
void
testSetSupportedClientInfo
()
throws
SQLException
{
...
...
@@ -74,17 +77,20 @@ public class TestConnection extends TestBase {
conn
.
setClientInfo
(
"ApplicationName"
,
"Connection Test"
);
assertEquals
(
conn
.
getClientInfo
(
"ApplicationName"
),
"Connection Test"
);
conn
.
close
();
}
private
void
testSetUnsupportedClientInfo
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"clientInfoDB2;MODE=DB2"
);
assertThrows
(
SQLClientInfoException
.
class
,
conn
).
setClientInfo
(
"UnsupportedName"
,
"SomeValue"
);
conn
.
close
();
}
private
void
testGetUnsupportedClientInfo
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"clientInfo"
);
assertNull
(
conn
.
getClientInfo
(
"UnknownProperty"
));
conn
.
close
();
}
private
void
testSetGetSchema
()
throws
SQLException
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论