Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ccecc321
提交
ccecc321
authored
9月 25, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
0e291079
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
115 行增加
和
115 行删除
+115
-115
UpdateTest.java
h2/src/test/org/h2/test/jaqu/UpdateTest.java
+115
-115
没有找到文件。
h2/src/test/org/h2/test/jaqu/UpdateTest.java
浏览文件 @
ccecc321
/*
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Initial Developer: H2 Group
*/
*/
package
org
.
h2
.
test
.
jaqu
;
package
org
.
h2
.
test
.
jaqu
;
import
org.h2.jaqu.Db
;
import
org.h2.jaqu.Db
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
static
java
.
sql
.
Date
.
valueOf
;
import
static
java
.
sql
.
Date
.
valueOf
;
/**
/**
* Tests the Db.update() function.
* Tests the Db.update() function.
*
*
* @author dmoebius at scoop slash gmbh dot de
* @author dmoebius at scoop slash gmbh dot de
*/
*/
public
class
UpdateTest
extends
TestBase
{
public
class
UpdateTest
extends
TestBase
{
Db
db
;
Db
db
;
/**
/**
* This method is called when executing this application from the command
* This method is called when executing this application from the command
* line.
* line.
*
*
* @param args the command line parameters
* @param args the command line parameters
*/
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
UpdateTest
().
test
();
new
UpdateTest
().
test
();
}
}
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
db
=
Db
.
open
(
"jdbc:h2:mem:"
,
"sa"
,
"sa"
);
db
=
Db
.
open
(
"jdbc:h2:mem:"
,
"sa"
,
"sa"
);
db
.
insertAll
(
Product
.
getList
());
db
.
insertAll
(
Product
.
getList
());
db
.
insertAll
(
Customer
.
getList
());
db
.
insertAll
(
Customer
.
getList
());
db
.
insertAll
(
Order
.
getList
());
db
.
insertAll
(
Order
.
getList
());
testSimpleUpdate
();
testSimpleUpdate
();
testSimpleUpdateWithCombinedPrimaryKey
();
testSimpleUpdateWithCombinedPrimaryKey
();
testSimpleMerge
();
testSimpleMerge
();
testSimpleMergeWithCombinedPrimaryKey
();
testSimpleMergeWithCombinedPrimaryKey
();
db
.
close
();
db
.
close
();
}
}
private
void
testSimpleUpdate
()
{
private
void
testSimpleUpdate
()
{
Product
p
=
new
Product
();
Product
p
=
new
Product
();
Product
pChang
=
db
.
from
(
p
).
where
(
p
.
productName
).
is
(
"Chang"
).
selectFirst
();
Product
pChang
=
db
.
from
(
p
).
where
(
p
.
productName
).
is
(
"Chang"
).
selectFirst
();
// update unitPrice from 19.0 to 19.5
// update unitPrice from 19.0 to 19.5
pChang
.
unitPrice
=
19.5
;
pChang
.
unitPrice
=
19.5
;
// update unitsInStock from 17 to 16
// update unitsInStock from 17 to 16
pChang
.
unitsInStock
=
16
;
pChang
.
unitsInStock
=
16
;
db
.
update
(
pChang
);
db
.
update
(
pChang
);
Product
p2
=
new
Product
();
Product
p2
=
new
Product
();
Product
pChang2
=
db
.
from
(
p2
).
where
(
p2
.
productName
).
is
(
"Chang"
).
selectFirst
();
Product
pChang2
=
db
.
from
(
p2
).
where
(
p2
.
productName
).
is
(
"Chang"
).
selectFirst
();
assertEquals
(
19.5
,
pChang2
.
unitPrice
);
assertEquals
(
19.5
,
pChang2
.
unitPrice
);
assertEquals
(
new
Integer
(
16
),
pChang2
.
unitsInStock
);
assertEquals
(
new
Integer
(
16
),
pChang2
.
unitsInStock
);
// undo update
// undo update
pChang
.
unitPrice
=
19.0
;
pChang
.
unitPrice
=
19.0
;
pChang
.
unitsInStock
=
17
;
pChang
.
unitsInStock
=
17
;
db
.
update
(
pChang
);
db
.
update
(
pChang
);
}
}
private
void
testSimpleUpdateWithCombinedPrimaryKey
()
{
private
void
testSimpleUpdateWithCombinedPrimaryKey
()
{
Order
o
=
new
Order
();
Order
o
=
new
Order
();
Order
ourOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-02"
)).
selectFirst
();
Order
ourOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-02"
)).
selectFirst
();
ourOrder
.
orderDate
=
valueOf
(
"2007-01-03"
);
ourOrder
.
orderDate
=
valueOf
(
"2007-01-03"
);
db
.
update
(
ourOrder
);
db
.
update
(
ourOrder
);
Order
ourUpdatedOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-03"
)).
selectFirst
();
Order
ourUpdatedOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-03"
)).
selectFirst
();
assertTrue
(
"updated order not found"
,
ourUpdatedOrder
!=
null
);
assertTrue
(
"updated order not found"
,
ourUpdatedOrder
!=
null
);
// undo update
// undo update
ourOrder
.
orderDate
=
valueOf
(
"2007-01-02"
);
ourOrder
.
orderDate
=
valueOf
(
"2007-01-02"
);
db
.
update
(
ourOrder
);
db
.
update
(
ourOrder
);
}
}
private
void
testSimpleMerge
()
{
private
void
testSimpleMerge
()
{
Product
p
=
new
Product
();
Product
p
=
new
Product
();
Product
pChang
=
db
.
from
(
p
).
where
(
p
.
productName
).
is
(
"Chang"
).
selectFirst
();
Product
pChang
=
db
.
from
(
p
).
where
(
p
.
productName
).
is
(
"Chang"
).
selectFirst
();
// update unitPrice from 19.0 to 19.5
// update unitPrice from 19.0 to 19.5
pChang
.
unitPrice
=
19.5
;
pChang
.
unitPrice
=
19.5
;
// update unitsInStock from 17 to 16
// update unitsInStock from 17 to 16
pChang
.
unitsInStock
=
16
;
pChang
.
unitsInStock
=
16
;
db
.
merge
(
pChang
);
db
.
merge
(
pChang
);
Product
p2
=
new
Product
();
Product
p2
=
new
Product
();
Product
pChang2
=
db
.
from
(
p2
).
where
(
p2
.
productName
).
is
(
"Chang"
).
selectFirst
();
Product
pChang2
=
db
.
from
(
p2
).
where
(
p2
.
productName
).
is
(
"Chang"
).
selectFirst
();
assertEquals
(
19.5
,
pChang2
.
unitPrice
);
assertEquals
(
19.5
,
pChang2
.
unitPrice
);
assertEquals
(
new
Integer
(
16
),
pChang2
.
unitsInStock
);
assertEquals
(
new
Integer
(
16
),
pChang2
.
unitsInStock
);
// undo update
// undo update
pChang
.
unitPrice
=
19.0
;
pChang
.
unitPrice
=
19.0
;
pChang
.
unitsInStock
=
17
;
pChang
.
unitsInStock
=
17
;
db
.
merge
(
pChang
);
db
.
merge
(
pChang
);
}
}
private
void
testSimpleMergeWithCombinedPrimaryKey
()
{
private
void
testSimpleMergeWithCombinedPrimaryKey
()
{
Order
o
=
new
Order
();
Order
o
=
new
Order
();
Order
ourOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-02"
)).
selectFirst
();
Order
ourOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-02"
)).
selectFirst
();
ourOrder
.
orderDate
=
valueOf
(
"2007-01-03"
);
ourOrder
.
orderDate
=
valueOf
(
"2007-01-03"
);
db
.
merge
(
ourOrder
);
db
.
merge
(
ourOrder
);
Order
ourUpdatedOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-03"
)).
selectFirst
();
Order
ourUpdatedOrder
=
db
.
from
(
o
).
where
(
o
.
orderDate
).
is
(
valueOf
(
"2007-01-03"
)).
selectFirst
();
assertTrue
(
"updated order not found"
,
ourUpdatedOrder
!=
null
);
assertTrue
(
"updated order not found"
,
ourUpdatedOrder
!=
null
);
// undo update
// undo update
ourOrder
.
orderDate
=
valueOf
(
"2007-01-02"
);
ourOrder
.
orderDate
=
valueOf
(
"2007-01-02"
);
db
.
merge
(
ourOrder
);
db
.
merge
(
ourOrder
);
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论