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