Skip to content

Commit 470f265

Browse files
committed
Fixed Cleaning Up Connections
1 parent a679980 commit 470f265

8 files changed

Lines changed: 223 additions & 4 deletions

File tree

Vehicle Rental System/src/main/java/com/sdmproject/VehicleRentingApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.context.annotation.Bean;
1212
import org.springframework.security.web.session.HttpSessionEventPublisher;
1313

14+
import com.sdmproject.connectionpool.BasicConnectionPool;
1415
import com.sdmproject.exceptions.DuplicateEntryException;
1516
import com.sdmproject.repository.ReservationHistoryRepository;
1617

@@ -31,6 +32,7 @@ public static void main(String[] args) {
3132
public void run()
3233
{
3334
System.err.println("Shutdown Hook is running !");
35+
BasicConnectionPool.closeAll();
3436
}
3537
});
3638
}

Vehicle Rental System/src/main/java/com/sdmproject/connectionpool/BasicConnectionPool.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public static BasicConnectionPool create(String url, String user, String passwor
4646
return instance;
4747
}
4848

49+
public static BasicConnectionPool getInstance() {
50+
return instance;
51+
}
4952

5053
// to make it singleton
5154
private BasicConnectionPool(String url, String user, String password, List<Connection> connectionPool) {
@@ -125,7 +128,7 @@ public void shutdown() throws SQLException {
125128
@PreDestroy
126129
public void cleanUp() {
127130

128-
System.err.println("Cleaning --------");
131+
System.err.println("--------- Cleaning up Connections --------");
129132

130133
connectionPool.forEach(connection -> {
131134
try {
@@ -144,4 +147,9 @@ public void cleanUp() {
144147
}
145148
});
146149
}
150+
151+
152+
public static void closeAll() {
153+
getInstance().cleanUp();
154+
}
147155
}

Vehicle Rental System/src/main/java/com/sdmproject/controller/ReservationController.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,38 @@ public ModelAndView checkVehicleAvailibilityFromDateRange(@RequestParam("vehicle
269269

270270
return modelAndView;
271271
}
272+
272273

274+
@RequestMapping(value = { "/admin/checkVehicleDueDate" }, method = RequestMethod.GET)
275+
public ModelAndView checkVehicleDueDate() {
276+
ModelAndView modelAndView = new ModelAndView();
277+
modelAndView.setViewName("admin/checkVehicleDueDate");
278+
279+
// edit here
280+
List<Vehicle> vehicles = vehicleRecordService.findAll();
281+
modelAndView.addObject("vehicles", vehicles);
282+
283+
return modelAndView;
284+
}
285+
286+
287+
@RequestMapping(value = { "/admin/checkVehicleDueDate" }, method = RequestMethod.POST)
288+
public ModelAndView checkVehicleDueDatePOST(@RequestParam("vehicleId") int vehicleId) {
289+
290+
ModelAndView modelAndView = new ModelAndView();
291+
292+
modelAndView.setViewName("admin/checkVehicleDueDate");
293+
List<Vehicle> vehicles = vehicleRecordService.findAll();
294+
modelAndView.addObject("vehicles", vehicles);
295+
296+
List<Reservation> reservations = reservationService.findAllWithVehiclID(vehicleId);
297+
298+
modelAndView.addObject("vehicleId", vehicleId);
299+
modelAndView.addObject("records", reservations);
300+
301+
return modelAndView;
302+
}
303+
304+
305+
273306
}

Vehicle Rental System/src/main/java/com/sdmproject/repository/ReservationRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,9 @@ public List<Reservation> findAllRentalWithVehicle(String sortProperty, String so
8989
return DAO.queryForParamsForDifferentOperationsWithSort(new String[] { "typeOfReservation", "vehicleID" },
9090
new String[] { "=", "="}, new Object[] { "RENTAL", id}, sortProperty, sortOrder.equals("desc"));
9191
}
92+
93+
public List<Reservation> findAllWithVehiclID(int vehicleId) {
94+
return DAO.queryForParamsForDifferentOperations(new String[] { "vehicleId" },
95+
new String[] { "="}, new Object[] {vehicleId });
96+
}
9297
}

Vehicle Rental System/src/main/java/com/sdmproject/service/ReservationService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ public List<Reservation> findAllReservations(Optional<String> sort, Optional<Str
6969
public List<Reservation> findAllResvationOnDueDate(Date dueDate) {
7070
return reservationRepository.findAllReservationOnDueDate(dueDate);
7171
}
72+
73+
public List<Reservation> findAllWithVehiclID(int vehicleId) {
74+
return reservationRepository.findAllWithVehiclID(vehicleId);
75+
}
7276
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:th="http://www.thymeleaf.org">
4+
5+
<head>
6+
<title>Rentals</title>
7+
<link rel="stylesheet" type="text/css" th:href="@{/css/dashboard.css}" />
8+
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" />
9+
<link
10+
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
11+
rel="stylesheet"
12+
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
13+
crossorigin="anonymous">
14+
15+
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" />
16+
<link rel="stylesheet" type="text/css" th:href="@{/css/filter.css}" />
17+
<link
18+
href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
19+
rel="stylesheet">
20+
21+
<link rel="shortcut icon" th:href="@{/images/favicon.ico}"
22+
type="image/png">
23+
<link rel="stylesheet"
24+
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker3.css" />
25+
</head>
26+
<style>
27+
table th {
28+
user-select: none;
29+
background: #eee;
30+
}
31+
32+
.content {
33+
margin-right: 20px;
34+
margin-left: 20px;
35+
width: 100px;
36+
}
37+
</style>
38+
39+
40+
<body>
41+
42+
<div th:replace="admin/header :: navbar"></div>
43+
<span class="glyphicon glyphicon-envelope"></span>
44+
<nav class="bodyMargin" aria-label="breadcrumb">
45+
<ol class="breadcrumb">
46+
<li class="breadcrumb-item"><a th:href="@{/admin/dashboard}">Home</a></li>
47+
<li class="breadcrumb-item active" aria-current="page">Find Due Date of Vehicle</li>
48+
</ol>
49+
</nav>
50+
51+
<main role="main" class="container-fluid">
52+
53+
<h2>
54+
Find Due Date of Vehicle
55+
</h3>
56+
57+
58+
<div class="jumbotron">
59+
<form id="filterForm" th:action="@{/admin/checkVehicleDueDate}"
60+
method="post">
61+
<div class="form-group">
62+
<label class="control-label" for="vehicle">Select Vehicle</label> <select
63+
class="form-control" name="vehicleId" id="vehicle">
64+
<option th:each="t : ${vehicles}"
65+
th:text="${t.id + ' - ' + t.plateNo + ' - ' + t.make + ' - ' + t.model + ' - ' + t.color + ' - ' + t.year }"
66+
th:value="${t.id}" th:selected="${vehicleId} == ${t.id}">
67+
</option>
68+
</select>
69+
<br/><br/>
70+
<button type="submit" class="btn btn-primary" value="Go">
71+
<i class="fa fa-search" aria-hidden="true"></i> Search
72+
</button>
73+
74+
<button id="resetButton" type="button" class="btn btn-primary"
75+
onclick="customReset()">
76+
<i class="fa fa-refresh" aria-hidden="true"></i> Reset
77+
</button>
78+
</div>
79+
</form>
80+
</div>
81+
82+
<table class="table table-bordered" id="filterableTable">
83+
<thead>
84+
<tr>
85+
<th data-sort-prop="id">Id</th>
86+
<th data-sort-prop="firstName">FirstName</th>
87+
<th data-sort-prop="lastName">LastName</th>
88+
<th data-sort-prop="driverLicienceNo">Driver Licence No</th>
89+
90+
<th data-sort-prop="phoneNo">Phone No</th>
91+
<th data-sort-prop="color">Color</th>
92+
<th data-sort-prop="plateNo">Plate No</th>
93+
<th data-sort-prop="make">Make</th>
94+
<th data-sort-prop="expiryDate">Model</th>
95+
<th data-sort-prop="year">Year</th>
96+
<th data-sort-prop="fromDateTime">Booking From</th>
97+
<th data-sort-prop="toDateTime">Booking Due</th>
98+
<th data-sort-prop="createdOn">Reservation Created</th>
99+
</tr>
100+
</thead>
101+
<tbody>
102+
<tr th:each="record : ${records}">
103+
<td th:text="${record.id}"></td>
104+
<td th:text="${record.client.firstName}"></td>
105+
<td th:text="${record.client.lastName}"></td>
106+
<td th:text="${record.client.driverLicienceNo}"></td>
107+
<!-- <td th:text="${#dates.format(record.client.expiryDate, 'MM/dd/yyyy')}"></td> -->
108+
<td th:text="${record.client.phoneNo}"></td>
109+
<td th:text="${record.vehicle.color}"></td>
110+
<td th:text="${record.vehicle.plateNo}"></td>
111+
<td th:text="${record.vehicle.make}"></td>
112+
<td th:text="${record.vehicle.model}"></td>
113+
<td th:text="${record.vehicle.year}"></td>
114+
<td th:text="${record.fromDateTime}"></td>
115+
<td th:text="${record.toDateTime}"></td>
116+
<td th:text="${record.createdOn}"></td>
117+
118+
119+
120+
</tr>
121+
</tbody>
122+
</table>
123+
124+
125+
126+
</main>
127+
<!-- /.container -->
128+
129+
<!-- Bootstrap core JavaScript
130+
================================================== -->
131+
<!-- Placed at the end of the document so the pages load faster -->
132+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
133+
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
134+
crossorigin="anonymous"></script>
135+
136+
<script
137+
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"
138+
integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"
139+
crossorigin="anonymous"></script>
140+
<script
141+
src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"
142+
integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
143+
crossorigin="anonymous"></script>
144+
145+
<script th:src="@{/js/filter.js}">
146+
147+
</script>
148+
<script th:src="@{/js/main.js}">
149+
150+
</script>
151+
<script type="text/javascript"
152+
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
153+
154+
<script>
155+
function customReset() {
156+
document.getElementById("vehicle").reset();
157+
}
158+
</script>
159+
</body>
160+
</html>

Vehicle Rental System/src/main/resources/templates/admin/header.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
<div class="dropdown-menu dropdown-menu-right">
2323
<a th:href="@{/admin/vehicleRecord/add}" class="dropdown-item">
2424
Add Vehicle Record </a> <a th:href="@{/common/vehicleRecord}"
25-
class="dropdown-item">View Vehicle Records</a> <a
25+
class="dropdown-item">View Vehicle Records</a>
26+
27+
<a
28+
th:href="@{/admin/checkVehicleDueDate}" class="dropdown-item">Find Due Date of Vehiclew</a>
29+
30+
<a
2631
th:href="@{/admin/checkVehicleAvailibility}" class="dropdown-item">Check
2732
Vehicle Availibility</a>
2833
</div></li>

Vehicle Rental System/src/main/resources/templates/admin/rentals.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ <h2> Rentals (currently out vehicles) </h3>
8181
<th data-sort-prop="firstName">FirstName</th>
8282
<th data-sort-prop="lastName">LastName</th>
8383
<th data-sort-prop="driverLicienceNo">Driver Licence No</th>
84-
<th data-sort-prop="expiryDate">Expiry Date</th>
84+
8585
<th data-sort-prop="phoneNo">Phone No</th>
8686
<th data-sort-prop="color">Color</th>
8787
<th data-sort-prop="plateNo">Plate No</th>
8888
<th data-sort-prop="make">Make</th>
89+
<th data-sort-prop="expiryDate">Model</th>
8990
<th data-sort-prop="year">Year</th>
9091
<th data-sort-prop="fromDateTime">Booking From</th>
9192
<th data-sort-prop="toDateTime">Booking Due</th>
@@ -98,11 +99,12 @@ <h2> Rentals (currently out vehicles) </h3>
9899
<td th:text="${record.client.firstName}"></td>
99100
<td th:text="${record.client.lastName}"></td>
100101
<td th:text="${record.client.driverLicienceNo}"></td>
101-
<td th:text="${#dates.format(record.client.expiryDate, 'MM/dd/yyyy')}"></td>
102+
<!-- <td th:text="${#dates.format(record.client.expiryDate, 'MM/dd/yyyy')}"></td> -->
102103
<td th:text="${record.client.phoneNo}"></td>
103104
<td th:text="${record.vehicle.color}"></td>
104105
<td th:text="${record.vehicle.plateNo}"></td>
105106
<td th:text="${record.vehicle.make}"></td>
107+
<td th:text="${record.vehicle.model}"></td>
106108
<td th:text="${record.vehicle.year}"></td>
107109
<td th:text="${record.fromDateTime}"></td>
108110
<td th:text="${record.toDateTime}"></td>

0 commit comments

Comments
 (0)