Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
572abc02
提交
572abc02
authored
1月 08, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
b4f64a3d
显示空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
151 行增加
和
151 行删除
+151
-151
ShowProgress.java
h2/src/test/org/h2/samples/ShowProgress.java
+3
-3
BenchA.java
h2/src/test/org/h2/test/bench/BenchA.java
+24
-25
BenchB.java
h2/src/test/org/h2/test/bench/BenchB.java
+4
-3
BenchC.java
h2/src/test/org/h2/test/bench/BenchC.java
+39
-39
BenchSimple.java
h2/src/test/org/h2/test/bench/BenchSimple.java
+3
-2
Database.java
h2/src/test/org/h2/test/bench/Database.java
+29
-29
Coverage.java
h2/src/test/org/h2/test/coverage/Coverage.java
+2
-2
TestIndex.java
h2/src/test/org/h2/test/db/TestIndex.java
+18
-18
TestListener.java
h2/src/test/org/h2/test/db/TestListener.java
+6
-6
TestLob.java
h2/src/test/org/h2/test/db/TestLob.java
+3
-3
TestMemoryUsage.java
h2/src/test/org/h2/test/db/TestMemoryUsage.java
+8
-8
TestMultiThread.java
h2/src/test/org/h2/test/db/TestMultiThread.java
+2
-3
TestMultiThreadedKernel.java
h2/src/test/org/h2/test/db/TestMultiThreadedKernel.java
+1
-1
TestOpenClose.java
h2/src/test/org/h2/test/db/TestOpenClose.java
+3
-3
TestTriggersConstraints.java
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
+6
-6
没有找到文件。
h2/src/test/org/h2/samples/ShowProgress.java
浏览文件 @
572abc02
...
...
@@ -55,9 +55,9 @@ public class ShowProgress implements DatabaseEventListener {
time
=
System
.
currentTimeMillis
();
int
len
=
1000
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
long
last
=
System
.
currentTimeMillis
();
if
(
last
>
time
+
1000
)
{
time
=
last
;
long
now
=
System
.
currentTimeMillis
();
if
(
now
>
time
+
1000
)
{
time
=
now
;
System
.
out
.
println
(
"Inserting "
+
(
100L
*
i
/
len
)
+
"%"
);
}
prep
.
setInt
(
1
,
i
);
...
...
h2/src/test/org/h2/test/bench/BenchA.java
浏览文件 @
572abc02
...
...
@@ -22,16 +22,16 @@ public class BenchA implements Bench {
private
static
final
String
FILLER
=
"abcdefghijklmnopqrstuvwxyz"
;
private
static
final
int
DELTA
=
10000
;
private
Database
d
b
;
private
Database
d
atabase
;
private
int
branches
;
private
int
tellers
;
private
int
accounts
;
private
int
size
;
private
int
transactions
;
public
void
init
(
Database
db
,
int
size
)
throws
SQLException
{
this
.
d
b
=
db
;
t
his
.
size
=
size
;
this
.
d
atabase
=
db
;
t
ransactions
=
size
*
30
;
int
scale
=
1
;
accounts
=
size
*
50
;
...
...
@@ -100,32 +100,31 @@ public class BenchA implements Bench {
public
void
runTest
()
throws
SQLException
{
d
b
.
start
(
this
,
"Transactions"
);
d
b
.
openConnection
();
d
atabase
.
start
(
this
,
"Transactions"
);
d
atabase
.
openConnection
();
processTransactions
();
d
b
.
closeConnection
();
d
b
.
end
();
d
atabase
.
closeConnection
();
d
atabase
.
end
();
d
b
.
openConnection
();
d
atabase
.
openConnection
();
processTransactions
();
d
b
.
logMemory
(
this
,
"Memory Usage"
);
d
b
.
closeConnection
();
d
atabase
.
logMemory
(
this
,
"Memory Usage"
);
d
atabase
.
closeConnection
();
}
private
void
processTransactions
()
throws
SQLException
{
Random
random
=
d
b
.
getRandom
();
Random
random
=
d
atabase
.
getRandom
();
int
branch
=
random
.
nextInt
(
branches
);
int
teller
=
random
.
nextInt
(
tellers
);
int
transactions
=
size
*
30
;
PreparedStatement
updateAccount
=
d
b
.
prepare
(
"UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?"
);
PreparedStatement
selectBalance
=
d
b
.
prepare
(
"SELECT ABALANCE FROM ACCOUNTS WHERE AID=?"
);
PreparedStatement
updateTeller
=
d
b
.
prepare
(
"UPDATE TELLERS SET TBALANCE=TBALANCE+? WHERE TID=?"
);
PreparedStatement
updateBranch
=
d
b
.
prepare
(
"UPDATE BRANCHES SET BBALANCE=BBALANCE+? WHERE BID=?"
);
PreparedStatement
insertHistory
=
d
b
.
prepare
(
"INSERT INTO HISTORY(AID,TID,BID,DELTA,HTIME,FILLER) VALUES(?,?,?,?,?,?)"
);
PreparedStatement
updateAccount
=
d
atabase
.
prepare
(
"UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?"
);
PreparedStatement
selectBalance
=
d
atabase
.
prepare
(
"SELECT ABALANCE FROM ACCOUNTS WHERE AID=?"
);
PreparedStatement
updateTeller
=
d
atabase
.
prepare
(
"UPDATE TELLERS SET TBALANCE=TBALANCE+? WHERE TID=?"
);
PreparedStatement
updateBranch
=
d
atabase
.
prepare
(
"UPDATE BRANCHES SET BBALANCE=BBALANCE+? WHERE BID=?"
);
PreparedStatement
insertHistory
=
d
atabase
.
prepare
(
"INSERT INTO HISTORY(AID,TID,BID,DELTA,HTIME,FILLER) VALUES(?,?,?,?,?,?)"
);
int
accountsPerBranch
=
accounts
/
branches
;
d
b
.
setAutoCommit
(
false
);
d
atabase
.
setAutoCommit
(
false
);
for
(
int
i
=
0
;
i
<
transactions
;
i
++)
{
int
account
;
...
...
@@ -142,18 +141,18 @@ public class BenchA implements Bench {
updateAccount
.
setBigDecimal
(
1
,
delta
);
updateAccount
.
setInt
(
2
,
account
);
d
b
.
update
(
updateAccount
,
"updateAccount"
);
d
atabase
.
update
(
updateAccount
,
"updateAccount"
);
updateTeller
.
setBigDecimal
(
1
,
delta
);
updateTeller
.
setInt
(
2
,
teller
);
d
b
.
update
(
updateTeller
,
"updateTeller"
);
d
atabase
.
update
(
updateTeller
,
"updateTeller"
);
updateBranch
.
setBigDecimal
(
1
,
delta
);
updateBranch
.
setInt
(
2
,
branch
);
d
b
.
update
(
updateBranch
,
"updateBranch"
);
d
atabase
.
update
(
updateBranch
,
"updateBranch"
);
selectBalance
.
setInt
(
1
,
account
);
d
b
.
queryReadResult
(
selectBalance
);
d
atabase
.
queryReadResult
(
selectBalance
);
insertHistory
.
setInt
(
1
,
account
);
insertHistory
.
setInt
(
2
,
teller
);
...
...
@@ -164,9 +163,9 @@ public class BenchA implements Bench {
// insertHistory.setDate(5, new java.sql.Date(current));
insertHistory
.
setTimestamp
(
5
,
new
java
.
sql
.
Timestamp
(
current
));
insertHistory
.
setString
(
6
,
BenchA
.
FILLER
);
d
b
.
update
(
insertHistory
,
"insertHistory"
);
d
atabase
.
update
(
insertHistory
,
"insertHistory"
);
d
b
.
commit
();
d
atabase
.
commit
();
}
updateAccount
.
close
();
selectBalance
.
close
();
...
...
h2/src/test/org/h2/test/bench/BenchB.java
浏览文件 @
572abc02
...
...
@@ -22,7 +22,7 @@ import java.util.Random;
public
class
BenchB
implements
Bench
,
Runnable
{
// master data
private
Database
d
b
;
private
Database
d
atabase
;
private
int
scale
=
1
;
private
int
branches
=
1
;
private
int
tellers
=
10
;
...
...
@@ -47,7 +47,7 @@ public class BenchB implements Bench, Runnable {
private
BenchB
(
BenchB
master
,
int
seed
)
throws
SQLException
{
this
.
master
=
master
;
random
=
new
Random
(
seed
);
conn
=
master
.
d
b
.
openNewConnection
();
conn
=
master
.
d
atabase
.
openNewConnection
();
conn
.
setAutoCommit
(
false
);
updateAccount
=
conn
.
prepareStatement
(
"UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?"
);
...
...
@@ -62,7 +62,7 @@ public class BenchB implements Bench, Runnable {
}
public
void
init
(
Database
db
,
int
size
)
throws
SQLException
{
this
.
d
b
=
db
;
this
.
d
atabase
=
db
;
this
.
transactionPerClient
=
size
;
db
.
start
(
this
,
"Init"
);
...
...
@@ -181,6 +181,7 @@ public class BenchB implements Bench, Runnable {
public
void
runTest
()
throws
Exception
{
Database
db
=
database
;
db
.
start
(
this
,
"Transactions"
);
db
.
openConnection
();
processTransactions
();
...
...
h2/src/test/org/h2/test/bench/BenchC.java
浏览文件 @
572abc02
...
...
@@ -169,7 +169,7 @@ public class BenchC implements Bench {
int
districtsPerWarehouse
=
10
;
int
customersPerDistrict
=
300
;
private
Database
d
b
;
private
Database
d
atabase
;
private
int
ordersPerDistrict
=
300
;
...
...
@@ -180,7 +180,7 @@ public class BenchC implements Bench {
public
void
init
(
Database
db
,
int
size
)
throws
SQLException
{
this
.
d
b
=
db
;
this
.
d
atabase
=
db
;
random
=
new
BenchCRandom
();
...
...
@@ -206,17 +206,17 @@ public class BenchC implements Bench {
private
void
load
()
throws
SQLException
{
for
(
String
sql
:
TABLES
)
{
d
b
.
dropTable
(
sql
);
d
atabase
.
dropTable
(
sql
);
}
for
(
String
sql
:
CREATE_SQL
)
{
d
b
.
update
(
sql
);
d
atabase
.
update
(
sql
);
}
d
b
.
setAutoCommit
(
false
);
d
atabase
.
setAutoCommit
(
false
);
loadItem
();
loadWarehouse
();
loadCustomer
();
loadOrder
();
d
b
.
commit
();
d
atabase
.
commit
();
trace
(
"Load done"
);
}
...
...
@@ -225,13 +225,13 @@ public class BenchC implements Bench {
}
private
void
trace
(
int
i
,
int
max
)
{
d
b
.
trace
(
action
,
i
,
max
);
d
atabase
.
trace
(
action
,
i
,
max
);
}
private
void
loadItem
()
throws
SQLException
{
trace
(
"Loading item table"
);
boolean
[]
original
=
random
.
getBoolean
(
items
,
items
/
10
);
PreparedStatement
prep
=
d
b
.
prepare
(
PreparedStatement
prep
=
d
atabase
.
prepare
(
"INSERT INTO ITEM(I_ID, I_IM_ID, I_NAME, I_PRICE, I_DATA) "
+
"VALUES(?, ?, ?, ?, ?)"
);
for
(
int
id
=
1
;
id
<=
items
;
id
++)
{
...
...
@@ -246,17 +246,17 @@ public class BenchC implements Bench {
prep
.
setString
(
3
,
name
);
prep
.
setBigDecimal
(
4
,
price
);
prep
.
setString
(
5
,
data
);
d
b
.
update
(
prep
,
"insertItem"
);
d
atabase
.
update
(
prep
,
"insertItem"
);
trace
(
id
,
items
);
if
(
id
%
commitEvery
==
0
)
{
d
b
.
commit
();
d
atabase
.
commit
();
}
}
}
private
void
loadWarehouse
()
throws
SQLException
{
trace
(
"Loading warehouse table"
);
PreparedStatement
prep
=
d
b
.
prepare
(
PreparedStatement
prep
=
d
atabase
.
prepare
(
"INSERT INTO WAREHOUSE(W_ID, W_NAME, W_STREET_1, "
+
"W_STREET_2, W_CITY, W_STATE, W_ZIP, W_TAX, W_YTD) "
+
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
...
...
@@ -279,11 +279,11 @@ public class BenchC implements Bench {
prep
.
setString
(
7
,
zip
);
prep
.
setBigDecimal
(
8
,
tax
);
prep
.
setBigDecimal
(
9
,
ytd
);
d
b
.
update
(
prep
,
"insertWarehouse"
);
d
atabase
.
update
(
prep
,
"insertWarehouse"
);
loadStock
(
id
);
loadDistrict
(
id
);
if
(
id
%
commitEvery
==
0
)
{
d
b
.
commit
();
d
atabase
.
commit
();
}
}
}
...
...
@@ -297,7 +297,7 @@ public class BenchC implements Bench {
loadCustomerSub
(
districtId
,
id
);
trace
(
i
++,
max
);
if
(
i
%
commitEvery
==
0
)
{
d
b
.
commit
();
d
atabase
.
commit
();
}
}
}
...
...
@@ -305,7 +305,7 @@ public class BenchC implements Bench {
private
void
loadCustomerSub
(
int
dId
,
int
wId
)
throws
SQLException
{
Timestamp
timestamp
=
new
Timestamp
(
System
.
currentTimeMillis
());
PreparedStatement
prepCustomer
=
d
b
.
prepare
(
PreparedStatement
prepCustomer
=
d
atabase
.
prepare
(
"INSERT INTO CUSTOMER(C_ID, C_D_ID, C_W_ID, "
+
"C_FIRST, C_MIDDLE, C_LAST, "
+
"C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, "
+
...
...
@@ -313,7 +313,7 @@ public class BenchC implements Bench {
"C_CREDIT_LIM, C_DISCOUNT, C_BALANCE, C_DATA, "
+
"C_YTD_PAYMENT, C_PAYMENT_CNT, C_DELIVERY_CNT) "
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
PreparedStatement
prepHistory
=
d
b
.
prepare
(
PreparedStatement
prepHistory
=
d
atabase
.
prepare
(
"INSERT INTO HISTORY(H_C_ID, H_C_D_ID, H_C_W_ID, "
+
"H_W_ID, H_D_ID, H_DATE, H_AMOUNT, H_DATA) "
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
);
...
...
@@ -367,7 +367,7 @@ public class BenchC implements Bench {
prepCustomer
.
setBigDecimal
(
19
,
ytdPayment
);
prepCustomer
.
setInt
(
20
,
paymentCnt
);
prepCustomer
.
setInt
(
21
,
deliveryCnt
);
d
b
.
update
(
prepCustomer
,
"insertCustomer"
);
d
atabase
.
update
(
prepCustomer
,
"insertCustomer"
);
BigDecimal
amount
=
new
BigDecimal
(
"10.00"
);
String
hData
=
random
.
getString
(
12
,
24
);
prepHistory
.
setInt
(
1
,
cId
);
...
...
@@ -378,7 +378,7 @@ public class BenchC implements Bench {
prepHistory
.
setTimestamp
(
6
,
timestamp
);
prepHistory
.
setBigDecimal
(
7
,
amount
);
prepHistory
.
setString
(
8
,
hData
);
d
b
.
update
(
prepHistory
,
"insertHistory"
);
d
atabase
.
update
(
prepHistory
,
"insertHistory"
);
}
}
...
...
@@ -397,14 +397,14 @@ public class BenchC implements Bench {
private
void
loadOrderSub
(
int
dId
,
int
wId
)
throws
SQLException
{
Timestamp
timestamp
=
new
Timestamp
(
System
.
currentTimeMillis
());
int
[]
orderid
=
random
.
getPermutation
(
ordersPerDistrict
);
PreparedStatement
prepOrder
=
d
b
.
prepare
(
PreparedStatement
prepOrder
=
d
atabase
.
prepare
(
"INSERT INTO ORDERS(O_ID, O_C_ID, O_D_ID, O_W_ID, "
+
"O_ENTRY_D, O_CARRIER_ID, O_OL_CNT, O_ALL_LOCAL) "
+
"VALUES(?, ?, ?, ?, ?, ?, ?, 1)"
);
PreparedStatement
prepNewOrder
=
d
b
.
prepare
(
PreparedStatement
prepNewOrder
=
d
atabase
.
prepare
(
"INSERT INTO NEW_ORDER (NO_O_ID, NO_D_ID, NO_W_ID) "
+
"VALUES (?, ?, ?)"
);
PreparedStatement
prepLine
=
d
b
.
prepare
(
PreparedStatement
prepLine
=
d
atabase
.
prepare
(
"INSERT INTO ORDER_LINE("
+
"OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, "
+
"OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, "
+
...
...
@@ -428,9 +428,9 @@ public class BenchC implements Bench {
prepNewOrder
.
setInt
(
1
,
oId
);
prepNewOrder
.
setInt
(
2
,
dId
);
prepNewOrder
.
setInt
(
3
,
wId
);
d
b
.
update
(
prepNewOrder
,
"newNewOrder"
);
d
atabase
.
update
(
prepNewOrder
,
"newNewOrder"
);
}
d
b
.
update
(
prepOrder
,
"insertOrder"
);
d
atabase
.
update
(
prepOrder
,
"insertOrder"
);
for
(
int
ol
=
1
;
ol
<=
olCnt
;
ol
++)
{
int
id
=
random
.
getInt
(
1
,
items
);
int
supplyId
=
wId
;
...
...
@@ -451,9 +451,9 @@ public class BenchC implements Bench {
prepLine
.
setInt
(
7
,
quantity
);
prepLine
.
setBigDecimal
(
8
,
amount
);
prepLine
.
setString
(
9
,
distInfo
);
d
b
.
update
(
prepLine
,
"insertOrderLine"
);
d
atabase
.
update
(
prepLine
,
"insertOrderLine"
);
if
(
i
++
%
commitEvery
==
0
)
{
d
b
.
commit
();
d
atabase
.
commit
();
}
}
}
...
...
@@ -462,7 +462,7 @@ public class BenchC implements Bench {
private
void
loadStock
(
int
wId
)
throws
SQLException
{
trace
(
"Loading stock table (warehouse "
+
wId
+
")"
);
boolean
[]
original
=
random
.
getBoolean
(
items
,
items
/
10
);
PreparedStatement
prep
=
d
b
.
prepare
(
PreparedStatement
prep
=
d
atabase
.
prepare
(
"INSERT INTO STOCK(S_I_ID, S_W_ID, S_QUANTITY, "
+
"S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, "
+
"S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10, "
+
...
...
@@ -501,9 +501,9 @@ public class BenchC implements Bench {
prep
.
setInt
(
15
,
0
);
prep
.
setInt
(
16
,
0
);
prep
.
setInt
(
17
,
0
);
d
b
.
update
(
prep
,
"insertStock"
);
d
atabase
.
update
(
prep
,
"insertStock"
);
if
(
id
%
commitEvery
==
0
)
{
d
b
.
commit
();
d
atabase
.
commit
();
}
trace
(
id
,
items
);
}
...
...
@@ -512,7 +512,7 @@ public class BenchC implements Bench {
private
void
loadDistrict
(
int
wId
)
throws
SQLException
{
BigDecimal
ytd
=
new
BigDecimal
(
"300000.00"
);
int
nextId
=
3001
;
PreparedStatement
prep
=
d
b
.
prepare
(
PreparedStatement
prep
=
d
atabase
.
prepare
(
"INSERT INTO DISTRICT(D_ID, D_W_ID, D_NAME, "
+
"D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, "
+
"D_TAX, D_YTD, D_NEXT_O_ID) "
+
...
...
@@ -537,26 +537,26 @@ public class BenchC implements Bench {
prep
.
setBigDecimal
(
9
,
tax
);
prep
.
setBigDecimal
(
10
,
ytd
);
prep
.
setInt
(
11
,
nextId
);
d
b
.
update
(
prep
,
"insertDistrict"
);
d
atabase
.
update
(
prep
,
"insertDistrict"
);
trace
(
dId
,
districtsPerWarehouse
);
}
}
public
void
runTest
()
throws
SQLException
{
d
b
.
start
(
this
,
"Transactions"
);
d
b
.
openConnection
();
d
atabase
.
start
(
this
,
"Transactions"
);
d
atabase
.
openConnection
();
for
(
int
i
=
0
;
i
<
70
;
i
++)
{
BenchCThread
process
=
new
BenchCThread
(
d
b
,
this
,
random
,
i
);
BenchCThread
process
=
new
BenchCThread
(
d
atabase
,
this
,
random
,
i
);
process
.
process
();
}
d
b
.
closeConnection
();
d
b
.
end
();
d
atabase
.
closeConnection
();
d
atabase
.
end
();
d
b
.
openConnection
();
BenchCThread
process
=
new
BenchCThread
(
d
b
,
this
,
random
,
0
);
d
atabase
.
openConnection
();
BenchCThread
process
=
new
BenchCThread
(
d
atabase
,
this
,
random
,
0
);
process
.
process
();
d
b
.
logMemory
(
this
,
"Memory Usage"
);
d
b
.
closeConnection
();
d
atabase
.
logMemory
(
this
,
"Memory Usage"
);
d
atabase
.
closeConnection
();
}
public
String
getName
()
{
...
...
h2/src/test/org/h2/test/bench/BenchSimple.java
浏览文件 @
572abc02
...
...
@@ -17,11 +17,11 @@ import java.util.Random;
*/
public
class
BenchSimple
implements
Bench
{
Database
d
b
;
Database
d
atabase
;
int
records
;
public
void
init
(
Database
db
,
int
size
)
throws
SQLException
{
this
.
d
b
=
db
;
this
.
d
atabase
=
db
;
this
.
records
=
size
*
60
;
db
.
start
(
this
,
"Init"
);
...
...
@@ -53,6 +53,7 @@ public class BenchSimple implements Bench {
public
void
runTest
()
throws
SQLException
{
PreparedStatement
prep
;
Database
db
=
database
;
Random
random
=
db
.
getRandom
();
db
.
openConnection
();
...
...
h2/src/test/org/h2/test/bench/Database.java
浏览文件 @
572abc02
...
...
@@ -34,7 +34,7 @@ class Database {
private
int
id
;
private
String
name
,
url
,
user
,
password
;
private
ArrayList
<
String
[]>
replace
=
new
ArrayList
<
String
[]>();
private
String
a
ction
;
private
String
currentA
ction
;
private
long
startTime
;
private
Connection
conn
;
private
Statement
stat
;
...
...
@@ -182,12 +182,12 @@ class Database {
* @return the opened connection
*/
Connection
openNewConnection
()
throws
SQLException
{
Connection
c
onn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
Connection
newC
onn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
if
(
url
.
startsWith
(
"jdbc:derby:"
))
{
// Derby: use higher cache size
Statement
s
tat
=
null
;
Statement
s
=
null
;
try
{
s
tat
=
c
onn
.
createStatement
();
s
=
newC
onn
.
createStatement
();
// stat.execute("CALL
// SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.storage.pageCacheSize',
// '64')");
...
...
@@ -195,19 +195,19 @@ class Database {
// SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.storage.pageSize',
// '8192')");
}
finally
{
JdbcUtils
.
closeSilently
(
s
tat
);
JdbcUtils
.
closeSilently
(
s
);
}
}
else
if
(
url
.
startsWith
(
"jdbc:hsqldb:"
))
{
// HSQLDB: use a WRITE_DELAY of 1 second
Statement
s
tat
=
null
;
Statement
s
=
null
;
try
{
s
tat
=
c
onn
.
createStatement
();
s
tat
.
execute
(
"SET WRITE_DELAY 1"
);
s
=
newC
onn
.
createStatement
();
s
.
execute
(
"SET WRITE_DELAY 1"
);
}
finally
{
JdbcUtils
.
closeSilently
(
s
tat
);
JdbcUtils
.
closeSilently
(
s
);
}
}
return
c
onn
;
return
newC
onn
;
}
/**
...
...
@@ -222,9 +222,9 @@ class Database {
* Close the database connection.
*/
void
closeConnection
()
throws
SQLException
{
//
if(!serverHSQLDB && url.startsWith("jdbc:hsqldb:")) {
//
stat.execute("SHUTDOWN");
//
}
//
if(!serverHSQLDB && url.startsWith("jdbc:hsqldb:")) {
//
stat.execute("SHUTDOWN");
//
}
conn
.
close
();
stat
=
null
;
conn
=
null
;
...
...
@@ -236,12 +236,12 @@ class Database {
* @param prop the properties with the translations to use
*/
void
setTranslations
(
Properties
prop
)
{
String
id
=
url
.
substring
(
"jdbc:"
.
length
());
id
=
id
.
substring
(
0
,
id
.
indexOf
(
':'
));
String
databaseType
=
url
.
substring
(
"jdbc:"
.
length
());
databaseType
=
databaseType
.
substring
(
0
,
databaseType
.
indexOf
(
':'
));
for
(
Object
k
:
prop
.
keySet
())
{
String
key
=
(
String
)
k
;
if
(
key
.
startsWith
(
id
+
"."
))
{
String
pattern
=
key
.
substring
(
id
.
length
()
+
1
);
if
(
key
.
startsWith
(
databaseType
+
"."
))
{
String
pattern
=
key
.
substring
(
databaseType
.
length
()
+
1
);
pattern
=
StringUtils
.
replaceAll
(
pattern
,
"_"
,
" "
);
pattern
=
StringUtils
.
toUpperEnglish
(
pattern
);
String
replacement
=
prop
.
getProperty
(
key
);
...
...
@@ -264,8 +264,8 @@ class Database {
private
String
getSQL
(
String
sql
)
{
for
(
String
[]
pair
:
replace
)
{
String
pattern
=
pair
[
0
];
String
replace
=
pair
[
1
];
sql
=
StringUtils
.
replaceAll
(
sql
,
pattern
,
replace
);
String
replace
ment
=
pair
[
1
];
sql
=
StringUtils
.
replaceAll
(
sql
,
pattern
,
replace
ment
);
}
return
sql
;
}
...
...
@@ -277,7 +277,7 @@ class Database {
* @param action the action
*/
void
start
(
Bench
bench
,
String
action
)
{
this
.
a
ction
=
bench
.
getName
()
+
": "
+
action
;
this
.
currentA
ction
=
bench
.
getName
()
+
": "
+
action
;
this
.
startTime
=
System
.
currentTimeMillis
();
}
...
...
@@ -287,7 +287,7 @@ class Database {
*/
void
end
()
{
long
time
=
System
.
currentTimeMillis
()
-
startTime
;
log
(
a
ction
,
"ms"
,
(
int
)
time
);
log
(
currentA
ction
,
"ms"
,
(
int
)
time
);
if
(
test
.
collect
)
{
totalTime
+=
time
;
}
...
...
@@ -310,10 +310,10 @@ class Database {
* Execute an SQL statement.
*
* @param prep the prepared statement
* @param trace the trace message
* @param trace
Message
the trace message
*/
void
update
(
PreparedStatement
prep
,
String
trace
)
throws
SQLException
{
test
.
trace
(
trace
);
void
update
(
PreparedStatement
prep
,
String
trace
Message
)
throws
SQLException
{
test
.
trace
(
trace
Message
);
prep
.
executeUpdate
();
if
(
test
.
collect
)
{
executedStatements
++;
...
...
@@ -410,12 +410,12 @@ class Database {
* @return the result set
*/
ResultSet
query
(
PreparedStatement
prep
)
throws
SQLException
{
//
long time = System.currentTimeMillis();
//
long time = System.currentTimeMillis();
ResultSet
rs
=
prep
.
executeQuery
();
//
time = System.currentTimeMillis() - time;
//
if(time > 100) {
//
System.out.println("time="+time);
//
}
//
time = System.currentTimeMillis() - time;
//
if(time > 100) {
//
System.out.println("time="+time);
//
}
if
(
test
.
collect
)
{
executedStatements
++;
}
...
...
h2/src/test/org/h2/test/coverage/Coverage.java
浏览文件 @
572abc02
...
...
@@ -92,8 +92,8 @@ public class Coverage {
}
}
private
void
addExclude
(
String
file
)
{
exclude
.
add
(
file
);
private
void
addExclude
(
String
file
Name
)
{
exclude
.
add
(
file
Name
);
}
private
boolean
isExcluded
(
String
s
)
{
...
...
h2/src/test/org/h2/test/db/TestIndex.java
浏览文件 @
572abc02
...
...
@@ -108,12 +108,12 @@ public class TestIndex extends TestBase {
private
void
testRandomized
()
throws
SQLException
{
boolean
reopen
=
!
config
.
memory
;
Random
rand
om
=
new
Random
(
1
);
Random
rand
=
new
Random
(
1
);
reconnect
();
stat
.
execute
(
"CREATE TABLE TEST(ID identity)"
);
int
len
=
getSize
(
100
,
1000
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
switch
(
rand
om
.
nextInt
(
4
))
{
switch
(
rand
.
nextInt
(
4
))
{
case
0
:
if
(
reopen
)
{
trace
(
"reconnect"
);
...
...
@@ -144,16 +144,16 @@ public class TestIndex extends TestBase {
int
len
=
getSize
(
1000
,
10000
);
stat
.
execute
(
"insert into testA select x, 'Hello' from system_range(1, "
+
len
+
")"
);
stat
.
execute
(
"insert into testB select x, 'Hello' from system_range(1, "
+
len
+
")"
);
Random
rand
om
=
new
Random
(
1
);
Random
rand
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
x
=
rand
om
.
nextInt
(
len
);
int
x
=
rand
.
nextInt
(
len
);
String
sql
=
""
;
switch
(
rand
om
.
nextInt
(
3
))
{
switch
(
rand
.
nextInt
(
3
))
{
case
0
:
sql
=
"delete from testA where id = "
+
x
;
break
;
case
1
:
sql
=
"update testA set name = "
+
rand
om
.
nextInt
(
100
)
+
" where id = "
+
x
;
sql
=
"update testA set name = "
+
rand
.
nextInt
(
100
)
+
" where id = "
+
x
;
break
;
case
2
:
sql
=
"select name from testA where id = "
+
x
;
...
...
@@ -314,21 +314,21 @@ public class TestIndex extends TestBase {
prep
.
setInt
(
1
,
a
);
prep
.
setInt
(
2
,
a
);
prep
.
execute
();
assertEquals
(
1
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
assertEquals
(
0
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST WHERE A=-1-"
+
a
));
assertEquals
(
1
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
assertEquals
(
0
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A=-1-"
+
a
));
}
reconnect
();
prep
=
conn
.
prepareStatement
(
"DELETE FROM TEST WHERE A=?"
);
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
if
(
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
)
!=
1
)
{
assertEquals
(
1
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
if
(
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
)
!=
1
)
{
assertEquals
(
1
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
}
prep
.
setInt
(
1
,
a
);
assertEquals
(
1
,
prep
.
executeUpdate
());
}
assertEquals
(
0
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
));
assertEquals
(
0
,
getValue
(
"SELECT COUNT(*) FROM TEST"
));
}
private
void
testMultiColumnIndex
()
throws
SQLException
{
...
...
@@ -346,13 +346,13 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"CREATE INDEX ON TEST(A, B)"
);
prep
=
conn
.
prepareStatement
(
"DELETE FROM TEST WHERE A=?"
);
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
log
(
stat
,
"SELECT * FROM TEST"
);
assertEquals
(
2
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST WHERE A="
+
(
len
-
a
-
1
)));
assertEquals
((
len
-
a
)
*
2
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
));
log
(
"SELECT * FROM TEST"
);
assertEquals
(
2
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
(
len
-
a
-
1
)));
assertEquals
((
len
-
a
)
*
2
,
getValue
(
"SELECT COUNT(*) FROM TEST"
));
prep
.
setInt
(
1
,
len
-
a
-
1
);
prep
.
execute
();
}
assertEquals
(
0
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
));
assertEquals
(
0
,
getValue
(
"SELECT COUNT(*) FROM TEST"
));
}
private
void
testMultiColumnHashIndex
()
throws
SQLException
{
...
...
@@ -392,17 +392,17 @@ public class TestIndex extends TestBase {
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST WHERE DATA <> 'i('||a||','||b||')u('||a||','||b||')'"
);
assertFalse
(
rs
.
next
());
assertEquals
(
len
*
(
len
/
2
),
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
));
assertEquals
(
len
*
(
len
/
2
),
getValue
(
"SELECT COUNT(*) FROM TEST"
));
stat
.
execute
(
"DROP TABLE TEST"
);
}
private
int
getValue
(
St
atement
stat
,
St
ring
sql
)
throws
SQLException
{
private
int
getValue
(
String
sql
)
throws
SQLException
{
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
rs
.
next
();
return
rs
.
getInt
(
1
);
}
private
void
log
(
St
atement
stat
,
St
ring
sql
)
throws
SQLException
{
private
void
log
(
String
sql
)
throws
SQLException
{
trace
(
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
int
cols
=
rs
.
getMetaData
().
getColumnCount
();
...
...
h2/src/test/org/h2/test/db/TestListener.java
浏览文件 @
572abc02
...
...
@@ -23,7 +23,7 @@ public class TestListener extends TestBase implements DatabaseEventListener {
private
long
last
;
private
int
lastState
=
-
1
;
private
String
u
rl
;
private
String
databaseU
rl
;
public
TestListener
()
{
start
=
last
=
System
.
currentTimeMillis
();
...
...
@@ -102,12 +102,12 @@ public class TestListener extends TestBase implements DatabaseEventListener {
}
public
void
closingDatabase
()
{
if
(
u
rl
.
toUpperCase
().
indexOf
(
"CIPHER"
)
>=
0
)
{
if
(
databaseU
rl
.
toUpperCase
().
indexOf
(
"CIPHER"
)
>=
0
)
{
return
;
}
Connection
conn
=
null
;
try
{
conn
=
DriverManager
.
getConnection
(
u
rl
,
getUser
(),
getPassword
());
conn
=
DriverManager
.
getConnection
(
databaseU
rl
,
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"DROP TABLE TEST2"
);
conn
.
close
();
}
catch
(
SQLException
e
)
{
...
...
@@ -118,16 +118,16 @@ public class TestListener extends TestBase implements DatabaseEventListener {
}
public
void
init
(
String
url
)
{
this
.
u
rl
=
url
;
this
.
databaseU
rl
=
url
;
}
public
void
opened
()
{
if
(
u
rl
.
toUpperCase
().
indexOf
(
"CIPHER"
)
>=
0
)
{
if
(
databaseU
rl
.
toUpperCase
().
indexOf
(
"CIPHER"
)
>=
0
)
{
return
;
}
Connection
conn
=
null
;
try
{
conn
=
DriverManager
.
getConnection
(
u
rl
,
getUser
(),
getPassword
());
conn
=
DriverManager
.
getConnection
(
databaseU
rl
,
getUser
(),
getPassword
());
conn
.
createStatement
().
execute
(
"CREATE TABLE IF NOT EXISTS TEST2(ID INT)"
);
conn
.
close
();
}
catch
(
SQLException
e
)
{
...
...
h2/src/test/org/h2/test/db/TestLob.java
浏览文件 @
572abc02
...
...
@@ -590,10 +590,10 @@ public class TestLob extends TestBase {
len
=
100
;
}
int
star
t
=
1
,
increment
=
19
;
int
firs
t
=
1
,
increment
=
19
;
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST(ID, B, C) VALUES(?, ?, ?)"
);
for
(
int
i
=
star
t
;
i
<
len
;
i
+=
increment
)
{
for
(
int
i
=
firs
t
;
i
<
len
;
i
+=
increment
)
{
int
l
=
i
;
prep
.
setInt
(
1
,
i
);
prep
.
setBinaryStream
(
2
,
getRandomStream
(
l
,
i
),
-
1
);
...
...
@@ -615,7 +615,7 @@ public class TestLob extends TestBase {
}
prep
=
conn
.
prepareStatement
(
"UPDATE TEST SET B=?, C=? WHERE ID=?"
);
for
(
int
i
=
star
t
;
i
<
len
;
i
+=
increment
)
{
for
(
int
i
=
firs
t
;
i
<
len
;
i
+=
increment
)
{
int
l
=
i
;
prep
.
setBinaryStream
(
1
,
getRandomStream
(
l
,
-
i
),
-
1
);
prep
.
setCharacterStream
(
2
,
getRandomReader
(
l
,
-
i
),
-
1
);
...
...
h2/src/test/org/h2/test/db/TestMemoryUsage.java
浏览文件 @
572abc02
...
...
@@ -81,20 +81,20 @@ public class TestMemoryUsage extends TestBase {
return
;
}
deleteDb
(
"memoryUsage"
);
Connection
conn
=
getConnection
(
"memoryUsage"
);
conn
=
getConnection
(
"memoryUsage"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET MAX_LENGTH_INPLACE_LOB 32768"
);
stat
.
execute
(
"SET CACHE_SIZE 8000"
);
stat
.
execute
(
"CREATE TABLE TEST(ID IDENTITY, DATA CLOB)"
);
freeSoftReferences
();
try
{
int
start
=
MemoryUtils
.
getMemoryUsed
();
int
base
=
MemoryUtils
.
getMemoryUsed
();
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
stat
.
execute
(
"INSERT INTO TEST(DATA) SELECT SPACE(32000) FROM SYSTEM_RANGE(1, 200)"
);
freeSoftReferences
();
int
used
=
MemoryUtils
.
getMemoryUsed
();
if
((
used
-
start
)
>
16000
)
{
fail
(
"Used: "
+
(
used
-
start
));
if
((
used
-
base
)
>
16000
)
{
fail
(
"Used: "
+
(
used
-
base
));
}
}
}
finally
{
...
...
@@ -122,7 +122,7 @@ public class TestMemoryUsage extends TestBase {
return
;
}
deleteDb
(
"memoryUsage"
);
Connection
conn
=
getConnection
(
"memoryUsage"
);
conn
=
getConnection
(
"memoryUsage"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar(255))"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(?, space(200))"
);
...
...
@@ -134,13 +134,13 @@ public class TestMemoryUsage extends TestBase {
prep
.
setInt
(
1
,
i
);
prep
.
executeUpdate
();
}
int
start
=
MemoryUtils
.
getMemoryUsed
();
int
base
=
MemoryUtils
.
getMemoryUsed
();
stat
.
execute
(
"create index idx_test_id on test(id)"
);
System
.
gc
();
System
.
gc
();
int
used
=
MemoryUtils
.
getMemoryUsed
();
if
((
used
-
start
)
>
getSize
(
7500
,
12000
))
{
fail
(
"Used: "
+
(
used
-
start
));
if
((
used
-
base
)
>
getSize
(
7500
,
12000
))
{
fail
(
"Used: "
+
(
used
-
base
));
}
stat
.
execute
(
"drop table test"
);
conn
.
close
();
...
...
h2/src/test/org/h2/test/db/TestMultiThread.java
浏览文件 @
572abc02
...
...
@@ -49,9 +49,8 @@ public class TestMultiThread extends TestBase implements Runnable {
}
public
void
test
()
throws
Exception
{
Connection
conn
=
getConnection
();
Statement
stat
=
conn
.
createStatement
();
conn
=
getConnection
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"
);
int
len
=
getSize
(
10
,
200
);
Thread
[]
threads
=
new
Thread
[
len
];
...
...
h2/src/test/org/h2/test/db/TestMultiThreadedKernel.java
浏览文件 @
572abc02
...
...
@@ -50,7 +50,7 @@ public class TestMultiThreadedKernel extends TestBase {
public
void
run
()
{
Connection
conn
=
null
;
try
{
for
(
int
i
=
0
;
i
<
100
&&
!
stop
;
i
++)
{
for
(
int
j
=
0
;
j
<
100
&&
!
stop
;
j
++)
{
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create local temporary table temp(id identity)"
);
...
...
h2/src/test/org/h2/test/db/TestOpenClose.java
浏览文件 @
572abc02
...
...
@@ -145,13 +145,13 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
threads
[
i
]
=
new
Thread
()
{
public
void
run
()
{
try
{
Connection
c
onn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
PreparedStatement
prep
=
c
onn
.
prepareStatement
(
"insert into employee values(?, ?, 0)"
);
Connection
c
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
PreparedStatement
prep
=
c
.
prepareStatement
(
"insert into employee values(?, ?, 0)"
);
int
id
=
getNextId
();
prep
.
setInt
(
1
,
id
);
prep
.
setString
(
2
,
"employee "
+
id
);
prep
.
execute
();
c
onn
.
close
();
c
.
close
();
}
catch
(
Throwable
e
)
{
TestBase
.
logError
(
"insert"
,
e
);
}
...
...
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
浏览文件 @
572abc02
...
...
@@ -270,16 +270,16 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
}
}
public
void
init
(
Connection
conn
,
String
schemaName
,
String
trigger
Name
,
String
tableName
,
boolean
before
,
int
type
)
{
this
.
triggerName
=
trigger
Name
;
public
void
init
(
Connection
conn
,
String
schemaName
,
String
trigger
,
String
tableName
,
boolean
before
,
int
type
)
{
this
.
triggerName
=
trigger
;
if
(!
"TEST"
.
equals
(
tableName
))
{
throw
new
AssertionError
(
"supposed to be TEST"
);
}
if
((
trigger
Name
.
endsWith
(
"AFTER"
)
&&
before
)
||
(
triggerName
.
endsWith
(
"BEFORE"
)
&&
!
before
))
{
throw
new
AssertionError
(
"triggerName: "
+
trigger
Name
+
" before:"
+
before
);
if
((
trigger
.
endsWith
(
"AFTER"
)
&&
before
)
||
(
trigger
.
endsWith
(
"BEFORE"
)
&&
!
before
))
{
throw
new
AssertionError
(
"triggerName: "
+
trigger
+
" before:"
+
before
);
}
if
((
trigger
Name
.
startsWith
(
"UPD"
)
&&
type
!=
UPDATE
)
||
(
triggerName
.
startsWith
(
"INS"
)
&&
type
!=
INSERT
)
||
(
triggerName
.
startsWith
(
"DEL"
)
&&
type
!=
DELETE
))
{
throw
new
AssertionError
(
"triggerName: "
+
trigger
Name
+
" type:"
+
type
);
if
((
trigger
.
startsWith
(
"UPD"
)
&&
type
!=
UPDATE
)
||
(
trigger
.
startsWith
(
"INS"
)
&&
type
!=
INSERT
)
||
(
trigger
.
startsWith
(
"DEL"
)
&&
type
!=
DELETE
))
{
throw
new
AssertionError
(
"triggerName: "
+
trigger
+
" type:"
+
type
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论