Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f447a3e4
提交
f447a3e4
authored
9月 01, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code style
上级
aed847e4
显示空白字符变更
内嵌
并排
正在显示
41 个修改的文件
包含
1135 行增加
和
1149 行删除
+1135
-1149
ant-build.properties
h2/ant-build.properties
+2
-2
FileFunctions.java
h2/src/test/org/h2/samples/FileFunctions.java
+1
-1
Function.java
h2/src/test/org/h2/samples/Function.java
+5
-5
FunctionMultiReturn.java
h2/src/test/org/h2/samples/FunctionMultiReturn.java
+10
-10
InitDatabaseFromJar.java
h2/src/test/org/h2/samples/InitDatabaseFromJar.java
+11
-5
MixedMode.java
h2/src/test/org/h2/samples/MixedMode.java
+8
-8
Newsfeed.java
h2/src/test/org/h2/samples/Newsfeed.java
+3
-3
SQLInjection.java
h2/src/test/org/h2/samples/SQLInjection.java
+18
-12
SecurePassword.java
h2/src/test/org/h2/samples/SecurePassword.java
+1
-1
ShowProgress.java
h2/src/test/org/h2/samples/ShowProgress.java
+10
-9
TriggerSample.java
h2/src/test/org/h2/samples/TriggerSample.java
+4
-4
BenchC.java
h2/src/test/org/h2/test/bench/BenchC.java
+67
-73
BenchCThread.java
h2/src/test/org/h2/test/bench/BenchCThread.java
+186
-186
TestAutoRecompile.java
h2/src/test/org/h2/test/db/TestAutoRecompile.java
+4
-4
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+6
-9
TestLobObject.java
h2/src/test/org/h2/test/db/TestLobObject.java
+1
-0
TestSQLInjection.java
h2/src/test/org/h2/test/db/TestSQLInjection.java
+18
-18
TestSpaceReuse.java
h2/src/test/org/h2/test/db/TestSpaceReuse.java
+3
-3
TestSpeed.java
h2/src/test/org/h2/test/db/TestSpeed.java
+334
-334
TestTempTables.java
h2/src/test/org/h2/test/db/TestTempTables.java
+6
-5
TestTransaction.java
h2/src/test/org/h2/test/db/TestTransaction.java
+65
-61
TestTwoPhaseCommit.java
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
+11
-11
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+4
-4
TestBitField.java
h2/src/test/org/h2/test/unit/TestBitField.java
+16
-16
TestCache.java
h2/src/test/org/h2/test/unit/TestCache.java
+5
-5
TestCompress.java
h2/src/test/org/h2/test/unit/TestCompress.java
+12
-14
TestDataPage.java
h2/src/test/org/h2/test/unit/TestDataPage.java
+10
-10
TestExit.java
h2/src/test/org/h2/test/unit/TestExit.java
+21
-27
TestFileLock.java
h2/src/test/org/h2/test/unit/TestFileLock.java
+3
-2
TestIntArray.java
h2/src/test/org/h2/test/unit/TestIntArray.java
+33
-33
TestIntIntHashMap.java
h2/src/test/org/h2/test/unit/TestIntIntHashMap.java
+3
-3
TestOverflow.java
h2/src/test/org/h2/test/unit/TestOverflow.java
+22
-22
TestPattern.java
h2/src/test/org/h2/test/unit/TestPattern.java
+18
-18
TestSampleApps.java
h2/src/test/org/h2/test/unit/TestSampleApps.java
+16
-17
TestScriptReader.java
h2/src/test/org/h2/test/unit/TestScriptReader.java
+39
-40
TestSecurity.java
h2/src/test/org/h2/test/unit/TestSecurity.java
+17
-22
TestStreams.java
h2/src/test/org/h2/test/unit/TestStreams.java
+21
-21
TestStringCache.java
h2/src/test/org/h2/test/unit/TestStringCache.java
+22
-22
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+43
-61
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+44
-36
TestValueHashMap.java
h2/src/test/org/h2/test/unit/TestValueHashMap.java
+12
-12
没有找到文件。
h2/ant-build.properties
浏览文件 @
f447a3e4
#Fri Aug 24 22:06:59 CEST 2007
javac
=
javac
#Sat Sep 01 17:01:19 CEST 2007
benchmark.drivers.dir
=
C
\:
/data/java
javac
=
javac
path.servlet.jar
=
C
\:
/data/classpath/servlet-api.jar
version.name.maven
=
1.0.57
jdk
=
1.4
h2/src/test/org/h2/samples/FileFunctions.java
浏览文件 @
f447a3e4
...
...
@@ -46,7 +46,7 @@ public class FileFunctions {
public
static
byte
[]
readFile
(
String
fileName
)
throws
IOException
{
RandomAccessFile
file
=
new
RandomAccessFile
(
fileName
,
"r"
);
try
{
byte
[]
buff
=
new
byte
[(
int
)
file
.
length
()];
byte
[]
buff
=
new
byte
[(
int
)
file
.
length
()];
file
.
readFully
(
buff
);
return
buff
;
}
finally
{
...
...
h2/src/test/org/h2/samples/Function.java
浏览文件 @
f447a3e4
...
...
@@ -23,9 +23,9 @@ public class Function {
stat
.
execute
(
"CREATE ALIAS IS_PRIME FOR \"org.h2.samples.Function.isPrime\" "
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT IS_PRIME(X), X FROM SYSTEM_RANGE(1, 20) ORDER BY X"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
boolean
isPrime
=
rs
.
getBoolean
(
1
);
if
(
isPrime
)
{
if
(
isPrime
)
{
int
x
=
rs
.
getInt
(
2
);
System
.
out
.
println
(
x
+
" is prime"
);
}
...
...
@@ -53,11 +53,11 @@ public class Function {
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"X"
,
Types
.
INTEGER
,
10
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
INTEGER
,
10
,
0
);
if
(
id
==
null
)
{
if
(
id
==
null
)
{
return
rs
;
}
for
(
int
x
=
0
;
x
<
id
.
intValue
();
x
++)
{
for
(
int
y
=
0
;
y
<
id
.
intValue
();
y
++)
{
for
(
int
x
=
0
;
x
<
id
.
intValue
();
x
++)
{
for
(
int
y
=
0
;
y
<
id
.
intValue
();
y
++)
{
rs
.
addRow
(
new
Object
[]
{
new
Integer
(
x
),
new
Integer
(
y
)
});
}
}
...
...
h2/src/test/org/h2/samples/FunctionMultiReturn.java
浏览文件 @
f447a3e4
...
...
@@ -25,7 +25,7 @@ public class FunctionMultiReturn {
prep
.
setDouble
(
1
,
5.0
);
prep
.
setDouble
(
2
,
0.5
);
ResultSet
rs
=
prep
.
executeQuery
();
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
x
=
rs
.
getDouble
(
1
);
double
y
=
rs
.
getDouble
(
2
);
System
.
out
.
println
(
"result: (x="
+
x
+
", y="
+
y
+
")"
);
...
...
@@ -35,7 +35,7 @@ public class FunctionMultiReturn {
stat
.
execute
(
"INSERT INTO TEST(R, A) VALUES(5.0, 0.5), (10.0, 0.6)"
);
stat
.
execute
(
"CREATE ALIAS P2C_SET FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianSet\" "
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM P2C_SET('SELECT * FROM TEST')"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
"R"
);
double
a
=
rs
.
getDouble
(
"A"
);
double
x
=
rs
.
getDouble
(
"X"
);
...
...
@@ -45,18 +45,18 @@ public class FunctionMultiReturn {
stat
.
execute
(
"CREATE ALIAS P2C_A FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianArray\" "
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, P2C_A(R, A) FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
1
);
double
a
=
rs
.
getDouble
(
2
);
Object
o
=
rs
.
getObject
(
3
);
Object
[]
xy
=
(
Object
[])
o
;
double
x
=
((
Double
)
xy
[
0
]).
doubleValue
();
double
y
=
((
Double
)
xy
[
1
]).
doubleValue
();
System
.
out
.
println
(
"(r="
+
r
+
" a="
+
a
+
") : (x="
+
x
+
", y="
+
y
+
")"
);
double
x
=
((
Double
)
xy
[
0
]).
doubleValue
();
double
y
=
((
Double
)
xy
[
1
]).
doubleValue
();
System
.
out
.
println
(
"(r="
+
r
+
" a="
+
a
+
") : (x="
+
x
+
", y="
+
y
+
")"
);
}
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, ARRAY_GET(E, 1), ARRAY_GET(E, 2) FROM (SELECT R, A, P2C_A(R, A) E FROM TEST)"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
1
);
double
a
=
rs
.
getDouble
(
2
);
double
x
=
rs
.
getDouble
(
3
);
...
...
@@ -75,7 +75,7 @@ public class FunctionMultiReturn {
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
if
(
r
!=
null
&&
alpha
!=
null
)
{
if
(
r
!=
null
&&
alpha
!=
null
)
{
double
x
=
r
.
doubleValue
()
*
Math
.
cos
(
alpha
.
doubleValue
());
double
y
=
r
.
doubleValue
()
*
Math
.
sin
(
alpha
.
doubleValue
());
rs
.
addRow
(
new
Object
[]
{
new
Double
(
x
),
new
Double
(
y
)
});
...
...
@@ -99,9 +99,9 @@ public class FunctionMultiReturn {
result
.
addColumn
(
"A"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
if
(
query
!=
null
)
{
if
(
query
!=
null
)
{
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
query
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
"R"
);
double
alpha
=
rs
.
getDouble
(
"A"
);
double
x
=
r
*
Math
.
cos
(
alpha
);
...
...
h2/src/test/org/h2/samples/InitDatabaseFromJar.java
浏览文件 @
f447a3e4
...
...
@@ -4,8 +4,13 @@
*/
package
org
.
h2
.
samples
;
import
java.io.*
;
import
java.sql.*
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
org.h2.tools.RunScript
;
public
class
InitDatabaseFromJar
{
...
...
@@ -29,12 +34,13 @@ public class InitDatabaseFromJar {
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test"
);
InputStream
in
=
getClass
().
getResourceAsStream
(
"script.sql"
);
if
(
in
==
null
)
{
System
.
out
.
println
(
"Please add the file script.sql to the classpath, package "
+
getClass
().
getPackage
().
getName
());
if
(
in
==
null
)
{
System
.
out
.
println
(
"Please add the file script.sql to the classpath, package "
+
getClass
().
getPackage
().
getName
());
}
else
{
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
));
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
));
}
conn
.
close
();
...
...
h2/src/test/org/h2/samples/MixedMode.java
浏览文件 @
f447a3e4
...
...
@@ -30,12 +30,12 @@ public class MixedMode {
System
.
out
.
println
(
"Execute this a few times: SELECT TIME FROM TIMER"
);
System
.
out
.
println
(
"To stop this application (and the server), run: DROP TABLE TIMER"
);
try
{
while
(
true
)
{
while
(
true
)
{
// runs forever, except if you drop the table remotely
stat
.
execute
(
"MERGE INTO TIMER VALUES(1, NOW())"
);
Thread
.
sleep
(
1000
);
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
.
toString
());
}
conn
.
close
();
...
...
h2/src/test/org/h2/samples/Newsfeed.java
浏览文件 @
f447a3e4
...
...
@@ -22,10 +22,10 @@ public class Newsfeed {
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:"
,
"sa"
,
""
);
InputStream
in
=
Newsfeed
.
class
.
getResourceAsStream
(
"newsfeed.sql"
);
ResultSet
rs
=
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
,
"ISO-8859-1"
));
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
String
file
=
rs
.
getString
(
"FILE"
);
String
content
=
rs
.
getString
(
"CONTENT"
);
if
(
file
.
equals
(
"-newsletter-"
))
{
if
(
file
.
equals
(
"-newsletter-"
))
{
System
.
out
.
println
(
convertHtml2Text
(
content
));
}
else
{
FileOutputStream
out
=
new
FileOutputStream
(
file
);
...
...
@@ -52,7 +52,7 @@ public class Newsfeed {
s
=
StringUtils
.
replaceAll
(
s
,
"<br />"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br/>"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br>"
,
""
);
if
(
s
.
indexOf
(
'<'
)
>=
0
||
s
.
indexOf
(
'>'
)
>=
0
)
{
if
(
s
.
indexOf
(
'<'
)
>=
0
||
s
.
indexOf
(
'>'
)
>=
0
)
{
throw
new
Error
(
"Unsupported HTML Tag: < or > in "
+
s
);
}
return
s
;
...
...
h2/src/test/org/h2/samples/SQLInjection.java
浏览文件 @
f447a3e4
...
...
@@ -4,8 +4,14 @@
*/
package
org
.
h2
.
samples
;
import
java.io.*
;
import
java.sql.*
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
SQLInjection
{
...
...
@@ -43,14 +49,14 @@ public class SQLInjection {
// loginByNameInsecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
// loginStoredProcedureInsecure();
limitRowAccess
();
}
// loginByNameSecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
stat
.
execute
(
"SET ALLOW_LITERALS NUMBERS"
);
stat
.
execute
(
"SET ALLOW_LITERALS ALL"
);
...
...
@@ -75,7 +81,7 @@ public class SQLInjection {
listActiveItems
();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_INACTIVE"
);
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_ACTIVE"
);
stat
.
execute
(
"CREATE CONSTANT TYPE_INACTIVE VALUE 0"
);
...
...
@@ -86,7 +92,7 @@ public class SQLInjection {
// listItemsSortedInsecure();
// listItemsSortedSecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
listItemsSortedSecureParam
();
// storePasswordHashWithSalt();
}
...
...
@@ -188,7 +194,7 @@ public class SQLInjection {
}
else
{
System
.
out
.
println
(
"Access denied!"
);
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -209,7 +215,7 @@ public class SQLInjection {
}
else
{
System
.
out
.
println
(
"Access denied!"
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -241,7 +247,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -258,7 +264,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -274,7 +280,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
h2/src/test/org/h2/samples/SecurePassword.java
浏览文件 @
f447a3e4
...
...
@@ -39,7 +39,7 @@ public class SecurePassword {
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
"NAME"
));
}
conn
.
close
();
...
...
h2/src/test/org/h2/samples/ShowProgress.java
浏览文件 @
f447a3e4
...
...
@@ -35,21 +35,21 @@ public class ShowProgress implements DatabaseEventListener {
long
time
;
time
=
System
.
currentTimeMillis
();
int
len
=
1000
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
long
last
=
System
.
currentTimeMillis
();
if
(
last
>
time
+
1000
)
{
if
(
last
>
time
+
1000
)
{
time
=
last
;
System
.
out
.
println
(
"Inserting "
+
(
100L
*
i
/
len
)
+
"%"
);
System
.
out
.
println
(
"Inserting "
+
(
100L
*
i
/
len
)
+
"%"
);
}
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
}
boolean
abnormalTermination
=
true
;
if
(
abnormalTermination
)
{
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
if
(
abnormalTermination
)
{
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
try
{
stat
.
execute
(
"INSERT INTO TEST VALUES(-1, 'Test' || SPACE(100))"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
}
}
else
{
conn
.
close
();
...
...
@@ -75,12 +75,12 @@ public class ShowProgress implements DatabaseEventListener {
public
void
setProgress
(
int
state
,
String
name
,
int
current
,
int
max
)
{
long
time
=
System
.
currentTimeMillis
();
if
(
time
<
last
+
5000
)
{
if
(
time
<
last
+
5000
)
{
return
;
}
last
=
time
;
String
stateName
=
"?"
;
switch
(
state
)
{
switch
(
state
)
{
case
STATE_SCAN_FILE:
stateName
=
"Scan "
+
name
;
break
;
...
...
@@ -95,7 +95,8 @@ public class ShowProgress implements DatabaseEventListener {
Thread
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
}
System
.
out
.
println
(
"State: "
+
stateName
+
" "
+
(
100
*
current
/
max
)
+
"% ("
+
current
+
" of "
+
max
+
") "
+
(
time
-
start
)+
" ms"
);
System
.
out
.
println
(
"State: "
+
stateName
+
" "
+
(
100
*
current
/
max
)
+
"% ("
+
current
+
" of "
+
max
+
") "
+
(
time
-
start
)
+
" ms"
);
}
public
void
closingDatabase
()
{
...
...
h2/src/test/org/h2/samples/TriggerSample.java
浏览文件 @
f447a3e4
...
...
@@ -49,11 +49,11 @@ public class TriggerSample {
Object
[]
oldRow
,
Object
[]
newRow
)
throws
SQLException
{
BigDecimal
diff
=
null
;
if
(
newRow
!=
null
)
{
diff
=
(
BigDecimal
)
newRow
[
1
];
if
(
newRow
!=
null
)
{
diff
=
(
BigDecimal
)
newRow
[
1
];
}
if
(
oldRow
!=
null
)
{
BigDecimal
m
=
(
BigDecimal
)
oldRow
[
1
];
if
(
oldRow
!=
null
)
{
BigDecimal
m
=
(
BigDecimal
)
oldRow
[
1
];
diff
=
diff
==
null
?
m
.
negate
()
:
diff
.
subtract
(
m
);
}
PreparedStatement
prep
=
conn
.
prepareStatement
(
...
...
h2/src/test/org/h2/test/bench/BenchC.java
浏览文件 @
f447a3e4
...
...
@@ -226,8 +226,6 @@ public class BenchC implements Bench {
PreparedStatement
prepHistory
=
db
.
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 (?, ?, ?, ?, ?, ?, ?, ?)"
);
for
(
int
cId
=
1
;
cId
<=
customersPerDistrict
;
cId
++)
{
int
c_d_id
=
dId
;
int
c_w_id
=
wId
;
String
first
=
random
.
getString
(
8
,
16
);
String
middle
=
"OE"
;
String
last
;
...
...
@@ -257,8 +255,8 @@ public class BenchC implements Bench {
int
paymentCnt
=
1
;
int
deliveryCnt
=
1
;
prepCustomer
.
setInt
(
1
,
cId
);
prepCustomer
.
setInt
(
2
,
c_d_i
d
);
prepCustomer
.
setInt
(
3
,
c_w_i
d
);
prepCustomer
.
setInt
(
2
,
dI
d
);
prepCustomer
.
setInt
(
3
,
wI
d
);
prepCustomer
.
setString
(
4
,
first
);
prepCustomer
.
setString
(
5
,
middle
);
prepCustomer
.
setString
(
6
,
last
);
...
...
@@ -281,10 +279,10 @@ public class BenchC implements Bench {
BigDecimal
amount
=
new
BigDecimal
(
"10.00"
);
String
hData
=
random
.
getString
(
12
,
24
);
prepHistory
.
setInt
(
1
,
cId
);
prepHistory
.
setInt
(
2
,
c_d_i
d
);
prepHistory
.
setInt
(
3
,
c_w_i
d
);
prepHistory
.
setInt
(
4
,
c_w_i
d
);
prepHistory
.
setInt
(
5
,
c_d_i
d
);
prepHistory
.
setInt
(
2
,
dI
d
);
prepHistory
.
setInt
(
3
,
wI
d
);
prepHistory
.
setInt
(
4
,
wI
d
);
prepHistory
.
setInt
(
5
,
dI
d
);
prepHistory
.
setTimestamp
(
6
,
timestamp
);
prepHistory
.
setBigDecimal
(
7
,
amount
);
prepHistory
.
setString
(
8
,
hData
);
...
...
@@ -305,8 +303,6 @@ public class BenchC implements Bench {
}
private
void
loadOrderSub
(
int
dId
,
int
wId
)
throws
Exception
{
int
o_d_id
=
dId
;
int
o_w_id
=
wId
;
Timestamp
timestamp
=
new
Timestamp
(
System
.
currentTimeMillis
());
int
[]
orderid
=
random
.
getPermutation
(
ordersPerDistrict
);
PreparedStatement
prepOrder
=
db
.
prepare
(
"INSERT INTO ORDERS(O_ID, O_C_ID, O_D_ID, O_W_ID, "
...
...
@@ -317,46 +313,46 @@ public class BenchC implements Bench {
+
"OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, "
+
"OL_DIST_INFO, OL_DELIVERY_D)"
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)"
);
for
(
int
oId
=
1
,
i
=
0
;
oId
<=
ordersPerDistrict
;
oId
++)
{
int
o_c_i
d
=
orderid
[
oId
-
1
];
int
o_carrier_i
d
=
random
.
getInt
(
1
,
10
);
int
o
_ol_c
nt
=
random
.
getInt
(
5
,
15
);
int
cI
d
=
orderid
[
oId
-
1
];
int
carrierI
d
=
random
.
getInt
(
1
,
10
);
int
o
lC
nt
=
random
.
getInt
(
5
,
15
);
prepOrder
.
setInt
(
1
,
oId
);
prepOrder
.
setInt
(
2
,
o_c_i
d
);
prepOrder
.
setInt
(
3
,
o_d_i
d
);
prepOrder
.
setInt
(
4
,
o_w_i
d
);
prepOrder
.
setInt
(
2
,
cI
d
);
prepOrder
.
setInt
(
3
,
dI
d
);
prepOrder
.
setInt
(
4
,
wI
d
);
prepOrder
.
setTimestamp
(
5
,
timestamp
);
prepOrder
.
setInt
(
7
,
o
_ol_c
nt
);
prepOrder
.
setInt
(
7
,
o
lC
nt
);
if
(
oId
<=
2100
)
{
prepOrder
.
setInt
(
6
,
o_carrier_i
d
);
prepOrder
.
setInt
(
6
,
carrierI
d
);
}
else
{
// the last 900 orders have not been delivered
prepOrder
.
setNull
(
6
,
Types
.
INTEGER
);
prepNewOrder
.
setInt
(
1
,
oId
);
prepNewOrder
.
setInt
(
2
,
o_d_i
d
);
prepNewOrder
.
setInt
(
3
,
o_w_i
d
);
prepNewOrder
.
setInt
(
2
,
dI
d
);
prepNewOrder
.
setInt
(
3
,
wI
d
);
db
.
update
(
prepNewOrder
,
"newNewOrder"
);
}
db
.
update
(
prepOrder
,
"insertOrder"
);
for
(
int
ol
=
1
;
ol
<=
o
_ol_c
nt
;
ol
++)
{
int
ol_i_
id
=
random
.
getInt
(
1
,
items
);
int
ol_supply_w_id
=
o_w_i
d
;
int
ol_
quantity
=
5
;
String
ol_dist_i
nfo
=
random
.
getString
(
24
);
BigDecimal
ol_
amount
;
for
(
int
ol
=
1
;
ol
<=
o
lC
nt
;
ol
++)
{
int
id
=
random
.
getInt
(
1
,
items
);
int
supplyId
=
wI
d
;
int
quantity
=
5
;
String
distI
nfo
=
random
.
getString
(
24
);
BigDecimal
amount
;
if
(
oId
<
2101
)
{
ol_
amount
=
random
.
getBigDecimal
(
0
,
2
);
amount
=
random
.
getBigDecimal
(
0
,
2
);
}
else
{
ol_
amount
=
random
.
getBigDecimal
(
random
.
getInt
(
0
,
1000000
),
2
);
amount
=
random
.
getBigDecimal
(
random
.
getInt
(
0
,
1000000
),
2
);
}
prepLine
.
setInt
(
1
,
oId
);
prepLine
.
setInt
(
2
,
o_d_i
d
);
prepLine
.
setInt
(
3
,
o_w_i
d
);
prepLine
.
setInt
(
2
,
dI
d
);
prepLine
.
setInt
(
3
,
wI
d
);
prepLine
.
setInt
(
4
,
ol
);
prepLine
.
setInt
(
5
,
ol_i_
id
);
prepLine
.
setInt
(
6
,
ol_supply_w_i
d
);
prepLine
.
setInt
(
7
,
ol_
quantity
);
prepLine
.
setBigDecimal
(
8
,
ol_
amount
);
prepLine
.
setString
(
9
,
ol_dist_i
nfo
);
prepLine
.
setInt
(
5
,
id
);
prepLine
.
setInt
(
6
,
supplyI
d
);
prepLine
.
setInt
(
7
,
quantity
);
prepLine
.
setBigDecimal
(
8
,
amount
);
prepLine
.
setString
(
9
,
distI
nfo
);
db
.
update
(
prepLine
,
"insertOrderLine"
);
if
(
i
++
%
commitEvery
==
0
)
{
db
.
commit
();
...
...
@@ -367,58 +363,56 @@ public class BenchC implements Bench {
private
void
loadStock
(
int
wId
)
throws
Exception
{
trace
(
"load stock (warehouse "
+
wId
+
")"
);
int
s_w_id
=
wId
;
boolean
[]
original
=
random
.
getBoolean
(
items
,
items
/
10
);
PreparedStatement
prep
=
db
.
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, "
+
"S_DATA, S_YTD, S_ORDER_CNT, S_REMOTE_CNT) "
+
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
for
(
int
s_i_id
=
1
;
s_i_id
<=
items
;
s_i_
id
++)
{
int
s_
quantity
=
random
.
getInt
(
10
,
100
);
String
s_dist_
01
=
random
.
getString
(
24
);
String
s_dist_
02
=
random
.
getString
(
24
);
String
s_dist_
03
=
random
.
getString
(
24
);
String
s_dist_
04
=
random
.
getString
(
24
);
String
s_dist_
05
=
random
.
getString
(
24
);
String
s_dist_
06
=
random
.
getString
(
24
);
String
s_dist_
07
=
random
.
getString
(
24
);
String
s_dist_
08
=
random
.
getString
(
24
);
String
s_dist_
09
=
random
.
getString
(
24
);
String
s_dist_
10
=
random
.
getString
(
24
);
String
s_
data
=
random
.
getString
(
26
,
50
);
if
(
original
[
s_i_
id
-
1
])
{
s_data
=
random
.
replace
(
s_
data
,
"original"
);
}
prep
.
setInt
(
1
,
s_i_
id
);
prep
.
setInt
(
2
,
s_w_i
d
);
prep
.
setInt
(
3
,
s_
quantity
);
prep
.
setString
(
4
,
s_dist_
01
);
prep
.
setString
(
5
,
s_dist_
02
);
prep
.
setString
(
6
,
s_dist_
03
);
prep
.
setString
(
7
,
s_dist_
04
);
prep
.
setString
(
8
,
s_dist_
05
);
prep
.
setString
(
9
,
s_dist_
06
);
prep
.
setString
(
10
,
s_dist_
07
);
prep
.
setString
(
11
,
s_dist_
08
);
prep
.
setString
(
12
,
s_dist_
09
);
prep
.
setString
(
13
,
s_dist_
10
);
prep
.
setString
(
14
,
s_
data
);
for
(
int
id
=
1
;
id
<=
items
;
id
++)
{
int
quantity
=
random
.
getInt
(
10
,
100
);
String
dist
01
=
random
.
getString
(
24
);
String
dist
02
=
random
.
getString
(
24
);
String
dist
03
=
random
.
getString
(
24
);
String
dist
04
=
random
.
getString
(
24
);
String
dist
05
=
random
.
getString
(
24
);
String
dist
06
=
random
.
getString
(
24
);
String
dist
07
=
random
.
getString
(
24
);
String
dist
08
=
random
.
getString
(
24
);
String
dist
09
=
random
.
getString
(
24
);
String
dist
10
=
random
.
getString
(
24
);
String
data
=
random
.
getString
(
26
,
50
);
if
(
original
[
id
-
1
])
{
data
=
random
.
replace
(
data
,
"original"
);
}
prep
.
setInt
(
1
,
id
);
prep
.
setInt
(
2
,
wI
d
);
prep
.
setInt
(
3
,
quantity
);
prep
.
setString
(
4
,
dist
01
);
prep
.
setString
(
5
,
dist
02
);
prep
.
setString
(
6
,
dist
03
);
prep
.
setString
(
7
,
dist
04
);
prep
.
setString
(
8
,
dist
05
);
prep
.
setString
(
9
,
dist
06
);
prep
.
setString
(
10
,
dist
07
);
prep
.
setString
(
11
,
dist
08
);
prep
.
setString
(
12
,
dist
09
);
prep
.
setString
(
13
,
dist
10
);
prep
.
setString
(
14
,
data
);
prep
.
setInt
(
15
,
0
);
prep
.
setInt
(
16
,
0
);
prep
.
setInt
(
17
,
0
);
db
.
update
(
prep
,
"insertStock"
);
if
(
s_i_
id
%
commitEvery
==
0
)
{
if
(
id
%
commitEvery
==
0
)
{
db
.
commit
();
}
trace
(
s_i_
id
,
items
);
trace
(
id
,
items
);
}
}
private
void
loadDistrict
(
int
wId
)
throws
Exception
{
int
d_w_id
=
wId
;
BigDecimal
d_ytd
=
new
BigDecimal
(
"300000.00"
);
int
d_next_o_id
=
3001
;
BigDecimal
ytd
=
new
BigDecimal
(
"300000.00"
);
int
nextId
=
3001
;
PreparedStatement
prep
=
db
.
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) "
+
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
...
...
@@ -432,7 +426,7 @@ public class BenchC implements Bench {
String
zip
=
address
[
4
];
BigDecimal
tax
=
random
.
getBigDecimal
(
random
.
getInt
(
0
,
2000
),
4
);
prep
.
setInt
(
1
,
dId
);
prep
.
setInt
(
2
,
d_w_i
d
);
prep
.
setInt
(
2
,
wI
d
);
prep
.
setString
(
3
,
name
);
prep
.
setString
(
4
,
street1
);
prep
.
setString
(
5
,
street2
);
...
...
@@ -440,8 +434,8 @@ public class BenchC implements Bench {
prep
.
setString
(
7
,
state
);
prep
.
setString
(
8
,
zip
);
prep
.
setBigDecimal
(
9
,
tax
);
prep
.
setBigDecimal
(
10
,
d_
ytd
);
prep
.
setInt
(
11
,
d_next_o_i
d
);
prep
.
setBigDecimal
(
10
,
ytd
);
prep
.
setInt
(
11
,
nextI
d
);
db
.
update
(
prep
,
"insertDistrict"
);
trace
(
dId
,
districtsPerWarehouse
);
}
...
...
h2/src/test/org/h2/test/bench/BenchCThread.java
浏览文件 @
f447a3e4
...
...
@@ -72,55 +72,55 @@ public class BenchCThread {
}
private
void
processNewOrder
()
throws
Exception
{
int
d
_i
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
int
c
_i
d
=
random
.
getNonUniform
(
1023
,
1
,
bench
.
customersPerDistrict
);
int
o
_ol_c
nt
=
random
.
getInt
(
5
,
15
);
int
d
I
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
int
c
I
d
=
random
.
getNonUniform
(
1023
,
1
,
bench
.
customersPerDistrict
);
int
o
lC
nt
=
random
.
getInt
(
5
,
15
);
boolean
rollback
=
random
.
getInt
(
1
,
100
)
==
1
;
int
[]
supply
_w_id
=
new
int
[
o_ol_c
nt
];
int
[]
item
_id
=
new
int
[
o_ol_c
nt
];
int
[]
quantity
=
new
int
[
o
_ol_c
nt
];
int
o_all_l
ocal
=
1
;
for
(
int
i
=
0
;
i
<
o
_ol_c
nt
;
i
++)
{
int
[]
supply
Id
=
new
int
[
olC
nt
];
int
[]
item
Id
=
new
int
[
olC
nt
];
int
[]
quantity
=
new
int
[
o
lC
nt
];
int
allL
ocal
=
1
;
for
(
int
i
=
0
;
i
<
o
lC
nt
;
i
++)
{
int
w
;
if
(
bench
.
warehouses
>
1
&&
random
.
getInt
(
1
,
100
)
==
1
)
{
do
{
w
=
random
.
getInt
(
1
,
bench
.
warehouses
);
}
while
(
w
!=
warehouseId
);
o_all_l
ocal
=
0
;
allL
ocal
=
0
;
}
else
{
w
=
warehouseId
;
}
supply
_w_i
d
[
i
]
=
w
;
supply
I
d
[
i
]
=
w
;
int
item
;
if
(
rollback
&&
i
==
o
_ol_c
nt
-
1
)
{
if
(
rollback
&&
i
==
o
lC
nt
-
1
)
{
// unused order number
item
=
-
1
;
}
else
{
item
=
random
.
getNonUniform
(
8191
,
1
,
bench
.
items
);
}
item
_i
d
[
i
]
=
item
;
item
I
d
[
i
]
=
item
;
quantity
[
i
]
=
random
.
getInt
(
1
,
10
);
}
char
[]
bg
=
new
char
[
o
_ol_c
nt
];
int
[]
stock
=
new
int
[
o
_ol_c
nt
];
BigDecimal
[]
amt
=
new
BigDecimal
[
o
_ol_c
nt
];
char
[]
bg
=
new
char
[
o
lC
nt
];
int
[]
stock
=
new
int
[
o
lC
nt
];
BigDecimal
[]
amt
=
new
BigDecimal
[
o
lC
nt
];
Timestamp
datetime
=
new
Timestamp
(
System
.
currentTimeMillis
());
PreparedStatement
prep
;
ResultSet
rs
;
prep
=
prepare
(
"UPDATE DISTRICT SET D_NEXT_O_ID=D_NEXT_O_ID+1 "
+
"WHERE D_ID=? AND D_W_ID=?"
);
prep
.
setInt
(
1
,
d
_i
d
);
prep
.
setInt
(
1
,
d
I
d
);
prep
.
setInt
(
2
,
warehouseId
);
db
.
update
(
prep
,
"updateDistrict"
);
prep
=
prepare
(
"SELECT D_NEXT_O_ID, D_TAX FROM DISTRICT "
+
"WHERE D_ID=? AND D_W_ID=?"
);
prep
.
setInt
(
1
,
d
_i
d
);
prep
.
setInt
(
1
,
d
I
d
);
prep
.
setInt
(
2
,
warehouseId
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
int
o
_i
d
=
rs
.
getInt
(
1
)
-
1
;
BigDecimal
d_
tax
=
rs
.
getBigDecimal
(
2
);
int
o
I
d
=
rs
.
getInt
(
1
)
-
1
;
BigDecimal
tax
=
rs
.
getBigDecimal
(
2
);
rs
.
close
();
// TODO optimizer: such cases can be optimized! A=1 AND B=A means
// also B=1!
...
...
@@ -130,24 +130,24 @@ public class BenchCThread {
prep
=
prepare
(
"SELECT C_DISCOUNT, C_LAST, C_CREDIT, W_TAX "
+
"FROM CUSTOMER, WAREHOUSE "
+
"WHERE C_ID=? AND C_W_ID=? AND C_W_ID=W_ID AND C_D_ID=?"
);
prep
.
setInt
(
1
,
c
_i
d
);
prep
.
setInt
(
1
,
c
I
d
);
prep
.
setInt
(
2
,
warehouseId
);
prep
.
setInt
(
3
,
d
_i
d
);
prep
.
setInt
(
3
,
d
I
d
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
BigDecimal
c_
discount
=
rs
.
getBigDecimal
(
1
);
BigDecimal
discount
=
rs
.
getBigDecimal
(
1
);
rs
.
getString
(
2
);
// c_last
rs
.
getString
(
3
);
// c_credit
BigDecimal
w
_t
ax
=
rs
.
getBigDecimal
(
4
);
BigDecimal
w
T
ax
=
rs
.
getBigDecimal
(
4
);
rs
.
close
();
BigDecimal
total
=
new
BigDecimal
(
"0"
);
for
(
int
ol_number
=
1
;
ol_number
<=
o_ol_cnt
;
ol_
number
++)
{
int
ol
_i_id
=
item_id
[
ol_
number
-
1
];
int
ol
_supply_w_id
=
supply_w_id
[
ol_
number
-
1
];
int
ol
_quantity
=
quantity
[
ol_
number
-
1
];
for
(
int
number
=
1
;
number
<=
olCnt
;
number
++)
{
int
ol
Id
=
itemId
[
number
-
1
];
int
ol
SupplyId
=
supplyId
[
number
-
1
];
int
ol
Quantity
=
quantity
[
number
-
1
];
prep
=
prepare
(
"SELECT I_PRICE, I_NAME, I_DATA "
+
"FROM ITEM WHERE I_ID=?"
);
prep
.
setInt
(
1
,
ol
_i_i
d
);
prep
.
setInt
(
1
,
ol
I
d
);
rs
=
db
.
query
(
prep
);
if
(!
rs
.
next
())
{
if
(
rollback
)
{
...
...
@@ -155,19 +155,19 @@ public class BenchCThread {
db
.
rollback
();
return
;
}
throw
new
Exception
(
"item not found: "
+
ol
_i_i
d
+
" "
+
ol
_supply_w_i
d
);
throw
new
Exception
(
"item not found: "
+
ol
I
d
+
" "
+
ol
SupplyI
d
);
}
BigDecimal
i_
price
=
rs
.
getBigDecimal
(
1
);
BigDecimal
price
=
rs
.
getBigDecimal
(
1
);
rs
.
getString
(
2
);
// i_name
String
i_
data
=
rs
.
getString
(
3
);
String
data
=
rs
.
getString
(
3
);
rs
.
close
();
prep
=
prepare
(
"SELECT S_QUANTITY, S_DATA, "
+
"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 "
+
"FROM STOCK WHERE S_I_ID=? AND S_W_ID=?"
);
prep
.
setInt
(
1
,
ol
_i_i
d
);
prep
.
setInt
(
2
,
ol
_supply_w_i
d
);
prep
.
setInt
(
1
,
ol
I
d
);
prep
.
setInt
(
2
,
ol
SupplyI
d
);
rs
=
db
.
query
(
prep
);
if
(!
rs
.
next
())
{
if
(
rollback
)
{
...
...
@@ -175,100 +175,100 @@ public class BenchCThread {
db
.
rollback
();
return
;
}
throw
new
Exception
(
"item not found: "
+
ol
_i_i
d
+
" "
+
ol
_supply_w_i
d
);
throw
new
Exception
(
"item not found: "
+
ol
I
d
+
" "
+
ol
SupplyI
d
);
}
int
s
_q
uantity
=
rs
.
getInt
(
1
);
String
s
_d
ata
=
rs
.
getString
(
2
);
String
[]
s_
dist
=
new
String
[
10
];
int
s
Q
uantity
=
rs
.
getInt
(
1
);
String
s
D
ata
=
rs
.
getString
(
2
);
String
[]
dist
=
new
String
[
10
];
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
s_
dist
[
i
]
=
rs
.
getString
(
3
+
i
);
dist
[
i
]
=
rs
.
getString
(
3
+
i
);
}
rs
.
close
();
String
ol_dist_info
=
s_dist
[
d_i
d
-
1
];
stock
[
ol_number
-
1
]
=
s_q
uantity
;
if
((
i_
data
.
indexOf
(
"original"
)
!=
-
1
)
&&
(
s
_d
ata
.
indexOf
(
"original"
)
!=
-
1
))
{
bg
[
ol_
number
-
1
]
=
'B'
;
String
distInfo
=
dist
[
dI
d
-
1
];
stock
[
number
-
1
]
=
sQ
uantity
;
if
((
data
.
indexOf
(
"original"
)
!=
-
1
)
&&
(
s
D
ata
.
indexOf
(
"original"
)
!=
-
1
))
{
bg
[
number
-
1
]
=
'B'
;
}
else
{
bg
[
ol_
number
-
1
]
=
'G'
;
bg
[
number
-
1
]
=
'G'
;
}
if
(
s
_quantity
>
ol_q
uantity
)
{
s
_quantity
=
s_quantity
-
ol_q
uantity
;
if
(
s
Quantity
>
olQ
uantity
)
{
s
Quantity
=
sQuantity
-
olQ
uantity
;
}
else
{
s
_quantity
=
s_quantity
-
ol_q
uantity
+
91
;
s
Quantity
=
sQuantity
-
olQ
uantity
+
91
;
}
prep
=
prepare
(
"UPDATE STOCK SET S_QUANTITY=? "
+
"WHERE S_W_ID=? AND S_I_ID=?"
);
prep
.
setInt
(
1
,
s
_q
uantity
);
prep
.
setInt
(
2
,
ol
_supply_w_i
d
);
prep
.
setInt
(
3
,
ol
_i_i
d
);
prep
.
setInt
(
1
,
s
Q
uantity
);
prep
.
setInt
(
2
,
ol
SupplyI
d
);
prep
.
setInt
(
3
,
ol
I
d
);
db
.
update
(
prep
,
"updateStock"
);
BigDecimal
ol
_amount
=
new
BigDecimal
(
ol_q
uantity
).
multiply
(
i_price
).
multiply
(
ONE
.
add
(
w_tax
).
add
(
d_
tax
)).
multiply
(
ONE
.
subtract
(
c_
discount
));
ol
_amount
=
ol_a
mount
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
amt
[
ol_number
-
1
]
=
ol_a
mount
;
total
=
total
.
add
(
ol
_a
mount
);
BigDecimal
ol
Amount
=
new
BigDecimal
(
olQ
uantity
).
multiply
(
price
).
multiply
(
ONE
.
add
(
wTax
).
add
(
tax
)).
multiply
(
ONE
.
subtract
(
discount
));
ol
Amount
=
olA
mount
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
amt
[
number
-
1
]
=
olA
mount
;
total
=
total
.
add
(
ol
A
mount
);
prep
=
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, OL_DIST_INFO) "
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
prep
.
setInt
(
1
,
o
_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
o
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
prep
.
setInt
(
4
,
ol_
number
);
prep
.
setInt
(
5
,
ol
_i_i
d
);
prep
.
setInt
(
6
,
ol
_supply_w_i
d
);
prep
.
setInt
(
7
,
ol
_q
uantity
);
prep
.
setBigDecimal
(
8
,
ol
_a
mount
);
prep
.
setString
(
9
,
ol_dist_i
nfo
);
prep
.
setInt
(
4
,
number
);
prep
.
setInt
(
5
,
ol
I
d
);
prep
.
setInt
(
6
,
ol
SupplyI
d
);
prep
.
setInt
(
7
,
ol
Q
uantity
);
prep
.
setBigDecimal
(
8
,
ol
A
mount
);
prep
.
setString
(
9
,
distI
nfo
);
db
.
update
(
prep
,
"insertOrderLine"
);
}
prep
=
prepare
(
"INSERT INTO ORDERS (O_ID, O_D_ID, O_W_ID, O_C_ID, "
+
"O_ENTRY_D, O_OL_CNT, O_ALL_LOCAL) "
+
"VALUES (?, ?, ?, ?, ?, ?, ?)"
);
prep
.
setInt
(
1
,
o
_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
o
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
prep
.
setInt
(
4
,
c
_i
d
);
prep
.
setInt
(
4
,
c
I
d
);
prep
.
setTimestamp
(
5
,
datetime
);
prep
.
setInt
(
6
,
o
_ol_c
nt
);
prep
.
setInt
(
7
,
o_all_l
ocal
);
prep
.
setInt
(
6
,
o
lC
nt
);
prep
.
setInt
(
7
,
allL
ocal
);
db
.
update
(
prep
,
"insertOrders"
);
prep
=
prepare
(
"INSERT INTO NEW_ORDER (NO_O_ID, NO_D_ID, NO_W_ID) "
+
"VALUES (?, ?, ?)"
);
prep
.
setInt
(
1
,
o
_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
o
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
db
.
update
(
prep
,
"insertNewOrder"
);
db
.
commit
();
}
private
void
processPayment
()
throws
Exception
{
int
d
_i
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
int
c_w_id
,
c_d_i
d
;
int
d
I
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
int
wId
,
cdI
d
;
if
(
bench
.
warehouses
>
1
&&
random
.
getInt
(
1
,
100
)
<=
15
)
{
do
{
c_w_i
d
=
random
.
getInt
(
1
,
bench
.
warehouses
);
}
while
(
c_w_i
d
!=
warehouseId
);
c
_d_i
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
wI
d
=
random
.
getInt
(
1
,
bench
.
warehouses
);
}
while
(
wI
d
!=
warehouseId
);
c
dI
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
}
else
{
c_w_i
d
=
warehouseId
;
c
_d_id
=
d_i
d
;
wI
d
=
warehouseId
;
c
dId
=
dI
d
;
}
boolean
byName
;
String
c_
last
;
int
c
_i
d
=
1
;
String
last
;
int
c
I
d
=
1
;
if
(
random
.
getInt
(
1
,
100
)
<=
60
)
{
byName
=
true
;
c_
last
=
random
.
getLastname
(
random
.
getNonUniform
(
255
,
0
,
999
));
last
=
random
.
getLastname
(
random
.
getNonUniform
(
255
,
0
,
999
));
}
else
{
byName
=
false
;
c_
last
=
""
;
c
_i
d
=
random
.
getNonUniform
(
1023
,
1
,
bench
.
customersPerDistrict
);
last
=
""
;
c
I
d
=
random
.
getNonUniform
(
1023
,
1
,
bench
.
customersPerDistrict
);
}
BigDecimal
h_
amount
=
random
.
getBigDecimal
(
random
.
getInt
(
100
,
500000
),
BigDecimal
amount
=
random
.
getBigDecimal
(
random
.
getInt
(
100
,
500000
),
2
);
Timestamp
datetime
=
new
Timestamp
(
System
.
currentTimeMillis
());
PreparedStatement
prep
;
...
...
@@ -276,12 +276,12 @@ public class BenchCThread {
prep
=
prepare
(
"UPDATE DISTRICT SET D_YTD = D_YTD+? "
+
"WHERE D_ID=? AND D_W_ID=?"
);
prep
.
setBigDecimal
(
1
,
h_
amount
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setBigDecimal
(
1
,
amount
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
db
.
update
(
prep
,
"updateDistrict"
);
prep
=
prepare
(
"UPDATE WAREHOUSE SET W_YTD=W_YTD+? WHERE W_ID=?"
);
prep
.
setBigDecimal
(
1
,
h_
amount
);
prep
.
setBigDecimal
(
1
,
amount
);
prep
.
setInt
(
2
,
warehouseId
);
db
.
update
(
prep
,
"updateWarehouse"
);
prep
=
prepare
(
"SELECT W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP, W_NAME "
...
...
@@ -294,11 +294,11 @@ public class BenchCThread {
rs
.
getString
(
3
);
// w_city
rs
.
getString
(
4
);
// w_state
rs
.
getString
(
5
);
// w_zip
String
w
_n
ame
=
rs
.
getString
(
6
);
String
w
N
ame
=
rs
.
getString
(
6
);
rs
.
close
();
prep
=
prepare
(
"SELECT D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, D_NAME "
+
"FROM DISTRICT WHERE D_ID=? AND D_W_ID=?"
);
prep
.
setInt
(
1
,
d
_i
d
);
prep
.
setInt
(
1
,
d
I
d
);
prep
.
setInt
(
2
,
warehouseId
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
...
...
@@ -307,16 +307,16 @@ public class BenchCThread {
rs
.
getString
(
3
);
// d_city
rs
.
getString
(
4
);
// d_state
rs
.
getString
(
5
);
// d_zip
String
d
_n
ame
=
rs
.
getString
(
6
);
String
d
N
ame
=
rs
.
getString
(
6
);
rs
.
close
();
BigDecimal
c_
balance
;
String
c
_c
redit
;
BigDecimal
balance
;
String
credit
;
if
(
byName
)
{
prep
=
prepare
(
"SELECT COUNT(C_ID) FROM CUSTOMER "
+
"WHERE C_LAST=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setString
(
1
,
c_
last
);
prep
.
setInt
(
2
,
c
_d_i
d
);
prep
.
setInt
(
3
,
c_w_i
d
);
prep
.
setString
(
1
,
last
);
prep
.
setInt
(
2
,
c
dI
d
);
prep
.
setInt
(
3
,
wI
d
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
int
namecnt
=
rs
.
getInt
(
1
);
...
...
@@ -332,9 +332,9 @@ public class BenchCThread {
+
"C_DISCOUNT, C_BALANCE, C_SINCE FROM CUSTOMER "
+
"WHERE C_LAST=? AND C_D_ID=? AND C_W_ID=? "
+
"ORDER BY C_FIRST"
);
prep
.
setString
(
1
,
c_
last
);
prep
.
setInt
(
2
,
c
_d_i
d
);
prep
.
setInt
(
3
,
c_w_i
d
);
prep
.
setString
(
1
,
last
);
prep
.
setInt
(
2
,
c
dI
d
);
prep
.
setInt
(
3
,
wI
d
);
rs
=
db
.
query
(
prep
);
// locate midpoint customer
if
(
namecnt
%
2
!=
0
)
{
...
...
@@ -345,17 +345,17 @@ public class BenchCThread {
}
rs
.
getString
(
1
);
// c_first
rs
.
getString
(
2
);
// c_middle
c
_i
d
=
rs
.
getInt
(
3
);
c
I
d
=
rs
.
getInt
(
3
);
rs
.
getString
(
4
);
// c_street_1
rs
.
getString
(
5
);
// c_street_2
rs
.
getString
(
6
);
// c_city
rs
.
getString
(
7
);
// c_state
rs
.
getString
(
8
);
// c_zip
rs
.
getString
(
9
);
// c_phone
c
_c
redit
=
rs
.
getString
(
10
);
credit
=
rs
.
getString
(
10
);
rs
.
getString
(
11
);
// c_credit_lim
rs
.
getBigDecimal
(
12
);
// c_discount
c_
balance
=
rs
.
getBigDecimal
(
13
);
balance
=
rs
.
getBigDecimal
(
13
);
rs
.
getTimestamp
(
14
);
// c_since
rs
.
close
();
}
else
{
...
...
@@ -364,9 +364,9 @@ public class BenchCThread {
+
"C_PHONE, C_CREDIT, C_CREDIT_LIM, "
+
"C_DISCOUNT, C_BALANCE, C_SINCE FROM CUSTOMER "
+
"WHERE C_ID=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setInt
(
1
,
c
_i
d
);
prep
.
setInt
(
2
,
c
_d_i
d
);
prep
.
setInt
(
3
,
c_w_i
d
);
prep
.
setInt
(
1
,
c
I
d
);
prep
.
setInt
(
2
,
c
dI
d
);
prep
.
setInt
(
3
,
wI
d
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
rs
.
getString
(
1
);
// c_first
...
...
@@ -376,78 +376,78 @@ public class BenchCThread {
rs
.
getString
(
5
);
// c_street_2
rs
.
getString
(
6
);
// c_city
rs
.
getString
(
7
);
// c_state
rs
.
getString
(
8
);
//
c_zip
rs
.
getString
(
8
);
//
c_zip
rs
.
getString
(
9
);
// c_phone
c
_c
redit
=
rs
.
getString
(
10
);
credit
=
rs
.
getString
(
10
);
rs
.
getString
(
11
);
// c_credit_lim
rs
.
getBigDecimal
(
12
);
// c_discount
c_
balance
=
rs
.
getBigDecimal
(
13
);
balance
=
rs
.
getBigDecimal
(
13
);
rs
.
getTimestamp
(
14
);
// c_since
rs
.
close
();
}
c_balance
=
c_balance
.
add
(
h_
amount
);
if
(
c
_c
redit
.
equals
(
"BC"
))
{
balance
=
balance
.
add
(
amount
);
if
(
credit
.
equals
(
"BC"
))
{
prep
=
prepare
(
"SELECT C_DATA INTO FROM CUSTOMER "
+
"WHERE C_ID=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setInt
(
1
,
c
_i
d
);
prep
.
setInt
(
2
,
c
_d_i
d
);
prep
.
setInt
(
3
,
c_w_i
d
);
prep
.
setInt
(
1
,
c
I
d
);
prep
.
setInt
(
2
,
c
dI
d
);
prep
.
setInt
(
3
,
wI
d
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
String
c
_d
ata
=
rs
.
getString
(
1
);
String
c
D
ata
=
rs
.
getString
(
1
);
rs
.
close
();
String
c
_new_data
=
"| "
+
c_id
+
" "
+
c_d_id
+
" "
+
c_w_i
d
+
" "
+
d
_id
+
" "
+
warehouseId
+
" "
+
h_
amount
+
" "
+
c
_d
ata
;
if
(
c
_new_d
ata
.
length
()
>
500
)
{
c
_new_data
=
c_new_d
ata
.
substring
(
0
,
500
);
String
c
NewData
=
"| "
+
cId
+
" "
+
cdId
+
" "
+
wI
d
+
" "
+
d
Id
+
" "
+
warehouseId
+
" "
+
amount
+
" "
+
c
D
ata
;
if
(
c
NewD
ata
.
length
()
>
500
)
{
c
NewData
=
cNewD
ata
.
substring
(
0
,
500
);
}
prep
=
prepare
(
"UPDATE CUSTOMER SET C_BALANCE=?, C_DATA=? "
+
"WHERE C_ID=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setBigDecimal
(
1
,
c_
balance
);
prep
.
setString
(
2
,
c
_new_d
ata
);
prep
.
setInt
(
3
,
c
_i
d
);
prep
.
setInt
(
4
,
c
_d_i
d
);
prep
.
setInt
(
5
,
c_w_i
d
);
prep
.
setBigDecimal
(
1
,
balance
);
prep
.
setString
(
2
,
c
NewD
ata
);
prep
.
setInt
(
3
,
c
I
d
);
prep
.
setInt
(
4
,
c
dI
d
);
prep
.
setInt
(
5
,
wI
d
);
db
.
update
(
prep
,
"updateCustomer"
);
}
else
{
prep
=
prepare
(
"UPDATE CUSTOMER SET C_BALANCE=? "
+
"WHERE C_ID=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setBigDecimal
(
1
,
c_
balance
);
prep
.
setInt
(
2
,
c
_i
d
);
prep
.
setInt
(
3
,
c
_d_i
d
);
prep
.
setInt
(
4
,
c_w_i
d
);
prep
.
setBigDecimal
(
1
,
balance
);
prep
.
setInt
(
2
,
c
I
d
);
prep
.
setInt
(
3
,
c
dI
d
);
prep
.
setInt
(
4
,
wI
d
);
db
.
update
(
prep
,
"updateCustomer"
);
}
// MySQL bug?
// String h_data = w_name + " " + d_name;
String
h
_data
=
w_name
+
" "
+
d_n
ame
;
String
h
Data
=
wName
+
" "
+
dN
ame
;
prep
=
prepare
(
"INSERT INTO HISTORY (H_C_D_ID, H_C_W_ID, H_C_ID, H_D_ID, "
+
"H_W_ID, H_DATE, H_AMOUNT, H_DATA) "
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
);
prep
.
setInt
(
1
,
c
_d_i
d
);
prep
.
setInt
(
2
,
c_w_i
d
);
prep
.
setInt
(
3
,
c
_i
d
);
prep
.
setInt
(
4
,
d
_i
d
);
prep
.
setInt
(
1
,
c
dI
d
);
prep
.
setInt
(
2
,
wI
d
);
prep
.
setInt
(
3
,
c
I
d
);
prep
.
setInt
(
4
,
d
I
d
);
prep
.
setInt
(
5
,
warehouseId
);
prep
.
setTimestamp
(
6
,
datetime
);
prep
.
setBigDecimal
(
7
,
h_
amount
);
prep
.
setString
(
8
,
h
_d
ata
);
prep
.
setBigDecimal
(
7
,
amount
);
prep
.
setString
(
8
,
h
D
ata
);
db
.
update
(
prep
,
"insertHistory"
);
db
.
commit
();
}
private
void
processOrderStatus
()
throws
Exception
{
int
d
_i
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
int
d
I
d
=
random
.
getInt
(
1
,
bench
.
districtsPerWarehouse
);
boolean
byName
;
String
c_
last
=
null
;
int
c
_i
d
=
-
1
;
String
last
=
null
;
int
c
I
d
=
-
1
;
if
(
random
.
getInt
(
1
,
100
)
<=
60
)
{
byName
=
true
;
c_
last
=
random
.
getLastname
(
random
.
getNonUniform
(
255
,
0
,
999
));
last
=
random
.
getLastname
(
random
.
getNonUniform
(
255
,
0
,
999
));
}
else
{
byName
=
false
;
c
_i
d
=
random
.
getNonUniform
(
1023
,
1
,
bench
.
customersPerDistrict
);
c
I
d
=
random
.
getNonUniform
(
1023
,
1
,
bench
.
customersPerDistrict
);
}
PreparedStatement
prep
;
ResultSet
rs
;
...
...
@@ -457,8 +457,8 @@ public class BenchCThread {
if
(
byName
)
{
prep
=
prepare
(
"SELECT COUNT(C_ID) FROM CUSTOMER "
+
"WHERE C_LAST=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setString
(
1
,
c_
last
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setString
(
1
,
last
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
...
...
@@ -473,8 +473,8 @@ public class BenchCThread {
+
"FROM CUSTOMER "
+
"WHERE C_LAST=? AND C_D_ID=? AND C_W_ID=? "
+
"ORDER BY C_FIRST"
);
prep
.
setString
(
1
,
c_
last
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setString
(
1
,
last
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
rs
=
db
.
query
(
prep
);
if
(
namecnt
%
2
!=
0
)
{
...
...
@@ -491,8 +491,8 @@ public class BenchCThread {
prep
=
prepare
(
"SELECT C_BALANCE, C_FIRST, C_MIDDLE, C_LAST "
+
"FROM CUSTOMER "
+
"WHERE C_ID=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setInt
(
1
,
c
_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
c
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
...
...
@@ -504,33 +504,33 @@ public class BenchCThread {
}
prep
=
prepare
(
"SELECT MAX(O_ID) "
+
"FROM ORDERS WHERE O_C_ID=? AND O_D_ID=? AND O_W_ID=?"
);
prep
.
setInt
(
1
,
c
_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
c
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
rs
=
db
.
query
(
prep
);
int
o
_i
d
=
-
1
;
int
o
I
d
=
-
1
;
if
(
rs
.
next
())
{
o
_i
d
=
rs
.
getInt
(
1
);
o
I
d
=
rs
.
getInt
(
1
);
if
(
rs
.
wasNull
())
{
o
_i
d
=
-
1
;
o
I
d
=
-
1
;
}
}
rs
.
close
();
if
(
o
_i
d
!=
-
1
)
{
if
(
o
I
d
!=
-
1
)
{
prep
=
prepare
(
"SELECT O_ID, O_CARRIER_ID, O_ENTRY_D "
+
"FROM ORDERS WHERE O_ID=?"
);
prep
.
setInt
(
1
,
o
_i
d
);
prep
.
setInt
(
1
,
o
I
d
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
o
_i
d
=
rs
.
getInt
(
1
);
o
I
d
=
rs
.
getInt
(
1
);
rs
.
getInt
(
2
);
// o_carrier_id
rs
.
getTimestamp
(
3
);
// o_entry_d
rs
.
close
();
prep
=
prepare
(
"SELECT OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, "
+
"OL_AMOUNT, OL_DELIVERY_D FROM ORDER_LINE "
+
"WHERE OL_O_ID=? AND OL_D_ID=? AND OL_W_ID=?"
);
prep
.
setInt
(
1
,
o
_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
o
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
rs
=
db
.
query
(
prep
);
while
(
rs
.
next
())
{
...
...
@@ -546,38 +546,38 @@ public class BenchCThread {
}
private
void
processDelivery
()
throws
Exception
{
int
o_carrier_i
d
=
random
.
getInt
(
1
,
10
);
int
carrierI
d
=
random
.
getInt
(
1
,
10
);
Timestamp
datetime
=
new
Timestamp
(
System
.
currentTimeMillis
());
PreparedStatement
prep
;
ResultSet
rs
;
prep
=
prepare
(
"UPDATE DISTRICT SET D_NEXT_O_ID=-1 WHERE D_ID=-1"
);
db
.
update
(
prep
,
"updateDistrict"
);
for
(
int
d
_id
=
1
;
d_id
<=
bench
.
districtsPerWarehouse
;
d_i
d
++)
{
for
(
int
d
Id
=
1
;
dId
<=
bench
.
districtsPerWarehouse
;
dI
d
++)
{
prep
=
prepare
(
"SELECT MIN(NO_O_ID) FROM NEW_ORDER "
+
"WHERE NO_D_ID=? AND NO_W_ID=?"
);
prep
.
setInt
(
1
,
d
_i
d
);
prep
.
setInt
(
1
,
d
I
d
);
prep
.
setInt
(
2
,
warehouseId
);
rs
=
db
.
query
(
prep
);
int
no
_o_i
d
=
-
1
;
int
no
I
d
=
-
1
;
if
(
rs
.
next
())
{
no
_o_i
d
=
rs
.
getInt
(
1
);
no
I
d
=
rs
.
getInt
(
1
);
if
(
rs
.
wasNull
())
{
no
_o_i
d
=
-
1
;
no
I
d
=
-
1
;
}
}
rs
.
close
();
if
(
no
_o_i
d
!=
-
1
)
{
if
(
no
I
d
!=
-
1
)
{
prep
=
prepare
(
"DELETE FROM NEW_ORDER "
+
"WHERE NO_O_ID=? AND NO_D_ID=? AND NO_W_ID=?"
);
prep
.
setInt
(
1
,
no
_o_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
no
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
db
.
update
(
prep
,
"deleteNewOrder"
);
prep
=
prepare
(
"SELECT O_C_ID FROM ORDERS "
+
"WHERE O_ID=? AND O_D_ID=? AND O_W_ID=?"
);
prep
.
setInt
(
1
,
no
_o_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
no
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
...
...
@@ -585,32 +585,32 @@ public class BenchCThread {
rs
.
close
();
prep
=
prepare
(
"UPDATE ORDERS SET O_CARRIER_ID=? "
+
"WHERE O_ID=? AND O_D_ID=? AND O_W_ID=?"
);
prep
.
setInt
(
1
,
o_carrier_i
d
);
prep
.
setInt
(
2
,
no
_o_i
d
);
prep
.
setInt
(
3
,
d
_i
d
);
prep
.
setInt
(
1
,
carrierI
d
);
prep
.
setInt
(
2
,
no
I
d
);
prep
.
setInt
(
3
,
d
I
d
);
prep
.
setInt
(
4
,
warehouseId
);
db
.
update
(
prep
,
"updateOrders"
);
prep
=
prepare
(
"UPDATE ORDER_LINE SET OL_DELIVERY_D=? "
+
"WHERE OL_O_ID=? AND OL_D_ID=? AND OL_W_ID=?"
);
prep
.
setTimestamp
(
1
,
datetime
);
prep
.
setInt
(
2
,
no
_o_i
d
);
prep
.
setInt
(
3
,
d
_i
d
);
prep
.
setInt
(
2
,
no
I
d
);
prep
.
setInt
(
3
,
d
I
d
);
prep
.
setInt
(
4
,
warehouseId
);
db
.
update
(
prep
,
"updateOrderLine"
);
prep
=
prepare
(
"SELECT SUM(OL_AMOUNT) FROM ORDER_LINE "
+
"WHERE OL_O_ID=? AND OL_D_ID=? AND OL_W_ID=?"
);
prep
.
setInt
(
1
,
no
_o_i
d
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
1
,
no
I
d
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
warehouseId
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
BigDecimal
ol_
amount
=
rs
.
getBigDecimal
(
1
);
BigDecimal
amount
=
rs
.
getBigDecimal
(
1
);
rs
.
close
();
prep
=
prepare
(
"UPDATE CUSTOMER SET C_BALANCE=C_BALANCE+? "
+
"WHERE C_ID=? AND C_D_ID=? AND C_W_ID=?"
);
prep
.
setBigDecimal
(
1
,
ol_
amount
);
prep
.
setInt
(
2
,
no
_o_i
d
);
prep
.
setInt
(
3
,
d
_i
d
);
prep
.
setBigDecimal
(
1
,
amount
);
prep
.
setInt
(
2
,
no
I
d
);
prep
.
setInt
(
3
,
d
I
d
);
prep
.
setInt
(
4
,
warehouseId
);
db
.
update
(
prep
,
"updateCustomer"
);
}
...
...
@@ -619,7 +619,7 @@ public class BenchCThread {
}
private
void
processStockLevel
()
throws
Exception
{
int
d
_i
d
=
(
terminalId
%
bench
.
districtsPerWarehouse
)
+
1
;
int
d
I
d
=
(
terminalId
%
bench
.
districtsPerWarehouse
)
+
1
;
int
threshold
=
random
.
getInt
(
10
,
20
);
PreparedStatement
prep
;
ResultSet
rs
;
...
...
@@ -629,11 +629,11 @@ public class BenchCThread {
prep
=
prepare
(
"SELECT D_NEXT_O_ID FROM DISTRICT "
+
"WHERE D_ID=? AND D_W_ID=?"
);
prep
.
setInt
(
1
,
d
_i
d
);
prep
.
setInt
(
1
,
d
I
d
);
prep
.
setInt
(
2
,
warehouseId
);
rs
=
db
.
query
(
prep
);
rs
.
next
();
int
o
_i
d
=
rs
.
getInt
(
1
);
int
o
I
d
=
rs
.
getInt
(
1
);
rs
.
close
();
// prep = prepare("SELECT COUNT(DISTINCT S_I_ID) "
// + "FROM ORDER_LINE, STOCK WHERE OL_W_ID=? AND "
...
...
@@ -650,9 +650,9 @@ public class BenchCThread {
+
"OL_O_ID>=? AND S_W_ID=? AND "
+
"S_I_ID=OL_I_ID AND S_QUANTITY<?"
);
prep
.
setInt
(
1
,
warehouseId
);
prep
.
setInt
(
2
,
d
_i
d
);
prep
.
setInt
(
3
,
o
_i
d
);
prep
.
setInt
(
4
,
o
_id
-
20
);
prep
.
setInt
(
2
,
d
I
d
);
prep
.
setInt
(
3
,
o
I
d
);
prep
.
setInt
(
4
,
o
Id
-
20
);
prep
.
setInt
(
5
,
warehouseId
);
prep
.
setInt
(
6
,
threshold
);
// TODO this is where HSQLDB is very slow
...
...
h2/src/test/org/h2/test/db/TestAutoRecompile.java
浏览文件 @
f447a3e4
...
...
@@ -15,7 +15,7 @@ public class TestAutoRecompile extends TestBase {
public
void
test
()
throws
Exception
{
deleteDb
(
"autoRecompile"
);
Connection
conn
=
getConnection
(
"autoRecompile"
);
Connection
conn
=
getConnection
(
"autoRecompile"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST"
);
...
...
@@ -32,13 +32,13 @@ public class TestAutoRecompile extends TestBase {
try
{
prep
.
execute
();
error
(
"must fail"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
try
{
prep
.
execute
();
error
(
"must fail"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
conn
.
close
();
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
f447a3e4
...
...
@@ -37,9 +37,7 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT LIMIT ? 1 ID FROM TEST"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT LIMIT ? 1 ID FROM TEST"
);
prep
.
setInt
(
1
,
2
);
prep
.
executeQuery
();
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
...
...
@@ -54,5 +52,4 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')"
);
}
}
h2/src/test/org/h2/test/db/TestLobObject.java
浏览文件 @
f447a3e4
...
...
@@ -9,6 +9,7 @@ import java.io.Serializable;
class
TestLobObject
implements
Serializable
{
private
static
final
long
serialVersionUID
=
904356179316518715L
;
String
data
;
TestLobObject
(
String
data
)
{
this
.
data
=
data
;
}
...
...
h2/src/test/org/h2/test/db/TestSQLInjection.java
浏览文件 @
f447a3e4
...
...
@@ -36,14 +36,14 @@ public class TestSQLInjection extends TestBase {
try
{
check
(
checkPasswordInsecure
(
"123456"
));
error
(
"Should fail now"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
check
(
checkPasswordSecure
(
"123456"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
conn
.
close
();
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
}
...
...
@@ -52,7 +52,7 @@ public class TestSQLInjection extends TestBase {
try
{
check
(
checkPasswordInsecure
(
"123456"
));
error
(
"Should fail now"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
check
(
checkPasswordSecure
(
"123456"
));
...
...
@@ -61,9 +61,9 @@ public class TestSQLInjection extends TestBase {
}
boolean
checkPasswordInsecure
(
String
pwd
)
throws
SQLException
{
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD='"
+
pwd
+
"'"
;
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD='"
+
pwd
+
"'"
;
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
sql
);
return
(
rs
.
next
());
return
(
rs
.
next
());
}
boolean
checkPasswordSecure
(
String
pwd
)
throws
Exception
{
...
...
@@ -71,17 +71,17 @@ public class TestSQLInjection extends TestBase {
PreparedStatement
prep
=
conn
.
prepareStatement
(
sql
);
prep
.
setString
(
1
,
pwd
);
ResultSet
rs
=
prep
.
executeQuery
();
return
(
rs
.
next
());
return
(
rs
.
next
());
}
private
void
reconnect
(
String
name
)
throws
Exception
{
if
(!
config
.
memory
)
{
if
(
conn
!=
null
)
{
if
(!
config
.
memory
)
{
if
(
conn
!=
null
)
{
conn
.
close
();
conn
=
null
;
}
}
if
(
conn
==
null
)
{
if
(
conn
==
null
)
{
conn
=
getConnection
(
name
);
stat
=
conn
.
createStatement
();
}
...
...
h2/src/test/org/h2/test/db/TestSpaceReuse.java
浏览文件 @
f447a3e4
...
...
@@ -12,7 +12,7 @@ import org.h2.test.TestBase;
public
class
TestSpaceReuse
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"spaceReuse"
);
...
...
@@ -27,11 +27,11 @@ public class TestSpaceReuse extends TestBase {
conn
.
createStatement
().
execute
(
"delete from t"
);
conn
.
close
();
now
=
new
File
(
baseDir
+
"/spaceReuse.data.db"
).
length
();
if
(
first
==
0
)
{
if
(
first
==
0
)
{
first
=
now
;
}
}
if
(
now
>
first
)
{
if
(
now
>
first
)
{
this
.
error
(
"first: "
+
first
+
" now: "
+
now
);
}
}
...
...
h2/src/test/org/h2/test/db/TestSpeed.java
浏览文件 @
f447a3e4
...
...
@@ -16,7 +16,8 @@ import org.h2.test.TestBase;
public
class
TestSpeed
extends
TestBase
{
// java -cp .;..\..\hsqldb\lib\hsqldb.jar -Xrunhprof:heap=sites,depth=6 org.h2.test.TestAll
// java -cp .;..\..\hsqldb\lib\hsqldb.jar -Xrunhprof:heap=sites,depth=6
// org.h2.test.TestAll
// java -Xrunhprof:heap=sites org.h2.test.TestAll
// TODO test: here is more code, currently untested!
...
...
@@ -28,147 +29,156 @@ public class TestSpeed extends TestBase {
conn
=
getConnection
(
"speed"
);
// conn = getConnection("speed;ASSERT=0;MAX_MEMORY_ROWS=1000000;MAX_LOG_SIZE=1000");
// conn =
// getConnection("speed;ASSERT=0;MAX_MEMORY_ROWS=1000000;MAX_LOG_SIZE=1000");
//
Class.forName("org.hsqldb.jdbcDriver");
//
conn = DriverManager.getConnection("jdbc:hsqldb:speed");
//
Class.forName("org.hsqldb.jdbcDriver");
//
conn = DriverManager.getConnection("jdbc:hsqldb:speed");
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
int
len
=
getSize
(
1
,
10000
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
stat
.
execute
(
"SELECT ID, NAME FROM TEST ORDER BY ID"
);
}
//drop table if exists test;
//
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
//
@LOOP 100000 INSERT INTO TEST VALUES(?, 'Hello');
//
@LOOP 100000 SELECT * FROM TEST WHERE ID = ?;
// drop table if exists test;
//
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
//
@LOOP 100000 INSERT INTO TEST VALUES(?, 'Hello');
//
@LOOP 100000 SELECT * FROM TEST WHERE ID = ?;
// stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
// for(int i=0; i<1000; i++) {
// stat.execute("INSERT INTO TEST VALUES("+i+", 'Hello')");
// }
// stat.execute("CREATE TABLE TEST_A(ID INT PRIMARY KEY, NAME VARCHAR(255))");
// stat.execute("INSERT INTO TEST_A VALUES(0, 'Hello')");
// stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME
// VARCHAR(255))");
// for(int i=0; i<1000; i++) {
// stat.execute("INSERT INTO TEST VALUES("+i+", 'Hello')");
// }
// stat.execute("CREATE TABLE TEST_A(ID INT PRIMARY KEY, NAME
// VARCHAR(255))");
// stat.execute("INSERT INTO TEST_A VALUES(0, 'Hello')");
long
time
=
System
.
currentTimeMillis
();
// for(int i=1; i<8000; i*=2) {
// stat.execute("INSERT INTO TEST_A SELECT ID+"+i+", NAME FROM TEST_A");
//
//// stat.execute("INSERT INTO TEST_A VALUES("+i+", 'Hello')");
// }
// for(int i=0; i<4; i++) {
// ResultSet rs = stat.executeQuery("SELECT * FROM TEST_A");
// while(rs.next()) {
// rs.getInt(1);
// rs.getString(2);
// }
// }
// System.out.println(System.currentTimeMillis()-time);
//
// stat.execute("CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME VARCHAR(255))");
// for(int i=0; i<80000; i++) {
// stat.execute("INSERT INTO TEST_B VALUES("+i+", 'Hello')");
// }
// for(int i=1; i<8000; i*=2) {
// stat.execute("INSERT INTO TEST_A SELECT ID+"+i+", NAME FROM TEST_A");
//
// // stat.execute("INSERT INTO TEST_A VALUES("+i+", 'Hello')");
// }
// for(int i=0; i<4; i++) {
// ResultSet rs = stat.executeQuery("SELECT * FROM TEST_A");
// while(rs.next()) {
// rs.getInt(1);
// rs.getString(2);
// }
// }
// System.out.println(System.currentTimeMillis()-time);
//
// stat.execute("CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME
// VARCHAR(255))");
// for(int i=0; i<80000; i++) {
// stat.execute("INSERT INTO TEST_B VALUES("+i+", 'Hello')");
// }
// conn.close();
//
System.exit(0);
//
int testParser;
//
System.exit(0);
//
int testParser;
// java -Xrunhprof:cpu=samples,depth=8 -cp . org.h2.test.TestAll
//
//
stat.execute("CREATE TABLE TEST(ID INT)");
//
stat.execute("INSERT INTO TEST VALUES(1)");
//
ResultSet rs = stat.executeQuery("SELECT ID OTHER_ID FROM TEST");
//
rs.next();
//
rs.getString("ID");
//
stat.execute("DROP TABLE TEST");
//
//
stat.execute("CREATE TABLE TEST(ID INT)");
//
stat.execute("INSERT INTO TEST VALUES(1)");
//
ResultSet rs = stat.executeQuery("SELECT ID OTHER_ID FROM TEST");
//
rs.next();
//
rs.getString("ID");
//
stat.execute("DROP TABLE TEST");
//
long time = System.currentTimeMillis();
//
long time = System.currentTimeMillis();
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE CACHED TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
int
max
=
getSize
(
1
,
10000
);
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setString
(
2
,
"abchelloasdfaldsjflajdflajdslfoajlskdfkjasdfadsfasdfadsfadfsalksdjflasjflajsdlkfjaksdjflkskd"
+
i
);
//prep.setString(2, "abchelloasdfaldsjflajdflajdslfoajlskdfkjasdfadsfasdfadsfadfsalksdjflasjflajsdlkfjaksdjflkskd");
prep
.
setString
(
2
,
"abchelloasdfaldsjflajdflajdslfoajlskdfkjasdfadsfasdfadsfadfsalksdjflasjflajsdlkfjaksdjflkskd"
+
i
);
// prep.setString(2,
// "abchelloasdfaldsjflajdflajdslfoajlskdfkjasdfadsfasdfadsfadfsalksdjflasjflajsdlkfjaksdjflkskd");
prep
.
execute
();
// System.out.println("i="+i);
// stat.execute("INSERT INTO TEST VALUES("+i+", 'abchelloasdfaldsjflajdflajdslfaajlskdfkjasdfadsfasdfadsfadfsalksdjflasjflajsdlkfjaksdjflkskd"+i+"')");
// ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE ID="+i);
// if(!rs.next()) {
// throw new Error("hey! i="+i);
// }
// if(rs.next()) {
// throw new Error("hey! i="+i);
// }
// System.out.println("i="+i);
// stat.execute("INSERT INTO TEST VALUES("+i+",
// 'abchelloasdfaldsjflajdflajdslfaajlskdfkjasdfadsfasdfadsfadfsalksdjflasjflajsdlkfjaksdjflkskd"+i+"')");
// ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE
// ID="+i);
// if(!rs.next()) {
// throw new Error("hey! i="+i);
// }
// if(rs.next()) {
// throw new Error("hey! i="+i);
// }
}
//
System.exit(0);
//
System.out.println("END "+Value.cacheHit+" "+Value.cacheMiss);
//
System.exit(0);
//
System.out.println("END "+Value.cacheHit+" "+Value.cacheMiss);
time
=
System
.
currentTimeMillis
()
-
time
;
trace
(
time
+
" insert"
);
trace
(
time
+
" insert"
);
//
if(true) return;
//
if(true) return;
//
if(config.log) {
//
System.gc();
//
System.gc();
//
log("mem="+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024);
//
}
//
if(config.log) {
//
System.gc();
//
System.gc();
//
log("mem="+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024);
//
}
//
conn.close();
//
conn.close();
time
=
System
.
currentTimeMillis
();
prep
=
conn
.
prepareStatement
(
"UPDATE TEST SET NAME='Another data row which is long' WHERE ID=?"
);
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
// System.out.println("updated "+i);
// stat.execute("UPDATE TEST SET NAME='Another data row which is long' WHERE ID="+i);
// ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE ID="+i);
// if(!rs.next()) {
// throw new Error("hey! i="+i);
// }
// if(rs.next()) {
// throw new Error("hey! i="+i);
// }
// System.out.println("updated "+i);
// stat.execute("UPDATE TEST SET NAME='Another data row which is
// long' WHERE ID="+i);
// ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE
// ID="+i);
// if(!rs.next()) {
// throw new Error("hey! i="+i);
// }
// if(rs.next()) {
// throw new Error("hey! i="+i);
// }
}
//
for(int i=0; i<max; i++) {
//
stat.execute("DELETE FROM TEST WHERE ID="+i);
//
ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE ID="+i);
//
if(rs.next()) {
//
throw new Error("hey!");
//
}
//
}
//
for(int i=0; i<max; i++) {
//
stat.execute("DELETE FROM TEST WHERE ID="+i);
//
ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE ID="+i);
//
if(rs.next()) {
//
throw new Error("hey!");
//
}
//
}
time
=
System
.
currentTimeMillis
()
-
time
;
trace
(
time
+
" update"
);
trace
(
time
+
" update"
);
conn
.
close
();
time
=
System
.
currentTimeMillis
()
-
time
;
trace
(
time
+
" close"
);
trace
(
time
+
" close"
);
}
//
private void testOuterJoin() throws Exception {
//
Class.forName("org.h2.jdbc.jdbcDriver");
//
Connection conn = DriverManager.getConnection("jdbc:h2:test");
//
private void testOuterJoin() throws Exception {
//
Class.forName("org.h2.jdbc.jdbcDriver");
//
Connection conn = DriverManager.getConnection("jdbc:h2:test");
//
Class.forName("org.hsqldb.jdbcDriver");
//
Connection conn = DriverManager.getConnection("jdbc:hsqldb:test");
//
Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:.");
//
Class.forName("org.hsqldb.jdbcDriver");
//
Connection conn = DriverManager.getConnection("jdbc:hsqldb:test");
//
Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:.");
//
Statement stat = conn.createStatement();
//
//
int len = getSize(1, 10000);
//
Statement stat = conn.createStatement();
//
//
int len = getSize(1, 10000);
// create table test(id int primary key, name varchar(255))
// insert into test values(1, 'b')
...
...
@@ -180,224 +190,214 @@ public class TestSpeed extends TestBase {
// select id from test group by id
// long start = System.currentTimeMillis();
//
// stat.executeUpdate("DROP TABLE IF EXISTS TEST");
// stat.executeUpdate("CREATE TABLE Test(" + "Id INTEGER PRIMARY KEY, "
// + "FirstName VARCHAR(20), " + "Name VARCHAR(50), "
// + "ZIP INTEGER)");
//
//
// stat.execute("create table a(a1 varchar(1), a2 int)");
// stat.execute("create table b(b1 varchar(1), b2 int)");
// stat.execute("insert into a values(null, 12)");
// stat.execute("insert into a values('a', 22)");
// stat.execute("insert into a values('b', 32)");
// stat.execute("insert into b values(null, 14)");
// stat.execute("insert into b values('a', 14)");
// stat.execute("insert into b values('c', 15)");
// create table a(a1 varchar(1), a2 int);
// create table b(b1 varchar(1), b2 int);
// insert into a values(null, 12);
// insert into a values('a', 22);
// insert into a values('b', 32);
// insert into b values(null, 14);
// insert into b values('a', 14);
// insert into b values('c', 15);
//query(stat, "select * from a left outer join b on a.a1=b.b1");
// long start = System.currentTimeMillis();
//
// stat.executeUpdate("DROP TABLE IF EXISTS TEST");
// stat.executeUpdate("CREATE TABLE Test(" + "Id INTEGER PRIMARY KEY, "
// + "FirstName VARCHAR(20), " + "Name VARCHAR(50), "
// + "ZIP INTEGER)");
//
//
// stat.execute("create table a(a1 varchar(1), a2 int)");
// stat.execute("create table b(b1 varchar(1), b2 int)");
// stat.execute("insert into a values(null, 12)");
// stat.execute("insert into a values('a', 22)");
// stat.execute("insert into a values('b', 32)");
// stat.execute("insert into b values(null, 14)");
// stat.execute("insert into b values('a', 14)");
// stat.execute("insert into b values('c', 15)");
// create table a(a1 varchar(1), a2 int);
// create table b(b1 varchar(1), b2 int);
// insert into a values(null, 12);
// insert into a values('a', 22);
// insert into a values('b', 32);
// insert into b values(null, 14);
// insert into b values('a', 14);
// insert into b values('c', 15);
// query(stat, "select * from a left outer join b on a.a1=b.b1");
// should be 3 rows
// query(stat, "select * from a left outer join b on ((a.a1=b.b1) or (a.a1 is null and b.b1 is null))");
// A1 A2 B1 B2
// null 12 null 14
// a 22 a 14
// b 32 null null
// query(stat, "select * from a left outer join b on ((a.a1=b.b1) or (a.a1
// is null and b.b1 is null))");
// A1 A2 B1 B2
// null 12 null 14
// a 22 a 14
// b 32 null null
// should be 3 rows
// query(stat, "select * from a left outer join b on ((a.a1=b.b1) or (a.a1 is null and b.b1 is null))");
// A1 A2 B1 B2
// 12 14
// a 22 a 14
// b 32
// query(stat, "select * from a left outer join b on ((a.a1=b.b1) or (a.a1
// is null and b.b1 is null))");
// A1 A2 B1 B2
// 12 14
// a 22 a 14
// b 32
// should be 2 rows
// query(stat, "select * from a left outer join b on (1=1) where ((a.a1=b.b1) or (a.a1 is null and b.b1 is null))");
// A1 A2 B1 B2
// 12 14
// a 22 a 14
// query(stat, "select * from a left outer join b on (1=1) where
// ((a.a1=b.b1) or (a.a1 is null and b.b1 is null))");
// A1 A2 B1 B2
// 12 14
// a 22 a 14
// should be 1 row
// query(stat, "select * from a left outer join b on (1=1) where a.a1=b.b1");
// query(stat, "select * from a left outer join b on (1=1) where
// a.a1=b.b1");
// should be 3 rows
// query(stat, "select * from a left outer join b on a.a1=b.b1 where (1=1)");
// if(true) return;
// query(stat, "select * from a left outer join b on a.a1=b.b1 where
// (1=1)");
// if(true) return;
// query(stat, "SELECT T1.ID, T2.ID FROM TEST T1, TEST T2 WHERE T1.ID >
// T2.ID");
//query(stat, "SELECT T1.ID, T2.ID FROM TEST T1, TEST T2 WHERE T1.ID > T2.ID");
// PreparedStatement prep;
//
// prep = conn
// .prepareStatement("INSERT INTO Test VALUES(?,'Julia','Peterson-Clancy',?)");
//query(stat, "SELECT * FROM TEST WHERE NAME LIKE 'Ju%'");
// PreparedStatement prep;
//
// prep = conn
// .prepareStatement("INSERT INTO Test
// VALUES(?,'Julia','Peterson-Clancy',?)");
// query(stat, "SELECT * FROM TEST WHERE NAME LIKE 'Ju%'");
// long time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
// prep.setInt(1, i);
// prep.setInt(2, i);
// prep.execute();
//query(stat, "SELECT * FROM TEST");
//if(i % 2 == 0) {
// stat.executeUpdate("INSERT INTO Test VALUES("+i+",'Julia','Peterson-Clancy',"+i+")");
//} else {
// stat.executeUpdate("INSERT INTO TEST VALUES("+i+",'Julia','Peterson-Clancy',"+i+")");
//}
// }
// long time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
// prep.setInt(1, i);
// prep.setInt(2, i);
// prep.execute();
// query(stat, "SELECT * FROM TEST");
// if(i % 2 == 0) {
// stat.executeUpdate("INSERT INTO Test
// VALUES("+i+",'Julia','Peterson-Clancy',"+i+")");
// } else {
// stat.executeUpdate("INSERT INTO TEST
// VALUES("+i+",'Julia','Peterson-Clancy',"+i+")");
// }
// }
//
query(stat, "SELECT ABS(-1) FROM TEST");
//
query(stat, "SELECT ABS(-1) FROM TEST");
//
conn.close();
//
conn.close();
// if(true) return;
//
stat.executeUpdate("UPDATE Test SET Name='Hans' WHERE Id=1");
//
query(stat, "SELECT * FROM Test WHERE Id=1");
//
stat.executeUpdate("DELETE FROM Test WHERE Id=1");
//
stat.executeUpdate("UPDATE Test SET Name='Hans' WHERE Id=1");
//
query(stat, "SELECT * FROM Test WHERE Id=1");
//
stat.executeUpdate("DELETE FROM Test WHERE Id=1");
//
query(stat, "SELECT * FROM TEST");
//
query(stat, "SELECT * FROM TEST");
//
conn.close();
//
//
if(true) {
//
return;
//
}
//
conn.close();
//
//
if(true) {
//
return;
//
}
// query(stat, "SELECT * FROM TEST WHERE ID = 182");
/*
for(int i=0; i<len; i++) {
query(stat, "SELECT * FROM TEST WHERE ID = "+i);
}
* for(int i=0; i<len; i++) { query(stat, "SELECT * FROM TEST WHERE ID =
* "+i); }
*/
// System.out.println("insert=" + (System.currentTimeMillis() - time));
// System.out.println("insert=" + (System.currentTimeMillis() - time));
// conn.setAutoCommit(false);
// prep = conn.prepareStatement("UPDATE Test SET FirstName='Hans' WHERE Id=?");
//
// time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
// prep.setInt(1, i);
// prep = conn.prepareStatement("UPDATE Test SET FirstName='Hans' WHERE
// Id=?");
//
// time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
// prep.setInt(1, i);
// if(i%10 == 0) {
// System.out.println(i+" ");
// }
// prep.execute();
// stat.executeUpdate("UPDATE Test SET FirstName='Hans' WHERE Id="+i);
// prep.execute();
// stat.executeUpdate("UPDATE Test SET FirstName='Hans' WHERE Id="+i);
// if(i==5) conn.close();
//
query(stat, "SELECT * FROM TEST");
//
}
//
query(stat, "SELECT * FROM TEST");
//
}
// conn.rollback();
// System.out.println("update=" + (System.currentTimeMillis() - time));
//
// prep = conn.prepareStatement("SELECT * FROM Test WHERE Id=?");
//
// time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
// prep.setInt(1, i);
// prep.execute();
//// stat.executeQuery("SELECT * FROM Test WHERE Id="+i);
// }
// System.out.println("select=" + (System.currentTimeMillis() - time));
// System.out.println("update=" + (System.currentTimeMillis() - time));
//
// prep = conn.prepareStatement("SELECT * FROM Test WHERE Id=?");
//
// time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
// prep.setInt(1, i);
// prep.execute();
// // stat.executeQuery("SELECT * FROM Test WHERE Id="+i);
// }
// System.out.println("select=" + (System.currentTimeMillis() - time));
// query(stat, "SELECT * FROM TEST");
// prep = conn.prepareStatement("DELETE FROM Test WHERE Id=?");
//
// time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
//// stat.executeUpdate("DELETE FROM Test WHERE Id="+i);
// prep.setInt(1, i);
// //System.out.println("delete "+i);
// prep.execute();
// // query(stat, "SELECT * FROM TEST");
// }
// System.out.println("delete=" + (System.currentTimeMillis() - time));
// System.out.println("total=" + (System.currentTimeMillis() - start));
// stat.executeUpdate("DROP TABLE Test");
//
// conn.close();
// prep = conn.prepareStatement("DELETE FROM Test WHERE Id=?");
//
// time = System.currentTimeMillis();
//
// for (int i = 0; i < len; i++) {
// // stat.executeUpdate("DELETE FROM Test WHERE Id="+i);
// prep.setInt(1, i);
// //System.out.println("delete "+i);
// prep.execute();
// // query(stat, "SELECT * FROM TEST");
// }
// System.out.println("delete=" + (System.currentTimeMillis() - time));
// System.out.println("total=" + (System.currentTimeMillis() - start));
// stat.executeUpdate("DROP TABLE Test");
//
// conn.close();
/*
* stat.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, VALUE
* DATE)"); stat.executeUpdate("INSERT INTO TEST VALUES(1, DATE
* '2004-12-19')"); stat.executeUpdate("INSERT INTO TEST VALUES(2, DATE
* '2004-12-20')"); query(stat, "SELECT * FROM TEST WHERE VALUE > DATE
* '2004-12-19'");
* stat.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, VALUE DATE)");
* stat.executeUpdate("INSERT INTO TEST VALUES(1, DATE '2004-12-19')");
* stat.executeUpdate("INSERT INTO TEST VALUES(2, DATE '2004-12-20')");
* query(stat, "SELECT * FROM TEST WHERE VALUE > DATE '2004-12-19'");
*/
/*
* stat.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, VALUE
* BINARY(10))"); stat.executeUpdate("INSERT INTO TEST VALUES(1,
* X'0011')"); stat.executeUpdate("INSERT INTO TEST VALUES(2,
* X'01FFAA')"); query(stat, "SELECT * FROM TEST WHERE VALUE >
* X'0011'");
* BINARY(10))"); stat.executeUpdate("INSERT INTO TEST VALUES(1, X'0011')");
* stat.executeUpdate("INSERT INTO TEST VALUES(2, X'01FFAA')"); query(stat,
* "SELECT * FROM TEST WHERE VALUE > X'0011'");
*/
/*
* stat.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME
* VARCHAR(255))"); stat.executeUpdate("INSERT INTO TEST VALUES(1,
* 'Hallo')"); stat.executeUpdate("INSERT INTO TEST VALUES(2,
* 'World')");
* 'Hallo')"); stat.executeUpdate("INSERT INTO TEST VALUES(2, 'World')");
*/
/*
* stat.executeUpdate("CREATE UNIQUE INDEX TEST_NAME ON TEST(NAME)");
* stat.executeUpdate("DROP INDEX TEST_NAME");
* stat.executeUpdate("INSERT INTO TEST VALUES(2, 'Hallo')
");
* stat.executeUpdate("DELETE FROM TEST"); for(int i=0; i <100; i++) {
* stat.executeUpdate("INSERT INTO TEST
VALUES("+i+", 'Test"+i+"')"); }
* stat.executeUpdate("DROP INDEX TEST_NAME"); stat.executeUpdate("INSERT
* INTO TEST VALUES(2, 'Hallo')"); stat.executeUpdate("DELETE FROM TEST
");
* for(int i=0; i <100; i++) { stat.executeUpdate("INSERT INTO TEST
*
VALUES("+i+", 'Test"+i+"')"); }
*/
/*
* query(stat, "SELECT T1.ID, T1.NAME FROM TEST T1"); query(stat,
* "SELECT T1.ID, T1.NAME, T2.ID, T2.NAME FROM TEST T1, TEST T2");
* query(stat, "SELECT T1.ID, T1.NAME, T2.ID, T2.NAME FROM TEST T1, TEST
* T2 WHERE T1.ID =
T2.ID");
* query(stat, "SELECT T1.ID, T1.NAME FROM TEST T1"); query(stat, "SELECT
* T1.ID, T1.NAME, T2.ID, T2.NAME FROM TEST T1, TEST T2"); query(stat,
* "SELECT T1.ID, T1.NAME, T2.ID, T2.NAME FROM TEST T1, TEST T2 WHERE T1.ID =
*
T2.ID");
*/
/*
* query(stat, "SELECT * FROM TEST WHERE ID = 1");
* stat.executeUpdate("DELETE FROM TEST WHERE ID = 2"); query(stat,
* "SELECT * FROM TEST WHERE ID < 10"); query(stat, "SELECT * FROM TEST
* WHERE ID = 2"); stat.executeUpdate("UPDATE TEST SET NAME = 'World'
* WHERE ID = 5"); query(stat, "SELECT * FROM TEST WHERE ID = 5");
* query(stat, "SELECT
* FROM TEST WHERE ID < 10");
* stat.executeUpdate("DELETE FROM TEST WHERE ID = 2"); query(stat, "SELECT *
* FROM TEST WHERE ID < 10"); query(stat, "SELECT * FROM TEST WHERE ID =
* 2"); stat.executeUpdate("UPDATE TEST SET NAME = 'World' WHERE ID = 5");
* query(stat, "SELECT * FROM TEST WHERE ID = 5"); query(stat, "SELECT *
* FROM TEST WHERE ID < 10");
*/
// }
// private static void query(Statement stat, String sql) throws SQLException {
// System.out.println("--------- " + sql);
// ResultSet rs = stat.executeQuery(sql);
// ResultSetMetaData meta = rs.getMetaData();
// while (rs.next()) {
// for (int i = 0; i < meta.getColumnCount(); i++) {
// System.out.print("[" + meta.getColumnLabel(i + 1) + "]="
// + rs.getString(i + 1) + " ");
// }
// System.out.println();
// }
// }
// }
// private static void query(Statement stat, String sql) throws SQLException
// {
// System.out.println("--------- " + sql);
// ResultSet rs = stat.executeQuery(sql);
// ResultSetMetaData meta = rs.getMetaData();
// while (rs.next()) {
// for (int i = 0; i < meta.getColumnCount(); i++) {
// System.out.print("[" + meta.getColumnLabel(i + 1) + "]="
// + rs.getString(i + 1) + " ");
// }
// System.out.println();
// }
// }
}
h2/src/test/org/h2/test/db/TestTempTables.java
浏览文件 @
f447a3e4
...
...
@@ -34,7 +34,8 @@ public class TestTempTables extends TestBase {
s2
.
execute
(
"DROP TABLE LT"
);
s1
.
execute
(
"DROP TABLE LT"
);
// temp tables: 'on commit' syntax is currently not documented, because not tested well
// temp tables: 'on commit' syntax is currently not documented, because
// not tested well
// and hopefully nobody is using it, as it looks like functional sugar
// (this features are here for compatibility only)
ResultSet
rs
;
...
...
@@ -56,7 +57,7 @@ public class TestTempTables extends TestBase {
try
{
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
error
(
"test_temp should have been dropped automatically"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
...
...
h2/src/test/org/h2/test/db/TestTransaction.java
浏览文件 @
f447a3e4
...
...
@@ -35,40 +35,44 @@ public class TestTransaction extends TestBase {
int
len
=
getSize
(
2000
,
10000
);
Random
random
=
new
Random
(
10
);
Savepoint
sp
=
null
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
tableId
=
random
.
nextInt
(
2
);
String
table
=
"TEST"
+
tableId
;
String
table
=
"TEST"
+
tableId
;
int
op
=
random
.
nextInt
(
6
);
switch
(
op
)
{
switch
(
op
)
{
case
0
:
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) VALUES('op"
+
i
+
"')"
);
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) VALUES('op"
+
i
+
"')"
);
count
[
tableId
]++;
break
;
case
1
:
if
(
count
[
tableId
]
>
0
)
{
stat
.
execute
(
"DELETE FROM "
+
table
+
" WHERE ID=SELECT MIN(ID) FROM "
+
table
);
if
(
count
[
tableId
]
>
0
)
{
stat
.
execute
(
"DELETE FROM "
+
table
+
" WHERE ID=SELECT MIN(ID) FROM "
+
table
);
count
[
tableId
]--;
}
break
;
case
2
:
sp
=
conn
.
setSavepoint
();
countSave
[
0
]
=
count
[
0
];
countSave
[
1
]
=
count
[
1
];
countSave
[
0
]
=
count
[
0
];
countSave
[
1
]
=
count
[
1
];
break
;
case
3
:
if
(
sp
!=
null
)
{
if
(
sp
!=
null
)
{
conn
.
rollback
(
sp
);
count
[
0
]
=
countSave
[
0
];
count
[
1
]
=
countSave
[
1
];
count
[
0
]
=
countSave
[
0
];
count
[
1
]
=
countSave
[
1
];
}
break
;
case
4
:
conn
.
commit
();
sp
=
null
;
countCommitted
[
0
]
=
count
[
0
];
countCommitted
[
1
]
=
count
[
1
];
countCommitted
[
0
]
=
count
[
0
];
countCommitted
[
1
]
=
count
[
1
];
break
;
case
5
:
conn
.
rollback
();
sp
=
null
;
count
[
0
]
=
countCommitted
[
0
];
count
[
1
]
=
countCommitted
[
1
];
count
[
0
]
=
countCommitted
[
0
];
count
[
1
]
=
countCommitted
[
1
];
break
;
}
checkTableCount
(
stat
,
"TEST0"
,
count
[
0
]);
...
...
@@ -86,12 +90,12 @@ public class TestTransaction extends TestBase {
public
void
testIsolation
()
throws
Exception
{
Connection
conn
=
getConnection
(
"transaction"
);
trace
(
"default TransactionIsolation="
+
conn
.
getTransactionIsolation
());
trace
(
"default TransactionIsolation="
+
conn
.
getTransactionIsolation
());
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_READ_COMMITTED
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_READ_COMMITTED
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_READ_COMMITTED
);
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_SERIALIZABLE
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_SERIALIZABLE
);
Statement
stat
=
conn
.
createStatement
();
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_SERIALIZABLE
);
Statement
stat
=
conn
.
createStatement
();
check
(
conn
.
getAutoCommit
());
conn
.
setAutoCommit
(
false
);
checkFalse
(
conn
.
getAutoCommit
());
...
...
@@ -101,10 +105,10 @@ public class TestTransaction extends TestBase {
conn
.
commit
();
test
(
stat
,
"INSERT INTO TEST VALUES(0)"
);
conn
.
rollback
();
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
conn
.
setAutoCommit
(
false
);
test
(
stat
,
"DELETE FROM TEST"
);
//testValue("SELECT COUNT(*) FROM TEST", "0");
//
testValue("SELECT COUNT(*) FROM TEST", "0");
conn
.
rollback
();
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
conn
.
commit
();
...
...
@@ -119,70 +123,70 @@ public class TestTransaction extends TestBase {
Statement
stat
=
conn
.
createStatement
();
test
(
stat
,
"CREATE TABLE NEST1(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
test
(
stat
,
"CREATE TABLE NEST2(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
DatabaseMetaData
meta
=
conn
.
getMetaData
();
DatabaseMetaData
meta
=
conn
.
getMetaData
();
Vector
result
;
ResultSet
rs1
,
rs2
;
result
=
new
Vector
();
rs1
=
meta
.
getTables
(
null
,
null
,
"NEST%"
,
null
);
while
(
rs1
.
next
())
{
String
table
=
rs1
.
getString
(
"TABLE_NAME"
);
rs2
=
meta
.
getColumns
(
null
,
null
,
table
,
null
);
while
(
rs2
.
next
())
{
String
column
=
rs2
.
getString
(
"COLUMN_NAME"
);
trace
(
"Table: "
+
table
+
" Column: "
+
column
);
result
.
add
(
table
+
"."
+
column
);
}
}
if
(
result
.
size
()!=
4
)
{
error
(
"Wrong result, should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME but is "
+
result
);
}
result
=
new
Vector
();
ResultSet
rs1
,
rs2
;
result
=
new
Vector
();
rs1
=
meta
.
getTables
(
null
,
null
,
"NEST%"
,
null
);
while
(
rs1
.
next
())
{
String
table
=
rs1
.
getString
(
"TABLE_NAME"
);
rs2
=
meta
.
getColumns
(
null
,
null
,
table
,
null
);
while
(
rs2
.
next
())
{
String
column
=
rs2
.
getString
(
"COLUMN_NAME"
);
trace
(
"Table: "
+
table
+
" Column: "
+
column
);
result
.
add
(
table
+
"."
+
column
);
}
}
if
(
result
.
size
()
!=
4
)
{
error
(
"Wrong result, should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME but is "
+
result
);
}
result
=
new
Vector
();
test
(
stat
,
"INSERT INTO NEST1 VALUES(1,'A')"
);
test
(
stat
,
"INSERT INTO NEST1 VALUES(2,'B')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(1,'1')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(2,'2')"
);
Statement
s1
=
conn
.
createStatement
();
Statement
s2
=
conn
.
createStatement
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
while
(
rs1
.
next
())
{
rs2
=
s2
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
while
(
rs2
.
next
())
{
String
v1
=
rs1
.
getString
(
"VALUE"
);
String
v2
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
+
"/"
+
v2
);
}
}
if
(
result
.
size
()!=
4
)
{
error
(
"Wrong result, should be A/1, A/2, B/1, B/2 but is "
+
result
);
}
result
=
new
Vector
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs2
=
s1
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
Statement
s1
=
conn
.
createStatement
();
Statement
s2
=
conn
.
createStatement
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
while
(
rs1
.
next
())
{
rs2
=
s2
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
while
(
rs2
.
next
())
{
String
v1
=
rs1
.
getString
(
"VALUE"
);
String
v2
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
+
"/"
+
v2
);
}
}
if
(
result
.
size
()
!=
4
)
{
error
(
"Wrong result, should be A/1, A/2, B/1, B/2 but is "
+
result
);
}
result
=
new
Vector
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs2
=
s1
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
try
{
rs1
.
next
();
error
(
"next worked on a closed result set"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
// this is already closed, so but closing again should no do any harm
rs1
.
close
();
while
(
rs2
.
next
())
{
String
v1
=
rs2
.
getString
(
"VALUE"
);
while
(
rs2
.
next
())
{
String
v1
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
);
}
if
(
result
.
size
()!=
2
)
{
error
(
"Wrong result, should be A, B but is "
+
result
);
if
(
result
.
size
()
!=
2
)
{
error
(
"Wrong result, should be A, B but is "
+
result
);
}
test
(
stat
,
"DROP TABLE NEST1"
);
test
(
stat
,
"DROP TABLE NEST2"
);
}
void
testValue
(
Statement
stat
,
String
sql
,
String
data
)
throws
Exception
{
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
rs
.
next
();
String
s
=
rs
.
getString
(
1
);
if
(
s
==
null
?
(
data
!=
null
)
:
(!
s
.
equals
(
data
)))
{
error
(
"s= "
+
s
+
" should be: "
+
data
);
String
s
=
rs
.
getString
(
1
);
if
(
s
==
null
?
(
data
!=
null
)
:
(!
s
.
equals
(
data
)))
{
error
(
"s= "
+
s
+
" should be: "
+
data
);
}
}
...
...
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
浏览文件 @
f447a3e4
...
...
@@ -13,7 +13,7 @@ import org.h2.test.TestBase;
public
class
TestTwoPhaseCommit
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
||
config
.
networked
||
config
.
logMode
==
0
)
{
if
(
config
.
memory
||
config
.
networked
||
config
.
logMode
==
0
)
{
return
;
}
...
...
@@ -36,7 +36,7 @@ public class TestTwoPhaseCommit extends TestBase {
rs
.
next
();
check
(
rs
.
getInt
(
1
),
1
);
check
(
rs
.
getString
(
2
),
"Hello"
);
if
(
rolledBack
)
{
if
(
rolledBack
)
{
}
else
{
rs
.
next
();
check
(
rs
.
getInt
(
1
),
2
);
...
...
@@ -51,12 +51,12 @@ public class TestTwoPhaseCommit extends TestBase {
Statement
stat
=
conn
.
createStatement
();
ArrayList
list
=
new
ArrayList
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
list
.
add
(
rs
.
getString
(
"TRANSACTION"
));
}
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
s
=
(
String
)
list
.
get
(
i
);
if
(
rollback
)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
s
=
(
String
)
list
.
get
(
i
);
if
(
rollback
)
{
stat
.
execute
(
"ROLLBACK TRANSACTION "
+
s
);
}
else
{
stat
.
execute
(
"COMMIT TRANSACTION "
+
s
);
...
...
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
f447a3e4
...
...
@@ -17,10 +17,10 @@ public class TestView extends TestBase {
Statement
s
=
conn
.
createStatement
();
s
.
execute
(
"create table t0(id int primary key)"
);
s
.
execute
(
"insert into t0 values(1), (2), (3)"
);
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"select * from t"
+
(
i
+
1
));
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"select * from t"
+
(
i
+
1
));
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
check
(
rs
.
next
());
check
(
rs
.
getInt
(
1
),
1
);
}
...
...
h2/src/test/org/h2/test/unit/TestBitField.java
浏览文件 @
f447a3e4
...
...
@@ -27,10 +27,10 @@ public class TestBitField extends TestBase {
int
max
=
300
;
int
count
=
100000
;
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
int
idx
=
random
.
nextInt
(
max
);
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
bits
.
set
(
idx
);
set
.
set
(
idx
);
}
else
{
...
...
@@ -47,23 +47,23 @@ public class TestBitField extends TestBase {
void
testGetSet
()
throws
Exception
{
BitField
bits
=
new
BitField
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
bits
.
set
(
i
);
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
}
if
(
bits
.
get
(
i
+
1
))
{
throw
new
Exception
(
"set: "
+
i
);
if
(
bits
.
get
(
i
+
1
))
{
throw
new
Exception
(
"set: "
+
i
);
}
}
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
}
}
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
int
k
=
bits
.
nextClearBit
(
0
);
if
(
k
!=
10000
)
{
if
(
k
!=
10000
)
{
throw
new
Exception
(
""
+
k
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestCache.java
浏览文件 @
f447a3e4
...
...
@@ -14,7 +14,7 @@ import org.h2.test.TestBase;
public
class
TestCache
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"cache"
);
...
...
@@ -26,7 +26,7 @@ public class TestCache extends TestBase {
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
PreparedStatement
prep2
=
conn
.
prepareStatement
(
"INSERT INTO MAIN VALUES(?, ?)"
);
int
max
=
10000
;
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setString
(
2
,
"Hello "
+
i
);
prep
.
execute
();
...
...
@@ -39,10 +39,10 @@ public class TestCache extends TestBase {
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET CACHE_SIZE 1024"
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID BETWEEN 40 AND 50"
);
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID = "
+
random
.
nextInt
(
max
));
if
((
i
%
10
)
==
0
)
{
if
((
i
%
10
)
==
0
)
{
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestCompress.java
浏览文件 @
f447a3e4
...
...
@@ -12,11 +12,11 @@ import org.h2.tools.CompressTool;
public
class
TestCompress
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
big
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
if
(
config
.
big
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
test
(
i
);
}
for
(
int
i
=
100
;
i
<
10000
;
i
+=
(
i
+
i
+
1
))
{
for
(
int
i
=
100
;
i
<
10000
;
i
+=
(
i
+
i
+
1
))
{
test
(
i
);
}
}
else
{
...
...
@@ -29,15 +29,15 @@ public class TestCompress extends TestBase {
}
void
test
(
int
len
)
throws
Exception
{
for
(
int
pattern
=
0
;
pattern
<
3
;
pattern
++)
{
for
(
int
pattern
=
0
;
pattern
<
3
;
pattern
++)
{
byte
[]
buff
=
new
byte
[
len
];
switch
(
pattern
)
{
switch
(
pattern
)
{
case
0
:
// leave empty
break
;
case
1
:
{
for
(
int
x
=
0
;
x
<
len
;
x
++)
{
buff
[
x
]
=
(
byte
)(
x
&
10
);
for
(
int
x
=
0
;
x
<
len
;
x
++)
{
buff
[
x
]
=
(
byte
)
(
x
&
10
);
}
break
;
}
...
...
@@ -47,11 +47,9 @@ public class TestCompress extends TestBase {
break
;
}
}
String
[]
algorithm
=
new
String
[]{
"LZF"
,
"Deflate"
,
"No"
};
String
[]
algorithm
=
new
String
[]
{
"LZF"
,
"Deflate"
,
"No"
};
CompressTool
utils
=
CompressTool
.
getInstance
();
for
(
int
i
=
0
;
i
<
algorithm
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
algorithm
.
length
;
i
++)
{
byte
[]
out
=
utils
.
compress
(
buff
,
algorithm
[
i
]);
byte
[]
test
=
utils
.
expand
(
out
);
check
(
test
.
length
,
buff
.
length
);
...
...
h2/src/test/org/h2/test/unit/TestDataPage.java
浏览文件 @
f447a3e4
...
...
@@ -35,8 +35,8 @@ public class TestDataPage extends TestBase implements DataHandler {
DataPage
page
=
DataPage
.
create
(
this
,
128
);
char
[]
data
=
new
char
[
0x10000
];
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
data
[
i
]
=
(
char
)
i
;
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
data
[
i
]
=
(
char
)
i
;
}
String
s
=
new
String
(
data
);
page
.
writeString
(
s
);
...
...
@@ -60,8 +60,8 @@ public class TestDataPage extends TestBase implements DataHandler {
trace
(
page
.
readString
());
trace
(
page
.
readValue
().
getInt
());
trace
(
page
.
readValue
().
getString
());
trace
(
""
+
page
.
readValue
().
getFloat
());
trace
(
""
+
page
.
readValue
().
getDouble
());
trace
(
""
+
page
.
readValue
().
getFloat
());
trace
(
""
+
page
.
readValue
().
getDouble
());
trace
(
page
.
readValue
().
toString
());
page
.
reset
();
...
...
@@ -98,7 +98,7 @@ public class TestDataPage extends TestBase implements DataHandler {
}
public
int
getChecksum
(
byte
[]
data
,
int
start
,
int
end
)
{
return
end
-
start
;
return
end
-
start
;
}
public
void
checkPowerOff
()
throws
SQLException
{
...
...
h2/src/test/org/h2/test/unit/TestExit.java
浏览文件 @
f447a3e4
...
...
@@ -16,18 +16,14 @@ import org.h2.test.TestBase;
public
class
TestExit
extends
TestBase
implements
DatabaseEventListener
{
public
void
test
()
throws
Exception
{
if
(
config
.
codeCoverage
)
{
if
(
config
.
codeCoverage
)
{
return
;
}
String
classPath
=
"bin"
+
File
.
pathSeparator
+
"."
;
String
classPath
=
"bin"
+
File
.
pathSeparator
+
"."
;
deleteDb
(
"exit"
);
String
[]
procDef
;
procDef
=
new
String
[]{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITH_CLOSE_ON_EXIT
};
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITH_CLOSE_ON_EXIT
};
Process
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
while
(
true
)
{
int
ch
=
proc
.
getErrorStream
().
read
();
...
...
@@ -44,17 +40,13 @@ public class TestExit extends TestBase implements DatabaseEventListener {
System
.
out
.
print
((
char
)
ch
);
}
proc
.
waitFor
();
if
(!
getClosedFile
().
exists
())
{
if
(!
getClosedFile
().
exists
())
{
error
(
"did not close database"
);
}
procDef
=
new
String
[]{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITHOUT_CLOSE_ON_EXIT
};
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITHOUT_CLOSE_ON_EXIT
};
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
proc
.
waitFor
();
if
(
getClosedFile
().
exists
())
{
if
(
getClosedFile
().
exists
())
{
error
(
"closed database"
);
}
}
...
...
@@ -64,7 +56,7 @@ public class TestExit extends TestBase implements DatabaseEventListener {
public
static
Connection
conn
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
args
.
length
==
0
)
{
if
(
args
.
length
==
0
)
{
System
.
exit
(
1
);
}
int
action
=
Integer
.
parseInt
(
args
[
0
]);
...
...
@@ -75,12 +67,14 @@ public class TestExit extends TestBase implements DatabaseEventListener {
void
execute
(
int
action
)
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
""
;
switch
(
action
)
{
switch
(
action
)
{
case
OPEN_WITH_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=true"
;
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=true"
;
break
;
case
OPEN_WITHOUT_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=false"
;
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=false"
;
break
;
}
conn
=
open
(
url
);
...
...
@@ -102,7 +96,7 @@ public class TestExit extends TestBase implements DatabaseEventListener {
public
void
closingDatabase
()
{
try
{
getClosedFile
().
createNewFile
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestFileLock.java
浏览文件 @
f447a3e4
...
...
@@ -23,7 +23,8 @@ public class TestFileLock extends TestBase implements Runnable {
private
static
volatile
int
locks
;
private
static
volatile
boolean
stop
;
public
TestFileLock
()
{}
public
TestFileLock
()
{
}
public
void
test
()
throws
Exception
{
test
(
false
);
...
...
h2/src/test/org/h2/test/unit/TestIntArray.java
浏览文件 @
f447a3e4
...
...
@@ -19,11 +19,11 @@ public class TestIntArray extends TestBase {
IntArray
array
=
new
IntArray
();
int
[]
test
=
new
int
[
0
];
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
int
idx
=
test
.
length
==
0
?
0
:
random
.
nextInt
(
test
.
length
);
int
v
=
random
.
nextInt
(
100
);
int
op
=
random
.
nextInt
(
9
);
switch
(
op
)
{
switch
(
op
)
{
case
0
:
array
.
add
(
idx
,
v
);
test
=
add
(
test
,
idx
,
v
);
...
...
@@ -46,7 +46,7 @@ public class TestIntArray extends TestBase {
check
(
a
,
b
);
break
;
case
4
:
if
(
test
.
length
>
idx
)
{
if
(
test
.
length
>
idx
)
{
check
(
array
.
get
(
idx
),
get
(
test
,
idx
));
}
break
;
...
...
@@ -55,7 +55,7 @@ public class TestIntArray extends TestBase {
test
=
remove
(
test
,
idx
);
break
;
case
6
:
if
(
test
.
length
>
idx
)
{
if
(
test
.
length
>
idx
)
{
v
=
test
[
idx
];
array
.
removeValue
(
v
);
test
=
removeValue
(
test
,
v
);
...
...
@@ -70,7 +70,7 @@ public class TestIntArray extends TestBase {
break
;
}
check
(
array
.
size
(),
test
.
length
);
for
(
int
j
=
0
;
j
<
test
.
length
;
j
++)
{
for
(
int
j
=
0
;
j
<
test
.
length
;
j
++)
{
check
(
test
[
j
],
array
.
get
(
j
));
}
...
...
@@ -78,10 +78,10 @@ public class TestIntArray extends TestBase {
}
int
[]
add
(
int
[]
array
,
int
i
,
int
value
)
{
int
[]
a2
=
new
int
[
array
.
length
+
1
];
int
[]
a2
=
new
int
[
array
.
length
+
1
];
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
array
.
length
);
if
(
i
<
array
.
length
)
{
System
.
arraycopy
(
a2
,
i
,
a2
,
i
+
1
,
a2
.
length
-
i
-
1
);
if
(
i
<
array
.
length
)
{
System
.
arraycopy
(
a2
,
i
,
a2
,
i
+
1
,
a2
.
length
-
i
-
1
);
}
array
=
a2
;
array
[
i
]
=
value
;
...
...
@@ -93,11 +93,11 @@ public class TestIntArray extends TestBase {
}
int
[]
addValueSorted
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
<
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
<
value
)
{
continue
;
}
if
(
array
[
i
]
==
value
)
{
if
(
array
[
i
]
==
value
)
{
return
array
;
}
else
{
return
add
(
array
,
i
,
value
);
...
...
@@ -107,8 +107,8 @@ public class TestIntArray extends TestBase {
}
int
findNextValueIndex
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
>=
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
>=
value
)
{
return
i
;
}
}
...
...
@@ -120,17 +120,17 @@ public class TestIntArray extends TestBase {
}
int
[]
remove
(
int
[]
array
,
int
i
)
{
int
[]
a2
=
new
int
[
array
.
length
-
1
];
int
[]
a2
=
new
int
[
array
.
length
-
1
];
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
i
);
if
(
i
<
a2
.
length
)
{
System
.
arraycopy
(
array
,
i
+
1
,
a2
,
i
,
array
.
length
-
i
-
1
);
if
(
i
<
a2
.
length
)
{
System
.
arraycopy
(
array
,
i
+
1
,
a2
,
i
,
array
.
length
-
i
-
1
);
}
return
a2
;
}
int
[]
removeValue
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
==
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
==
value
)
{
return
remove
(
array
,
i
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestIntIntHashMap.java
浏览文件 @
f447a3e4
...
...
@@ -30,7 +30,7 @@ public class TestIntIntHashMap extends TestBase {
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
map
.
put
(
x
[
i
],
i
);
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
}
...
...
@@ -46,7 +46,7 @@ public class TestIntIntHashMap extends TestBase {
for
(
int
i
=
1
;
i
<
len
;
i
+=
2
)
{
map
.
put
(
x
[
i
],
i
);
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
}
...
...
h2/src/test/org/h2/test/unit/TestOverflow.java
浏览文件 @
f447a3e4
...
...
@@ -31,25 +31,25 @@ public class TestOverflow extends TestBase {
private
void
test
(
int
type
,
long
min
,
long
max
)
throws
Exception
{
values
=
new
ArrayList
();
this
.
type
=
type
;
this
.
min
=
new
BigInteger
(
""
+
min
);
this
.
max
=
new
BigInteger
(
""
+
max
);
this
.
min
=
new
BigInteger
(
""
+
min
);
this
.
max
=
new
BigInteger
(
""
+
max
);
add
(
0
);
add
(
min
);
add
(
max
);
add
(
max
-
1
);
add
(
min
+
1
);
add
(
max
-
1
);
add
(
min
+
1
);
add
(
1
);
add
(-
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
40
;
i
++)
{
if
(
max
>
Integer
.
MAX_VALUE
)
{
for
(
int
i
=
0
;
i
<
40
;
i
++)
{
if
(
max
>
Integer
.
MAX_VALUE
)
{
add
(
random
.
nextLong
());
}
else
{
add
((
random
.
nextBoolean
()
?
1
:
-
1
)
*
random
.
nextInt
((
int
)
max
));
add
((
random
.
nextBoolean
()
?
1
:
-
1
)
*
random
.
nextInt
((
int
)
max
));
}
}
for
(
int
a
=
0
;
a
<
values
.
size
();
a
++)
{
for
(
int
b
=
0
;
b
<
values
.
size
();
b
++)
{
for
(
int
a
=
0
;
a
<
values
.
size
();
a
++)
{
for
(
int
b
=
0
;
b
<
values
.
size
();
b
++)
{
Value
va
=
(
Value
)
values
.
get
(
a
);
Value
vb
=
(
Value
)
values
.
get
(
b
);
testValues
(
va
,
vb
);
...
...
@@ -58,19 +58,19 @@ public class TestOverflow extends TestBase {
}
void
checkIfExpected
(
String
a
,
String
b
)
throws
Exception
{
if
(
successExpected
)
{
if
(
successExpected
)
{
check
(
a
,
b
);
}
}
void
onSuccess
()
throws
Exception
{
if
(!
successExpected
&&
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
if
(!
successExpected
&&
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
error
(
"unexpected success"
);
}
}
void
onError
()
throws
Exception
{
if
(
successExpected
)
{
if
(
successExpected
)
{
error
(
"unexpected error"
);
}
}
...
...
@@ -82,28 +82,28 @@ public class TestOverflow extends TestBase {
try
{
checkIfExpected
(
va
.
negate
().
getString
(),
a
.
negate
().
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
successExpected
=
inRange
(
a
.
add
(
b
));
try
{
checkIfExpected
(
va
.
add
(
vb
).
getString
(),
a
.
add
(
b
).
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
successExpected
=
inRange
(
a
.
subtract
(
b
));
try
{
checkIfExpected
(
va
.
subtract
(
vb
).
getString
(),
a
.
subtract
(
b
).
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
successExpected
=
inRange
(
a
.
multiply
(
b
));
try
{
checkIfExpected
(
va
.
multiply
(
vb
).
getString
(),
a
.
multiply
(
b
).
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
}
...
...
h2/src/test/org/h2/test/unit/TestPattern.java
浏览文件 @
f447a3e4
...
...
@@ -21,9 +21,9 @@ public class TestPattern extends TestBase {
test
(
comp
,
"A"
,
"A%%"
);
test
(
comp
,
"A_A"
,
"%\\_%"
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
String
pattern
=
getRandomPattern
();
String
value
=
getRandomValue
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
String
pattern
=
getRandomPattern
();
String
value
=
getRandomValue
();
test
(
comp
,
value
,
pattern
);
}
}
...
...
@@ -32,30 +32,30 @@ public class TestPattern extends TestBase {
String
regexp
=
initPatternRegexp
(
pattern
,
'\\'
);
boolean
resultRegexp
=
value
.
matches
(
regexp
);
boolean
result
=
comp
.
test
(
pattern
,
value
,
'\\'
);
if
(
result
!=
resultRegexp
)
{
error
(
"Error: >"
+
value
+
"< LIKE >"
+
pattern
+
"< result="
+
result
+
" resultReg="
+
resultRegexp
);
if
(
result
!=
resultRegexp
)
{
error
(
"Error: >"
+
value
+
"< LIKE >"
+
pattern
+
"< result="
+
result
+
" resultReg="
+
resultRegexp
);
}
}
static
String
getRandomValue
()
{
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
(
int
)(
Math
.
random
()
*
10
);
int
len
=
(
int
)
(
Math
.
random
()
*
10
);
String
s
=
"AB_%\\"
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
s
.
charAt
((
int
)
(
Math
.
random
()*
s
.
length
())));
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
s
.
charAt
((
int
)
(
Math
.
random
()
*
s
.
length
())));
}
return
buff
.
toString
();
}
static
String
getRandomPattern
()
{
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
(
int
)(
Math
.
random
()
*
4
);
int
len
=
(
int
)
(
Math
.
random
()
*
4
);
String
s
=
"A%_\\"
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
c
=
s
.
charAt
((
int
)
(
Math
.
random
()*
s
.
length
()));
if
((
c
==
'_'
||
c
==
'%'
)
&&
Math
.
random
()
>
0.5
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
c
=
s
.
charAt
((
int
)
(
Math
.
random
()
*
s
.
length
()));
if
((
c
==
'_'
||
c
==
'%'
)
&&
Math
.
random
()
>
0.5
)
{
buff
.
append
(
'\\'
);
}
else
if
(
c
==
'\\'
)
{
}
else
if
(
c
==
'\\'
)
{
buff
.
append
(
c
);
}
buff
.
append
(
c
);
...
...
@@ -79,7 +79,7 @@ public class TestPattern extends TestBase {
buff
.
append
(
".*"
);
}
else
if
(
c
==
'_'
)
{
buff
.
append
(
'.'
);
}
else
if
(
c
==
'\\'
)
{
}
else
if
(
c
==
'\\'
)
{
buff
.
append
(
"\\\\"
);
}
else
{
buff
.
append
(
c
);
...
...
@@ -87,7 +87,7 @@ public class TestPattern extends TestBase {
// TODO regexp: there are other chars that need escaping
}
String
regexp
=
buff
.
toString
();
//
System.out.println("regexp = " + regexp);
//
System.out.println("regexp = " + regexp);
return
regexp
;
}
...
...
h2/src/test/org/h2/test/unit/TestSampleApps.java
浏览文件 @
f447a3e4
...
...
@@ -16,39 +16,38 @@ public class TestSampleApps extends TestBase {
public
void
test
()
throws
Exception
{
testApp
(
org
.
h2
.
samples
.
Compact
.
class
,
null
,
"Compacting...\nDone."
);
testApp
(
org
.
h2
.
samples
.
CsvSample
.
class
,
null
,
"NAME: Bob Meier\n"
+
"EMAIL: bob.meier@abcde.abc\n"
+
"PHONE: +41123456789\n\n"
+
"NAME: John Jones\n"
+
"EMAIL: john.jones@abcde.abc\n"
+
"PHONE: +41976543210\n"
);
testApp
(
org
.
h2
.
samples
.
CsvSample
.
class
,
null
,
"NAME: Bob Meier\n"
+
"EMAIL: bob.meier@abcde.abc\n"
+
"PHONE: +41123456789\n\n"
+
"NAME: John Jones\n"
+
"EMAIL: john.jones@abcde.abc\n"
+
"PHONE: +41976543210\n"
);
testApp
(
org
.
h2
.
samples
.
Function
.
class
,
null
,
"2 is prime\n3 is prime\n5 is prime\n7 is prime\n11 is prime\n13 is prime\n17 is prime\n19 is prime"
);
testApp
(
org
.
h2
.
samples
.
SecurePassword
.
class
,
null
,
"Hello"
);
// TODO test ShowProgress (percent numbers are hardware specific)
// TODO test ShutdownServer (server needs to be started in a separate process)
// TODO test ShutdownServer (server needs to be started in a separate
// process)
testApp
(
org
.
h2
.
samples
.
TriggerSample
.
class
,
null
,
"The sum is 20.00"
);
// tools
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
new
String
[]{
"-?"
},
"java org.h2.tools.ChangePassword [-dir <dir>] "
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
new
String
[]
{
"-?"
},
"java org.h2.tools.ChangePassword [-dir <dir>] "
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
null
,
"java org.h2.tools.ChangePassword [-dir <dir>] "
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
DeleteDbFiles
.
class
,
new
String
[]{
"-?"
},
"java org.h2.tools.DeleteDbFiles [-dir <dir>] [-db <database>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
DeleteDbFiles
.
class
,
new
String
[]
{
"-?"
},
"java org.h2.tools.DeleteDbFiles [-dir <dir>] [-db <database>] [-quiet]"
);
}
private
void
testApp
(
Class
clazz
,
String
[]
args
,
String
expected
)
throws
Exception
{
DeleteDbFiles
.
execute
(
"data"
,
"test"
,
true
);
Method
m
=
clazz
.
getMethod
(
"main"
,
new
Class
[]
{
String
[].
class
});
Method
m
=
clazz
.
getMethod
(
"main"
,
new
Class
[]
{
String
[].
class
});
PrintStream
oldOut
=
System
.
out
,
oldErr
=
System
.
err
;
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
PrintStream
out
=
new
PrintStream
(
buff
,
false
,
"UTF-8"
);
System
.
setOut
(
out
);
System
.
setErr
(
out
);
try
{
m
.
invoke
(
null
,
new
Object
[]
{
args
});
}
catch
(
Throwable
e
)
{
m
.
invoke
(
null
,
new
Object
[]
{
args
});
}
catch
(
Throwable
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
out
.
flush
();
...
...
h2/src/test/org/h2/test/unit/TestScriptReader.java
浏览文件 @
f447a3e4
...
...
@@ -20,24 +20,24 @@ public class TestScriptReader extends TestBase {
private
void
testRandom
()
throws
Exception
{
int
len
=
getSize
(
1000
,
10000
);
Random
random
=
new
Random
(
10
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
l
=
random
.
nextInt
(
10
);
String
[]
sql
=
new
String
[
l
];
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
sql
[
j
]
=
randomStatement
(
random
);
buff
.
append
(
sql
[
j
]);
if
(
j
<
l
-
1
)
{
if
(
j
<
l
-
1
)
{
buff
.
append
(
";"
);
}
}
String
s
=
buff
.
toString
();
StringReader
reader
=
new
StringReader
(
s
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
String
e
=
source
.
readStatement
();
String
c
=
sql
[
j
];
if
(
c
.
length
()
==
0
&&
j
==
l
-
1
)
{
if
(
c
.
length
()
==
0
&&
j
==
l
-
1
)
{
c
=
null
;
}
check
(
e
,
c
);
...
...
@@ -49,21 +49,21 @@ public class TestScriptReader extends TestBase {
private
String
randomStatement
(
Random
random
)
{
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
random
.
nextInt
(
5
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
switch
(
random
.
nextInt
(
10
))
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
switch
(
random
.
nextInt
(
10
))
{
case
0
:
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
" "
,
"*"
,
"a"
,
"0"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
" "
,
"*"
,
"a"
,
"0"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
break
;
}
case
1
:
{
buff
.
append
(
'\''
);
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\""
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]
{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\""
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
'\''
);
...
...
@@ -71,9 +71,9 @@ public class TestScriptReader extends TestBase {
}
case
2
:
{
buff
.
append
(
'"'
);
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\'"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]
{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\'"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
'"'
);
...
...
@@ -81,17 +81,17 @@ public class TestScriptReader extends TestBase {
}
case
3
:
{
buff
.
append
(
'-'
);
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
"*"
,
"a"
,
" "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
"*"
,
"a"
,
" "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
else
{
buff
.
append
(
'-'
);
String
[]
ch
=
new
String
[]{
";"
,
"-"
,
"//"
,
"/*"
,
"*/"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
String
[]
ch
=
new
String
[]
{
";"
,
"-"
,
"//"
,
"/*"
,
"*/"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
'\n'
);
...
...
@@ -100,17 +100,17 @@ public class TestScriptReader extends TestBase {
}
case
4
:
{
buff
.
append
(
'/'
);
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
"a"
,
" "
,
"- "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
"a"
,
" "
,
"- "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
else
{
buff
.
append
(
'*'
);
String
[]
ch
=
new
String
[]{
";"
,
"-"
,
"//"
,
"/* "
,
"--"
,
"\n"
,
"\r"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
String
[]
ch
=
new
String
[]
{
";"
,
"-"
,
"//"
,
"/* "
,
"--"
,
"\n"
,
"\r"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
"*/"
);
...
...
@@ -123,16 +123,15 @@ public class TestScriptReader extends TestBase {
}
private
void
testCommon
()
throws
Exception
{
String
s
=
"a;';';\";\";--;\n;/*;\n*/;//;\na;"
;
String
s
=
"a;';';\";\";--;\n;/*;\n*/;//;\na;"
;
StringReader
reader
=
new
StringReader
(
s
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
check
(
source
.
readStatement
(),
"a"
);
check
(
source
.
readStatement
(),
"';'"
);
check
(
source
.
readStatement
(),
"\";\""
);
check
(
source
.
readStatement
(),
"--;\n"
);
check
(
source
.
readStatement
(),
"/*;\n*/"
);
check
(
source
.
readStatement
(),
"//;\na"
);
check
(
source
.
readStatement
(),
"a"
);
check
(
source
.
readStatement
(),
"';'"
);
check
(
source
.
readStatement
(),
"\";\""
);
check
(
source
.
readStatement
(),
"--;\n"
);
check
(
source
.
readStatement
(),
"/*;\n*/"
);
check
(
source
.
readStatement
(),
"//;\na"
);
check
(
source
.
readStatement
(),
null
);
source
.
close
();
}
...
...
h2/src/test/org/h2/test/unit/TestSecurity.java
浏览文件 @
f447a3e4
...
...
@@ -10,7 +10,6 @@ import org.h2.security.XTEA;
import
org.h2.test.TestBase
;
import
org.h2.util.ByteUtils
;
/**
* @author Thomas
*/
...
...
@@ -34,26 +33,23 @@ public class TestSecurity extends TestBase {
}
private
void
testOneSHA
(
SHA256
sha
)
throws
Exception
{
if
(!
getHashString
(
sha
,
new
byte
[]
{
})
.
equals
(
if
(!
getHashString
(
sha
,
new
byte
[]
{}).
equals
(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
))
{
throw
new
Exception
(
"x"
);
}
if
(!
getHashString
(
sha
,
new
byte
[]
{
0x19
})
.
equals
(
if
(!
getHashString
(
sha
,
new
byte
[]
{
0x19
}).
equals
(
"68aa2e2ee5dff96e3355e6c7ee373e3d6a4e17f75f9518d843709c0c9bc3e3d4"
))
{
throw
new
Exception
(
"x"
);
}
if
(!
getHashString
(
sha
,
new
byte
[]
{
(
byte
)
0xe3
,
(
byte
)
0xd7
,
0x25
,
0x70
,
(
byte
)
0xdc
,
(
byte
)
0xdd
,
0x78
,
0x7c
,
(
byte
)
0xe3
,
(
byte
)
0x88
,
0x7a
,
(
byte
)
0xb2
,
(
byte
)
0xcd
,
0x68
,
0x46
,
0x52
})
.
equals
(
if
(!
getHashString
(
sha
,
new
byte
[]
{
(
byte
)
0xe3
,
(
byte
)
0xd7
,
0x25
,
0x70
,
(
byte
)
0xdc
,
(
byte
)
0xdd
,
0x78
,
0x7c
,
(
byte
)
0xe3
,
(
byte
)
0x88
,
0x7a
,
(
byte
)
0xb2
,
(
byte
)
0xcd
,
0x68
,
0x46
,
0x52
}).
equals
(
"175ee69b02ba9b58e2b0a5fd13819cea573f3940a94f825128cf4209beabb4e8"
))
{
throw
new
Exception
(
"x"
);
}
}
public
void
testXTEA
()
throws
Exception
{
byte
[]
test
=
new
byte
[
4096
];
XTEA
xtea
=
new
XTEA
();
...
...
@@ -71,7 +67,7 @@ public class TestSecurity extends TestBase {
byte
[]
enc
=
new
byte
[
128
];
test
.
encrypt
(
enc
,
0
,
128
);
test
.
decrypt
(
enc
,
0
,
128
);
if
(
ByteUtils
.
compareNotNull
(
in
,
enc
)!=
0
)
{
if
(
ByteUtils
.
compareNotNull
(
in
,
enc
)
!=
0
)
{
throw
new
Error
(
"hey!"
);
}
...
...
@@ -81,5 +77,4 @@ public class TestSecurity extends TestBase {
}
}
}
h2/src/test/org/h2/test/unit/TestStreams.java
浏览文件 @
f447a3e4
...
...
@@ -19,15 +19,15 @@ public class TestStreams extends TestBase {
}
byte
[]
getRandomBytes
(
Random
random
)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
1000
),
random
.
nextInt
(
100000
),
random
.
nextInt
(
1000000
)
};
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
1000
),
random
.
nextInt
(
100000
),
random
.
nextInt
(
1000000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
byte
[]
buffer
=
new
byte
[
size
];
if
(
random
.
nextInt
(
5
)
==
1
)
{
if
(
random
.
nextInt
(
5
)
==
1
)
{
random
.
nextBytes
(
buffer
);
}
else
if
(
random
.
nextBoolean
())
{
int
patternLen
=
random
.
nextInt
(
100
)
+
1
;
for
(
int
j
=
0
;
j
<
size
;
j
++)
{
buffer
[
j
]
=
(
byte
)(
j
%
patternLen
);
}
else
if
(
random
.
nextBoolean
())
{
int
patternLen
=
random
.
nextInt
(
100
)
+
1
;
for
(
int
j
=
0
;
j
<
size
;
j
++)
{
buffer
[
j
]
=
(
byte
)
(
j
%
patternLen
);
}
}
return
buffer
;
...
...
@@ -36,23 +36,23 @@ public class TestStreams extends TestBase {
private
void
testLZFStreams
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
int
max
=
getSize
(
100
,
1000
);
for
(
int
i
=
0
;
i
<
max
;
i
+=
3
)
{
for
(
int
i
=
0
;
i
<
max
;
i
+=
3
)
{
byte
[]
buffer
=
getRandomBytes
(
random
);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
LZFOutputStream
comp
=
new
LZFOutputStream
(
out
);
if
(
random
.
nextInt
(
10
)
==
1
)
{
if
(
random
.
nextInt
(
10
)
==
1
)
{
comp
.
write
(
buffer
);
}
else
{
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
size
=
Math
.
min
(
size
,
buffer
.
length
-
j
);
if
(
size
==
1
)
{
if
(
size
==
1
)
{
comp
.
write
(
buffer
[
j
]);
}
else
{
comp
.
write
(
buffer
,
j
,
size
);
}
j
+=
size
;
j
+=
size
;
}
}
comp
.
close
();
...
...
@@ -60,19 +60,19 @@ public class TestStreams extends TestBase {
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
compressed
);
LZFInputStream
decompress
=
new
LZFInputStream
(
in
);
byte
[]
test
=
new
byte
[
buffer
.
length
];
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
if
(
size
==
1
)
{
if
(
size
==
1
)
{
int
x
=
decompress
.
read
();
if
(
x
<
0
)
{
if
(
x
<
0
)
{
break
;
}
test
[
j
++]
=
(
byte
)
x
;
test
[
j
++]
=
(
byte
)
x
;
}
else
{
size
=
Math
.
min
(
size
,
test
.
length
-
j
);
size
=
Math
.
min
(
size
,
test
.
length
-
j
);
int
l
=
decompress
.
read
(
test
,
j
,
size
);
if
(
l
<
0
)
{
if
(
l
<
0
)
{
break
;
}
else
{
j
+=
l
;
...
...
h2/src/test/org/h2/test/unit/TestStringCache.java
浏览文件 @
f447a3e4
...
...
@@ -17,18 +17,18 @@ public class TestStringCache extends TestBase {
private
void
runBenchmark
()
throws
Exception
{
returnNew
=
false
;
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
useIntern
=
(
i
%
2
)
==
1
;
long
time
=
System
.
currentTimeMillis
();
testSingleThread
(
100000
);
time
=
System
.
currentTimeMillis
()
-
time
;
System
.
out
.
println
(
time
+
" ms (useIntern="
+
useIntern
+
")"
);
time
=
System
.
currentTimeMillis
()
-
time
;
System
.
out
.
println
(
time
+
" ms (useIntern="
+
useIntern
+
")"
);
}
}
private
Random
random
=
new
Random
(
1
);
private
String
[]
some
=
new
String
[]
{
null
,
""
,
"ABC"
,
"this is a medium sized string"
,
"1"
,
"2"
};
private
String
[]
some
=
new
String
[]
{
null
,
""
,
"ABC"
,
"this is a medium sized string"
,
"1"
,
"2"
};
private
volatile
boolean
stop
;
private
boolean
returnNew
;
private
boolean
useIntern
;
...
...
@@ -45,16 +45,16 @@ public class TestStringCache extends TestBase {
}
String
randomString
()
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
String
s
=
some
[
random
.
nextInt
(
some
.
length
)];
if
(
s
!=
null
&&
random
.
nextBoolean
())
{
if
(
s
!=
null
&&
random
.
nextBoolean
())
{
s
=
new
String
(
s
);
}
return
s
;
}
else
{
int
len
=
random
.
nextBoolean
()
?
random
.
nextInt
(
1000
)
:
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
random
.
nextInt
(
0xfff
));
}
return
buff
.
toString
();
...
...
@@ -63,19 +63,19 @@ public class TestStringCache extends TestBase {
void
testString
()
{
String
a
=
randomString
();
if
(
returnNew
)
{
if
(
returnNew
)
{
String
b
=
StringCache
.
getNew
(
a
);
try
{
check
(
a
,
b
);
}
catch
(
Exception
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
if
(
a
!=
null
&&
a
==
b
&&
a
.
length
()>
0
)
{
if
(
a
!=
null
&&
a
==
b
&&
a
.
length
()
>
0
)
{
throw
new
Error
(
"a="
+
System
.
identityHashCode
(
a
)
+
" b="
+
System
.
identityHashCode
(
b
));
}
}
else
{
String
b
;
if
(
useIntern
)
{
if
(
useIntern
)
{
b
=
a
==
null
?
null
:
a
.
intern
();
}
else
{
b
=
StringCache
.
get
(
a
);
...
...
@@ -89,7 +89,7 @@ public class TestStringCache extends TestBase {
}
private
void
testSingleThread
(
int
len
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
testString
();
}
}
...
...
@@ -97,23 +97,23 @@ public class TestStringCache extends TestBase {
private
void
testMultiThreads
()
throws
Exception
{
int
threadCount
=
getSize
(
3
,
100
);
Thread
[]
threads
=
new
Thread
[
threadCount
];
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
Thread
t
=
new
Thread
(
new
Runnable
()
{
public
void
run
()
{
while
(!
stop
)
{
while
(!
stop
)
{
testString
();
}
}
});
threads
[
i
]
=
t
;
}
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
threads
[
i
].
start
();
}
int
wait
=
getSize
(
200
,
2000
);
Thread
.
sleep
(
wait
);
stop
=
true
;
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
threads
[
i
].
join
();
}
}
...
...
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
f447a3e4
...
...
@@ -28,64 +28,46 @@ public class TestStringUtils extends TestBase {
check
(
"Rand&Blue"
,
StringUtils
.
xmlText
(
"Rand&Blue"
));
check
(
"<<[[[]]]>>"
,
StringUtils
.
xmlCData
(
"<<[[[]]]>>"
));
Date
dt
=
StringUtils
.
parseDateTime
(
"2001-02-03 04:05:06 GMT"
,
"yyyy-MM-dd HH:mm:ss z"
,
"en"
,
"GMT"
);
String
s
=
StringUtils
.
xmlStartDoc
()
+
StringUtils
.
xmlComment
(
"Test Comment"
)
+
StringUtils
.
xmlNode
(
"rss"
,
StringUtils
.
xmlAttr
(
"version"
,
"2.0"
),
StringUtils
.
xmlComment
(
"Test Comment\nZeile2"
)
+
StringUtils
.
xmlNode
(
"channel"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
+
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"item"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"New Version 0.9.9.9.9"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
StringUtils
.
xmlCData
(
"\nNew Features\nTest\n"
)
)
)
)
);
check
(
s
,
"<?xml version=\"1.0\"?>\n"
+
"<!-- Test Comment -->\n"
+
"<rss version=\"2.0\">\n"
+
" <!--\n"
+
" Test Comment\n"
+
" Zeile2\n"
+
" -->\n"
+
" <channel>\n"
+
" <title>H2 Database Engine</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>H2 Database Engine</description>\n"
+
" <language>en-us</language>\n"
+
" <pubDate>Sat, 3 Feb 2001 04:05:06 GMT</pubDate>\n"
+
" <lastBuildDate>Sat, 3 Feb 2001 04:05:06 GMT</lastBuildDate>\n"
+
" <item>\n"
+
" <title>New Version 0.9.9.9.9</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>\n"
+
" <![CDATA[\n"
+
" New Features\n"
+
" Test\n"
+
" ]]>\n"
+
" </description>\n"
+
" </item>\n"
+
" </channel>\n"
+
"</rss>\n"
);
String
s
=
StringUtils
.
xmlStartDoc
()
+
StringUtils
.
xmlComment
(
"Test Comment"
)
+
StringUtils
.
xmlNode
(
"rss"
,
StringUtils
.
xmlAttr
(
"version"
,
"2.0"
),
StringUtils
.
xmlComment
(
"Test Comment\nZeile2"
)
+
StringUtils
.
xmlNode
(
"channel"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
+
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"item"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"New Version 0.9.9.9.9"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
StringUtils
.
xmlCData
(
"\nNew Features\nTest\n"
)))));
check
(
s
,
"<?xml version=\"1.0\"?>\n"
+
"<!-- Test Comment -->\n"
+
"<rss version=\"2.0\">\n"
+
" <!--\n"
+
" Test Comment\n"
+
" Zeile2\n"
+
" -->\n"
+
" <channel>\n"
+
" <title>H2 Database Engine</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>H2 Database Engine</description>\n"
+
" <language>en-us</language>\n"
+
" <pubDate>Sat, 3 Feb 2001 04:05:06 GMT</pubDate>\n"
+
" <lastBuildDate>Sat, 3 Feb 2001 04:05:06 GMT</lastBuildDate>\n"
+
" <item>\n"
+
" <title>New Version 0.9.9.9.9</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>\n"
+
" <![CDATA[\n"
+
" New Features\n"
+
" Test\n"
+
" ]]>\n"
+
" </description>\n"
+
" </item>\n"
+
" </channel>\n"
+
"</rss>\n"
);
}
private
void
testURL
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
}
else
{
buff
.
append
((
char
)
random
.
nextInt
(
255
));
buff
.
append
((
char
)
random
.
nextInt
(
255
));
}
}
String
a
=
buff
.
toString
();
...
...
@@ -99,14 +81,14 @@ public class TestStringUtils extends TestBase {
private
void
testJavaString
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
}
else
{
buff
.
append
((
char
)
random
.
nextInt
(
255
));
buff
.
append
((
char
)
random
.
nextInt
(
255
));
}
}
String
a
=
buff
.
toString
();
...
...
@@ -118,17 +100,17 @@ public class TestStringUtils extends TestBase {
private
void
testSplit
()
throws
Exception
{
check
(
3
,
StringUtils
.
arraySplit
(
"ABC,DEF,G\\,HI"
,
','
,
false
).
length
);
check
(
StringUtils
.
arrayCombine
(
new
String
[]
{
""
,
" "
,
","
},
','
),
", ,\\,"
);
check
(
StringUtils
.
arrayCombine
(
new
String
[]
{
""
,
" "
,
","
},
','
),
", ,\\,"
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
String
select
=
"abcd,"
;
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
char
c
=
select
.
charAt
(
random
.
nextInt
(
select
.
length
()));
if
(
c
==
'a'
)
{
if
(
c
==
'a'
)
{
buff
.
append
(
"\\\\"
);
}
else
if
(
c
==
'b'
)
{
}
else
if
(
c
==
'b'
)
{
buff
.
append
(
"\\,"
);
}
else
{
buff
.
append
(
c
);
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
f447a3e4
...
...
@@ -4,15 +4,19 @@
*/
package
org
.
h2
.
test
.
unit
;
import
java.sql.*
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Backup
;
import
org.h2.tools.Restore
;
import
org.h2.tools.Script
;
import
org.h2.tools.ChangePassword
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Restore
;
import
org.h2.tools.RunScript
;
import
org.h2.tools.Script
;
import
org.h2.tools.Server
;
import
org.h2.util.Resources
;
...
...
@@ -30,27 +34,29 @@ public class TestTools extends TestBase {
private
void
testManagementDb
()
throws
Exception
{
int
count
=
getSize
(
2
,
10
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Server
server
=
Server
.
createTcpServer
(
new
String
[]{}).
start
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{}).
start
();
server
.
stop
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-tcpPassword"
,
"abc"
}).
start
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-tcpPassword"
,
"abc"
}).
start
();
server
.
stop
();
}
}
private
void
testScriptRunscript
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
fileName
=
baseDir
+
"/b2.sql"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
close
();
Script
.
main
(
new
String
[]{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"nodata"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
DeleteDbFiles
.
main
(
new
String
[]{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
RunScript
.
main
(
new
String
[]{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
Script
.
main
(
new
String
[]
{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"nodata"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
RunScript
.
main
(
new
String
[]
{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
checkFalse
(
rs
.
next
());
conn
.
close
();
...
...
@@ -58,59 +64,61 @@ public class TestTools extends TestBase {
private
void
testBackupRestore
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
fileName
=
baseDir
+
"/b2.zip"
;
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
close
();
Backup
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Restore
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
Backup
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Restore
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
check
(
rs
.
next
());
checkFalse
(
rs
.
next
());
conn
.
close
();
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
}
private
void
testResourceGenerator
()
throws
Exception
{
Resources
.
main
(
new
String
[]
{
"."
});
Resources
.
main
(
new
String
[]
{
"."
});
}
private
void
testChangePassword
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=XTEA;STORAGE=TEXT"
,
"sa"
,
"abc 123"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=XTEA;STORAGE=TEXT"
,
"sa"
,
"abc 123"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
conn
.
close
();
String
[]
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"XTEA"
,
"-decrypt"
,
"abc"
,
"-quiet"
};
String
[]
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"XTEA"
,
"-decrypt"
,
"abc"
,
"-quiet"
};
ChangePassword
.
main
(
args
);
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"AES"
,
"-encrypt"
,
"def"
,
"-quiet"
};
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"AES"
,
"-encrypt"
,
"def"
,
"-quiet"
};
ChangePassword
.
main
(
args
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=AES"
,
"sa"
,
"def 123"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=AES"
,
"sa"
,
"def 123"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM TEST"
);
conn
.
close
();
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
};
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
};
DeleteDbFiles
.
main
(
args
);
}
private
void
testServer
()
throws
Exception
{
Connection
conn
;
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"false"
,
"-baseDir"
,
baseDir
}).
start
();
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"false"
,
"-baseDir"
,
baseDir
}).
start
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
.
close
();
server
.
stop
();
server
=
Server
.
createTcpServer
(
new
String
[]{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test2"
,
"sa"
,
""
);
error
(
"should not be able to create new db"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
...
...
@@ -118,7 +126,7 @@ public class TestTools extends TestBase {
try
{
Server
.
shutdownTcpServer
(
"tcp://localhost"
,
""
,
true
);
error
(
"shouldn't work and should throw an exception"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
// expected
}
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
...
...
@@ -127,7 +135,7 @@ public class TestTools extends TestBase {
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
error
(
"server must have been closed"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestValueHashMap.java
浏览文件 @
f447a3e4
...
...
@@ -28,20 +28,20 @@ public class TestValueHashMap extends TestBase implements DataHandler {
Random
random
=
new
Random
(
1
);
Comparator
vc
=
new
Comparator
()
{
public
int
compare
(
Object
o1
,
Object
o2
)
{
Value
v1
=
(
Value
)
o1
;
Value
v2
=
(
Value
)
o2
;
Value
v1
=
(
Value
)
o1
;
Value
v2
=
(
Value
)
o2
;
try
{
return
v1
.
compareTo
(
v2
,
compareMode
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
Error
(
e
);
}
}
};
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
int
op
=
random
.
nextInt
(
10
);
Value
key
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
Value
value
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
switch
(
op
)
{
switch
(
op
)
{
case
0
:
map
.
put
(
key
,
value
);
hash
.
put
(
key
,
value
);
...
...
@@ -53,7 +53,7 @@ public class TestValueHashMap extends TestBase implements DataHandler {
case
2
:
Value
v1
=
(
Value
)
map
.
get
(
key
);
Value
v2
=
(
Value
)
hash
.
get
(
key
);
check
((
v1
==
null
&&
v2
==
null
)
||
v1
.
compareEqual
(
v2
));
check
((
v1
==
null
&&
v2
==
null
)
||
v1
.
compareEqual
(
v2
));
break
;
case
3
:
{
ObjectArray
a1
=
map
.
keys
();
...
...
@@ -61,8 +61,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
check
(
a1
.
size
(),
a2
.
size
());
a1
.
sort
(
vc
);
a2
.
sort
(
vc
);
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
}
break
;
}
...
...
@@ -72,8 +72,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
check
(
a1
.
size
(),
a2
.
size
());
a1
.
sort
(
vc
);
a2
.
sort
(
vc
);
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
}
break
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论