Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit 135ff79

Browse files
committed
Improved performance
Fixed Hibernate exceptions, Prepare database removed from login page and added in menubar(as admin, system), Hotel Properties window issues fixed, and etc…
1 parent 359e6f6 commit 135ff79

File tree

74 files changed

+1138
-750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1138
-750
lines changed

src/Screenshots/main.png

43.2 KB
Loading

src/com/coder/hms/beans/SessionBean.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class SessionBean implements Serializable {
2525
private static String surname;
2626
private static String nickName;
2727
private static String password;
28+
private static String hotelName;
2829
private static String Date;
2930
private static int roomCount;
3031
private static Object[] tableRowCol;
@@ -68,14 +69,22 @@ public void setPassword(String password) {
6869
SessionBean.password = password;
6970
}
7071

72+
public String getHotelName() {
73+
return hotelName;
74+
}
75+
76+
public void setHotelName(String hotelName) {
77+
SessionBean.hotelName = hotelName;
78+
}
79+
7180
public String getDate() {
7281
return Date;
7382
}
7483

7584
public static void setDate(String date) {
7685
Date = date;
7786
}
78-
87+
7988
public static int getRoomCount() {
8089
return roomCount;
8190
}

src/com/coder/hms/daoImpl/CustomerDaoImpl.java

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,25 @@ public CustomerDaoImpl() {
3333

3434
@Override
3535
public Customer findCustomerByName(String name, String lastName) {
36-
Customer customer = null;
36+
3737
try {
38-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
38+
39+
session = dataSourceFactory.getSessionFactory().openSession();
3940
beginTransactionIfAllowed(session);
4041
Query<Customer> query = session.createQuery("from Customer where FirstName=:name and LastName=:lastName", Customer.class);
4142
query.setParameter("name", name);
4243
query.setParameter("lastName", lastName);
4344

44-
customer = query.getSingleResult();
45+
return query.getSingleResult();
4546

4647
} catch (NoResultException e) {
4748
final InformationFrame frame = new InformationFrame();
4849
frame.setMessage("Customers not found!");
4950
frame.setVisible(true);
51+
return null;
52+
} finally {
53+
session.close();
5054
}
51-
session.close();
52-
return customer;
5355
}
5456

5557
@Override
@@ -60,99 +62,116 @@ public Customer findCustomerByDocumentId(long DocumentNo) {
6062

6163
@Override
6264
public List<Customer> getAllCustomers() {
63-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
64-
beginTransactionIfAllowed(session);
65-
Query<Customer> query = session.createQuery("from Customer", Customer.class);
66-
List<Customer> customerList = query.getResultList();
67-
session.close();
68-
69-
return customerList;
65+
66+
try {
67+
session = dataSourceFactory.getSessionFactory().openSession();
68+
beginTransactionIfAllowed(session);
69+
Query<Customer> query = session.createQuery("from Customer", Customer.class);
70+
return query.getResultList();
71+
72+
} catch (NoResultException e) {
73+
return null;
74+
} finally {
75+
session.close();
76+
}
77+
7078
}
7179

7280
@Override
7381
public boolean save(Customer theCustomer) {
74-
boolean success = false;
82+
7583
try {
76-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
84+
85+
session = dataSourceFactory.getSessionFactory().openSession();
7786
beginTransactionIfAllowed(session);
7887
session.save(theCustomer);
7988
session.getTransaction().commit();
8089

81-
success = true;
90+
return true;
8291
} catch (HibernateException e) {
8392
session.getTransaction().rollback();
84-
success = false;
93+
return false;
94+
} finally {
95+
session.close();
8596
}
86-
session.close();
87-
return success;
8897
}
8998

9099
@Override
91100
public boolean update(Customer theCustomer) {
92-
boolean success = false;
101+
93102
try {
94-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
103+
session = dataSourceFactory.getSessionFactory().openSession();
95104
beginTransactionIfAllowed(session);
96105
session.update(theCustomer);
97106
session.getTransaction().commit();
98-
session.close();
99107

100-
success = true;
108+
return true;
101109
} catch (HibernateException e) {
102110
session.getTransaction().rollback();
103-
success = false;
111+
return false;
112+
} finally {
113+
session.close();
104114
}
105-
return success;
106115
}
107116

108117
public List<Customer> getCustomerByReservId(long id) {
109-
List<Customer> customerList = null;
118+
110119
try {
111-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
120+
session = dataSourceFactory.getSessionFactory().openSession();
112121
beginTransactionIfAllowed(session);
113122
Query<Customer> query = session.createQuery("from Customer where ReservationId=:id", Customer.class);
114123
query.setParameter("id", id);
115-
customerList = query.getResultList();
124+
return query.getResultList();
116125

117126
} catch (NoResultException e) {
118127
final InformationFrame frame = new InformationFrame();
119128
frame.setMessage("Customers not found!");
120129
frame.setVisible(true);
130+
return null;
131+
} finally {
132+
session.close();
121133
}
122-
session.close();
123-
return customerList;
124134
}
125135

126136
@Override
127137
@SuppressWarnings("rawtypes")
128138
public void deleteCustomerByReservationId(long id) {
129-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
130-
beginTransactionIfAllowed(session);
131-
Query query = session.createQuery("delete from Customers where ReservationId=:id");
132-
query.setParameter("id", id);
133-
session.getTransaction().commit();
134-
session.close();
139+
140+
try {
141+
142+
session = dataSourceFactory.getSessionFactory().openSession();
143+
beginTransactionIfAllowed(session);
144+
Query query = session.createQuery("delete from Customers where ReservationId=:id");
145+
query.setParameter("id", id);
146+
session.getTransaction().commit();
147+
148+
} catch (HibernateException e) {
149+
session.getTransaction().rollback();
150+
} finally {
151+
session.close();
152+
}
135153

136154
}
137155

138156
@Override
139157
public Customer getSinlgeCustomerByReservId(long id) {
140-
Customer customer = null;
158+
141159
try {
142-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
160+
session = dataSourceFactory.getSessionFactory().openSession();
143161
beginTransactionIfAllowed(session);
144162
Query<Customer> query = session.createQuery("from Customer where ReservationId=:theId", Customer.class);
145163
query.setParameter("theId", id);
146164

147-
customer = query.getSingleResult();
165+
return query.getSingleResult();
148166

149167
} catch (NoResultException e) {
150168
final InformationFrame frame = new InformationFrame();
151169
frame.setMessage("Customers not found!");
152170
frame.setVisible(true);
171+
return null;
172+
} finally {
173+
session.close();
153174
}
154-
session.close();
155-
return customer;
156175
}
157176

158177
@Override

src/com/coder/hms/daoImpl/HotelDaoImpl.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
package com.coder.hms.daoImpl;
77

8+
import javax.persistence.NoResultException;
9+
10+
import org.hibernate.HibernateException;
811
import org.hibernate.Session;
912
import org.hibernate.query.Query;
1013

@@ -27,23 +30,36 @@ public HotelDaoImpl() {
2730

2831
@Override
2932
public void saveHotel(Hotel hotel) {
30-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
31-
beginTransactionIfAllowed(session);
32-
session.saveOrUpdate(hotel);
33-
session.getTransaction().commit();
34-
session.close();
33+
34+
try {
35+
36+
session = dataSourceFactory.getSessionFactory().openSession();
37+
beginTransactionIfAllowed(session);
38+
session.saveOrUpdate(hotel);
39+
session.getTransaction().commit();
40+
41+
} catch (HibernateException e) {
42+
session.getTransaction().rollback();
43+
} finally {
44+
session.close();
45+
}
3546

3647
}
3748

3849
@Override
3950
public Hotel getHotel() {
40-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
41-
beginTransactionIfAllowed(session);
42-
Query<Hotel> query = session.createQuery("from Hotel", Hotel.class);
43-
Hotel hotel = query.getSingleResult();
44-
session.close();
45-
46-
return hotel;
51+
52+
try {
53+
session = dataSourceFactory.getSessionFactory().openSession();
54+
beginTransactionIfAllowed(session);
55+
Query<Hotel> query = session.createQuery("from Hotel", Hotel.class);
56+
return query.getSingleResult();
57+
58+
} catch (NoResultException e) {
59+
return null;
60+
} finally {
61+
session.close();
62+
}
4763
}
4864

4965
@Override

src/com/coder/hms/daoImpl/HotelSystemStatusImpl.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.coder.hms.daoImpl;
22

3+
import javax.persistence.NoResultException;
4+
5+
import org.hibernate.HibernateException;
36
import org.hibernate.Session;
47
import org.hibernate.query.Query;
58

@@ -20,22 +23,36 @@ public HotelSystemStatusImpl() {
2023

2124
@Override
2225
public HotelSystemStatus getSystemStatus() {
23-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
24-
beginTransactionIfAllowed(session);
25-
Query<HotelSystemStatus> query = session.createQuery("from HotelSystemStatus where id=1", HotelSystemStatus.class);
26-
HotelSystemStatus status = query.getSingleResult();
2726

28-
session.close();
29-
return status;
27+
try {
28+
29+
session = dataSourceFactory.getSessionFactory().openSession();
30+
beginTransactionIfAllowed(session);
31+
Query<HotelSystemStatus> query = session.createQuery("from HotelSystemStatus where id=1", HotelSystemStatus.class);
32+
return query.getSingleResult();
33+
34+
} catch (NoResultException e) {
35+
return null;
36+
} finally {
37+
session.close();
38+
}
3039
}
3140

3241
@Override
3342
public void updateSystemStatus(HotelSystemStatus hotelSystemStatus) {
34-
session = dataSourceFactory.getSessionFactory().getCurrentSession();
35-
beginTransactionIfAllowed(session);
36-
session.saveOrUpdate(hotelSystemStatus);
37-
session.getTransaction().commit();
38-
session.close();
43+
44+
try {
45+
46+
session = dataSourceFactory.getSessionFactory().openSession();
47+
beginTransactionIfAllowed(session);
48+
session.saveOrUpdate(hotelSystemStatus);
49+
session.getTransaction().commit();
50+
51+
} catch (HibernateException e) {
52+
session.getTransaction().rollback();
53+
} finally {
54+
session.close();
55+
}
3956

4057
}
4158

0 commit comments

Comments
 (0)