Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
QZero_0
java-design-patterns
提交
e99bcf77
J
java-design-patterns
项目概览
QZero_0
/
java-design-patterns
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
java-design-patterns
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
GitCode(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e99bcf77
编写于
8月 11, 2020
作者:
A
Ashish Trivedi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#1321 Added comments about TS
上级
75b10ed6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
1 deletion
+20
-1
transaction-script/src/main/java/com/ashishtrivedi16/transactionscript/App.java
.../main/java/com/ashishtrivedi16/transactionscript/App.java
+20
-1
未找到文件。
transaction-script/src/main/java/com/ashishtrivedi16/transactionscript/App.java
浏览文件 @
e99bcf77
...
...
@@ -29,6 +29,20 @@ import org.h2.jdbcx.JdbcDataSource;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Transaction Script (TS) is one of the simplest domain logic pattern.
* It needs less work to implement than other domain logic patterns and therefore
* it’s perfect fit for smaller applications that don't need big architecture behind them.
*
* <p>In this example we will use the TS pattern to implement booking and cancellation
* methods for a Hotel management App. The main method will initialise an instance of
* {@link Hotel} and add rooms to it. After that it will book and cancel a couple of rooms
* and that will be printed by the logger.</p>
*
* <p>The thing we have to note here is that all the operations related to booking or cancelling
* a room like checking the database if the room exists, checking the booking status or the
* room, calculating refund price are all clubbed inside a single transaction script method.</p>
*/
public
class
App
{
private
static
final
String
H2_DB_URL
=
"jdbc:h2:~/test"
;
...
...
@@ -36,7 +50,8 @@ public class App {
/**
* Program entry point.
*
* Initialises an instance of Hotel and adds rooms to it.
* Carries out booking and cancel booking transactions.
* @param args command line arguments
* @throws Exception if any error occurs
*/
...
...
@@ -47,12 +62,15 @@ public class App {
createSchema
(
dataSource
);
final
var
dao
=
new
HotelDaoImpl
(
dataSource
);
// Add rooms
addRooms
(
dao
);
// Print room booking status
getRoomStatus
(
dao
);
var
hotel
=
new
Hotel
(
dao
);
// Book rooms
hotel
.
bookRoom
(
1
);
hotel
.
bookRoom
(
2
);
hotel
.
bookRoom
(
3
);
...
...
@@ -60,6 +78,7 @@ public class App {
hotel
.
bookRoom
(
5
);
hotel
.
bookRoom
(
6
);
// Cancel booking for a few rooms
hotel
.
cancelRoomBooking
(
1
);
hotel
.
cancelRoomBooking
(
3
);
hotel
.
cancelRoomBooking
(
5
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录