1 package ejava.examples.txhotel.ejb;
2
3 import java.rmi.RemoteException;
4
5 import java.util.Date;
6 import java.util.List;
7 import java.util.concurrent.TimeUnit;
8
9 import javax.annotation.PostConstruct;
10 import javax.annotation.PreDestroy;
11 import javax.annotation.Resource;
12 import javax.ejb.EJBException;
13 import javax.ejb.Remove;
14 import javax.ejb.SessionContext;
15 import javax.ejb.SessionSynchronization;
16 import javax.ejb.StatefulTimeout;
17
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import ejava.examples.txhotel.bl.HotelReservationException;
22 import ejava.examples.txhotel.bl.HotelReservationSession;
23 import ejava.examples.txhotel.blimpl.HotelReservationSessionImpl;
24 import ejava.examples.txhotel.bo.Person;
25 import ejava.examples.txhotel.bo.Reservation;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 @StatefulTimeout(value=3, unit=TimeUnit.MINUTES)
60 public class HotelReservationSessionEJB
61 implements HotelReservationSessionLocal, HotelReservationSessionRemote,
62 SessionSynchronization {
63 private static final Logger log = LoggerFactory.getLogger(HotelReservationSessionEJB.class);
64 private HotelReservationSession impl;
65
66 @Resource
67 private SessionContext ctx;
68
69
70 private HotelRegistrationLocal reservationist;
71
72
73
74
75
76
77
78
79 @PostConstruct
80 public void init() {
81 log.info("*** HotelReservationSessionEJB ***");
82
83
84 log.debug("ctx=" + ctx);
85 log.debug("reservationist=" + reservationist);
86
87
88 impl = new HotelReservationSessionImpl();
89 ((HotelReservationSessionImpl)impl).setReservationist(reservationist);
90 }
91
92
93
94
95
96 @PreDestroy
97 public void closing() {
98 log.info("*** HotelReservationSessionEJB closing ***");
99 }
100
101
102
103
104 @Remove
105 public void close() {
106 log.info("*** HotelReservationSessionEJB close ***");
107 impl.close();
108 }
109
110 public void createReservation(Person person, Date startDate, Date endDate)
111 throws HotelReservationException {
112 impl.createReservation(person, startDate, endDate);
113 }
114
115 public void cancelReservations() throws HotelReservationException {
116 impl.cancelReservations();
117 }
118
119 public List<Reservation> commit() throws HotelReservationException {
120 return impl.commit();
121 }
122
123
124
125
126
127 public void afterBegin() {
128 log.debug("*** Transaction Started ***");
129 }
130
131
132
133
134 public void beforeCompletion() throws EJBException, RemoteException {
135 log.debug("*** Transaction about to complete, rollback:" +
136 ctx.getRollbackOnly() + " ***");
137 }
138
139
140
141 public void afterCompletion(boolean status) {
142 log.debug("*** Transaction Completed:" + status + " ***");
143 }
144 }