diff --git a/transaction-script/src/main/java/com/ashishtrivedi16/transactionscript/App.java b/transaction-script/src/main/java/com/ashishtrivedi16/transactionscript/App.java index 576458e0b..98762520d 100644 --- a/transaction-script/src/main/java/com/ashishtrivedi16/transactionscript/App.java +++ b/transaction-script/src/main/java/com/ashishtrivedi16/transactionscript/App.java @@ -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. + * + *
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.
+ * + *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.
+ */ 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);