#1321 Added UML diagram
This commit is contained in:
parent
4017c37b6f
commit
12d392931e
@ -1,19 +1,15 @@
|
||||
--- # this is so called 'Yaml Front Matter', read up on it here: http://jekyllrb.com/docs/frontmatter/
|
||||
layout: pattern # layout must always be pattern
|
||||
title: Best Pattern Ever # the properly formatted title
|
||||
folder: best-pattern-ever # the folder name in which this pattern lies
|
||||
permalink: /patterns/best-pattern-ever/ # the permalink to the pattern, to keep this uniform please stick to /patterns/FOLDER/
|
||||
description: # short meta description that shows in Google search results
|
||||
|
||||
# both categories and tags are Yaml Lists
|
||||
# you can either just pick one or write a list with '-'s
|
||||
# usable categories and tags are listed here: https://github.com/iluwatar/java-design-patterns/blob/gh-pages/_config.yml
|
||||
categories: creational # categories of the pattern
|
||||
tags: # tags of the pattern
|
||||
- best
|
||||
- ever
|
||||
- awesome
|
||||
---
|
||||
layout: pattern
|
||||
title: Transaction script
|
||||
folder: transaction-script
|
||||
permalink: /patterns/transaction-script/
|
||||
categories: Domain logic
|
||||
tags:
|
||||
- Data access
|
||||
---
|
||||
|
||||
## Intent
|
||||
Transaction script(TS) is mainly used in small applications where nothing complex is done and bigger architecture's are not needed.
|
||||
|
||||
## Name / classification
|
||||
...
|
||||
@ -21,8 +17,6 @@ tags: # tags of the pattern
|
||||
## Also known as
|
||||
...
|
||||
|
||||
## Intent
|
||||
...
|
||||
|
||||
## Explanation
|
||||
...
|
||||
|
65
transaction-script/etc/transaction-script.urm.puml
Normal file
65
transaction-script/etc/transaction-script.urm.puml
Normal file
@ -0,0 +1,65 @@
|
||||
@startuml
|
||||
package com.ashishtrivedi16.transaction-script {
|
||||
class TransactionScriptApp {
|
||||
- H2_DB_URL : String {static}
|
||||
- LOGGER : Logger {static}
|
||||
- addRooms(hotelDaoImpl : HotelDaoImpl) {static}
|
||||
- createDataSource() : DataSource {static}
|
||||
- createSchema(dataSource : DataSource) {static}
|
||||
- deleteSchema(dataSource : DataSource) {static}
|
||||
- getRoomsStatus(hotelDaoImpl : HotelDaoImpl) {static}
|
||||
- generateSampleRooms() : List<Room> {static}
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
class Room {
|
||||
- id: Int
|
||||
- roomType: String
|
||||
- price: Int
|
||||
- booked: Boolean
|
||||
+ Customer(id : int, roomType : String, price: Int, booked: Boolean)
|
||||
+ getId() : int
|
||||
+ getRoomType() : String
|
||||
+ getPrice() : Int
|
||||
+ isBooked() : Boolean
|
||||
+ setId(id : int)
|
||||
+ setRoomType(roomType : String)
|
||||
+ setPrice(price : Int)
|
||||
+ setBooked(booked : boolean)
|
||||
+ equals(that : Object) : boolean
|
||||
+ hashCode() : int
|
||||
+ toString() : String
|
||||
}
|
||||
interface HotelDao {
|
||||
+ add(Room) : boolean {abstract}
|
||||
+ delete(Room) : boolean {abstract}
|
||||
+ getAll() : Stream<Room> {abstract}
|
||||
+ getById(int) : Optional<Room> {abstract}
|
||||
+ update(Room) : boolean {abstract}
|
||||
}
|
||||
class RoomSchemaSql {
|
||||
+ CREATE_SCHEMA_SQL : String {static}
|
||||
+ DELETE_SCHEMA_SQL : String {static}
|
||||
- RoomSchemaSql()
|
||||
}
|
||||
class HotelDaoImpl {
|
||||
- dataSource : DataSource
|
||||
+ HotelDaoImpl(dataSource : DataSource)
|
||||
+ add(room : Room) : boolean
|
||||
- createRoom(resultSet : ResultSet) : Room
|
||||
+ delete(room : Room) : boolean
|
||||
+ getAll() : Stream<Room>
|
||||
+ getById(id : int) : Optional<Room>
|
||||
- getConnection() : Connection
|
||||
- mutedClose(connection : Connection, statement : PreparedStatement, resultSet : ResultSet)
|
||||
+ update(room : Room) : boolean
|
||||
}
|
||||
class Hotel {
|
||||
- LOGGER : Logger {static}
|
||||
- hotelDao: HotelDaoImpl
|
||||
+ Hotel(hotelDao: HotelDaoImpl)
|
||||
+ bookRoom(roomNumber: Int)
|
||||
+ cancelRoomBooking(roomNumber: Int)
|
||||
}
|
||||
}
|
||||
HotelDaoImpl ..|> HotelDao
|
||||
@enduml
|
@ -47,6 +47,7 @@ public class TransactionScriptApp {
|
||||
deleteSchema(dataSource);
|
||||
createSchema(dataSource);
|
||||
final var dao = new HotelDaoImpl(dataSource);
|
||||
|
||||
addRooms(dao);
|
||||
|
||||
getRoomStatus(dao);
|
||||
@ -97,7 +98,7 @@ public class TransactionScriptApp {
|
||||
*
|
||||
* @return h2 datasource
|
||||
*/
|
||||
public static DataSource createDataSource() {
|
||||
private static DataSource createDataSource() {
|
||||
JdbcDataSource dataSource = new JdbcDataSource();
|
||||
dataSource.setUrl(H2_DB_URL);
|
||||
return dataSource;
|
||||
@ -114,7 +115,7 @@ public class TransactionScriptApp {
|
||||
*
|
||||
* @return list of rooms
|
||||
*/
|
||||
public static List<Room> generateSampleRooms() {
|
||||
private static List<Room> generateSampleRooms() {
|
||||
final var room1 = new Room(1, "Single", 50, false);
|
||||
final var room2 = new Room(2, "Double", 80, false);
|
||||
final var room3 = new Room(3, "Queen", 120, false);
|
||||
|
@ -261,7 +261,6 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An arbitrary number which does not correspond to an active Room id.
|
||||
*
|
||||
|
@ -63,7 +63,7 @@ public class HotelTest {
|
||||
@Test()
|
||||
public void bookingRoomWithInvalidIdShouldRaiseException() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
hotel.bookRoom(999);
|
||||
hotel.bookRoom(getNonExistingRoomId());
|
||||
});
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public class HotelTest {
|
||||
@Test
|
||||
public void cancelRoomBookingWithInvalidIdShouldRaiseException() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
hotel.cancelRoomBooking(999);
|
||||
hotel.cancelRoomBooking(getNonExistingRoomId());
|
||||
});
|
||||
}
|
||||
|
||||
@ -140,4 +140,13 @@ public class HotelTest {
|
||||
final var room6 = new Room(6, "Double", 80, false);
|
||||
return List.of(room1, room2, room3, room4, room5, room6);
|
||||
}
|
||||
|
||||
/**
|
||||
* An arbitrary number which does not correspond to an active Room id.
|
||||
*
|
||||
* @return an int of a room id which doesn't exist
|
||||
*/
|
||||
private int getNonExistingRoomId() {
|
||||
return 999;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user