Hi,

I'm trying to create a session bean that checks the contents of a potential new 
record against a table before adding that record to the table. The table is a 
list of (funnily enough) hotel bookings. I want to make sure that the booking 
dates don't clash for a particular room. Because a booking has a start date and 
end date, it's not sufficient to have a compound primary key based on dates.

I'm using EJB3 on JBOSS 4

If I were doing it in normal java it would look something like:


  | List<Booking> bookings = ....
  | Object bookingLock = new Object();
  | 
  | 
  | public void create(Boooking booking) {
  |     synchronized(bookingLock) {
  |         if (!roomBookedForInterval(booking)) {
  |             saveBooking(booking)
  |         }
  |     }
  | }
  | 
  | private boolean roomBookedForInterval(Booking booking) {
  |     for(Booking b : bookings) {
  |         if (b.endDate() > booking.startDate() ||
  |             b.startDate() < booking.endDate() ) {
  | 
  |                return true;
  |         }
  |     }
  | 
  |     return false;
  | }
  | 
  | private void saveBooking(Booking booking) {
  |     bookings.add(booking);
  | }
  | 
  | 
  | 

My question is, what is the EJB3 equivalent of the synchronized{} block? IS it 
a transaction? If so, how does it work?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117809#4117809

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117809
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to